This repository has been archived by the owner on Nov 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enable ProxyHeader handler to get accurate scheme/hosts/etc * Figure out hostname from hosts header * Add tests for above * Support legacy REDIRECT_URI
- Loading branch information
Showing
4 changed files
with
100 additions
and
8 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
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,43 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/gorilla/handlers" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestSelfRoot(t *testing.T) { | ||
var ( | ||
r *http.Request | ||
err error | ||
) | ||
|
||
// Test Default | ||
r, err = http.NewRequest("GET", "/authorize", nil) | ||
r.Host = "foo.bar" | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.Equal(t, "http://foo.bar", SelfRoot(r)) | ||
|
||
// Test Manual forwarded proto | ||
r, err = http.NewRequest("GET", "/validate", nil) | ||
r.Host = "foo.bar" | ||
r.Header.Set("X-Forwarded-Proto", "https") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.Equal(t, "https://foo.bar", SelfRoot(r)) | ||
|
||
// Test ProxyHeader handler | ||
rr := httptest.NewRecorder() | ||
r, err = http.NewRequest("GET", "/validate", nil) | ||
r.Header.Set("X-Forwarded-Host", "foo.bar") | ||
r.Header.Set("X-Forwarded-Proto", "https") | ||
handlers.ProxyHeaders(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})).ServeHTTP(rr, r) | ||
assert.Equal(t, "https://foo.bar", SelfRoot(r)) | ||
} |
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