generated from hashicorp/terraform-provider-scaffolding-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Allow overwriting the
Host
header for all request.
This is to work around situations where DNS isn't available (yet) but Gotify is behind a reverse-proxy which is routing traffic based on Hostnames. For these scenarios, we can simply use the static IP as the Endpoint and overwrite the `Host` header to what the reverse proxy requires to correctly route the request.
- Loading branch information
1 parent
e3890c7
commit 2f6b791
Showing
5 changed files
with
114 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/gotify/go-api-client/v2/client/application" | ||
) | ||
|
||
const ( | ||
testHost = "my.coolapp.local" | ||
// the httptest.NewServer always listens on this address | ||
Check failure on line 15 in client_test.go GitHub Actions / Build
|
||
localHost = "127.0.0.1" | ||
) | ||
|
||
func TestClientHostOverwrite(t *testing.T) { | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | ||
if req.Host != testHost { | ||
t.Errorf("Expected \"Host\" to be %q, got %q", testHost, req.Host) | ||
} | ||
|
||
// Return valid response for test endpoint | ||
w.Header().Set("Content-Type", "application/json") | ||
fmt.Fprintln(w, "[]") | ||
})) | ||
defer ts.Close() | ||
|
||
host := testHost | ||
client, err := NewAuthedClient(ts.URL, "test", "test", &host) | ||
if err != nil { | ||
t.Fatalf("Could not construct client: %v", err.Error()) | ||
} | ||
|
||
params := application.NewGetAppsParams() | ||
_, err = client.client.Application.GetApps(params, client.auth) | ||
if err != nil { | ||
t.Fatalf("Error during test request: %v", err.Error()) | ||
} | ||
} | ||
|
||
func TestClientHostDefault(t *testing.T) { | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | ||
if !strings.HasPrefix(req.Host, localHost) { | ||
t.Errorf("Expected \"Host\" to start with %q, got %q", localHost, req.Host) | ||
} | ||
|
||
// Return valid response for test endpoint | ||
w.Header().Set("Content-Type", "application/json") | ||
fmt.Fprintln(w, "[]") | ||
})) | ||
defer ts.Close() | ||
|
||
client, err := NewAuthedClient(ts.URL, "test", "test", nil) | ||
if err != nil { | ||
t.Fatalf("Could not construct client: %v", err.Error()) | ||
} | ||
|
||
params := application.NewGetAppsParams() | ||
_, err = client.client.Application.GetApps(params, client.auth) | ||
if err != nil { | ||
t.Fatalf("Error during test request: %v", err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
# Required configuration | ||
provider "gotify" { | ||
endpoint = "http://my.gotify.local" # or GOTIFY_ENDPOINT | ||
username = "admin" # or GOTIFY_USERNAME | ||
password = "admin" # or GOTIFY_PASSWORD | ||
} | ||
|
||
# When Gotify is behind a reverse proxy and DNS isn't setup yet | ||
provider "gotify" { | ||
endpoint = "http://192.168.1.4" # public, static IP of deployment | ||
host_header = "my.gotify.local" # Host header expected by reverse proxy | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters