add tests for implicit issuer

This commit is contained in:
AJ ONeal 2019-03-06 14:59:25 -07:00
parent e753b5a1a6
commit 074b91bc2f
1 changed files with 56 additions and 0 deletions

View File

@ -2,6 +2,8 @@ package keyfetch
import ( import (
"errors" "errors"
"net/http"
"net/url"
"testing" "testing"
) )
@ -132,3 +134,57 @@ func TestIssuerMatches(t *testing.T) {
t.Fatal("A bad URL slipped past", iss) t.Fatal("A bad URL slipped past", iss)
} }
} }
func TestImplicitIssuer(t *testing.T) {
var r *http.Request
var iss string
r = &http.Request{
Host: "example.com",
URL: &url.URL{Path: "/foo/bar/baz"},
Header: http.Header(map[string][]string{
"x-forwarded-host": []string{"example.com"},
}),
}
iss = "https://example.com/foo"
if !IsTrustedIssuer(iss, nil, r) {
t.Fatal("A good URL didn't make it:", iss)
}
r = &http.Request{
Host: "example.com",
URL: &url.URL{Path: "/"},
Header: http.Header(map[string][]string{
"x-forwarded-host": []string{"example.com"},
"x-forwarded-proto": []string{"http"},
}),
}
iss = "http://example.com/foo"
if IsTrustedIssuer(iss, nil, r) {
t.Fatal("A bad URL slipped past:", iss)
}
r = &http.Request{
Host: "example.com",
URL: &url.URL{Path: "/foo"},
Header: http.Header(map[string][]string{
"x-forwarded-host": []string{"example.com"},
}),
}
iss = "https://example.com/foo/bar/baz"
if IsTrustedIssuer(iss, nil, r) {
t.Fatal("A bad URL slipped past:", iss)
}
r = &http.Request{
Host: "example.com",
URL: &url.URL{Path: "/"},
Header: http.Header(map[string][]string{
"x-forwarded-proto": []string{"https"},
}),
}
iss = "https://example.com/"
if !IsTrustedIssuer(iss, nil, r) {
t.Fatal("A good URL didn't make it:", iss)
}
}