Files
archie/internal/domain/identity/authentication_test.go
T

28 lines
1.4 KiB
Go

package identity
import "testing"
func TestAuthenticationSettingsRejectUntrustedOrigins(t *testing.T) {
for _, tc := range []struct {
name, url, issuer, client, audience string
want bool
}{
{name: "public TLS", url: "https://archie.example", want: true},
{name: "localhost", url: "http://localhost:8484", want: true},
{name: "userinfo is not an origin", url: "https://user:password@archie.example", want: false},
{name: "URL path cannot change the RP origin", url: "https://archie.example/subpath", want: false},
{name: "query is not an origin", url: "https://archie.example?token=1", want: false},
{name: "complete provider", url: "https://archie.example", issuer: "https://identity.example", client: "archie", audience: "archie", want: true},
{name: "remote insecure provider", url: "https://archie.example", issuer: "http://identity.example", client: "archie", audience: "archie", want: false},
{name: "issuer without client", url: "https://archie.example", issuer: "https://identity.example", audience: "archie", want: false},
{name: "audience without provider", url: "https://archie.example", audience: "archie", want: false},
} {
t.Run(tc.name, func(t *testing.T) {
err := (AuthenticationSettings{PublicURL: tc.url, OIDCIssuer: tc.issuer, OIDCClientID: tc.client, OIDCAudience: tc.audience}).Validate()
if (err == nil) != tc.want {
t.Fatalf("validation err=%v, allowed=%v", err, tc.want)
}
})
}
}