34 lines
1.3 KiB
Go
34 lines
1.3 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"sea-vhost/internal/store"
|
|
"testing"
|
|
)
|
|
|
|
func TestOIDCPasswordPolicyDoesNotAffectHosts(t *testing.T) {
|
|
off := false
|
|
c := secretServiceConfig{UserPasswordLogin: &off, AdminPasswordLogin: &off}
|
|
if !oidcPasswordAllowed(c, "host") || oidcPasswordAllowed(c, "admin") || oidcPasswordAllowed(c, "tenant") {
|
|
t.Fatal("password policy scope incorrect")
|
|
}
|
|
if !oidcPasswordAllowed(secretServiceConfig{}, "admin") || !oidcPasswordAllowed(secretServiceConfig{}, "tenant") {
|
|
t.Fatal("old settings must preserve password login")
|
|
}
|
|
}
|
|
func TestOIDCProviderIdentityIncludesIssuer(t *testing.T) {
|
|
a := oidcProviderKey(secretServiceConfig{Issuer: "https://id.example.com"})
|
|
if a != oidcProviderKey(secretServiceConfig{Issuer: "https://id.example.com/"}) || a == oidcProviderKey(secretServiceConfig{Issuer: "https://other.example.com"}) || len(a) > 40 {
|
|
t.Fatal("issuer isolation invalid")
|
|
}
|
|
}
|
|
func TestSSOAutomaticCreationRequiresVerifiedEmail(t *testing.T) {
|
|
for _, p := range []store.PendingOIDCLogin{{Email: "a@example.com"}, {Email: "not-an-email", EmailVerified: true}, {Email: "Name <a@example.com>", EmailVerified: true}} {
|
|
if validSSOEmail(p) {
|
|
t.Fatal("untrusted email accepted")
|
|
}
|
|
}
|
|
if !validSSOEmail(store.PendingOIDCLogin{Email: "a@example.com", EmailVerified: true}) {
|
|
t.Fatal("verified email rejected")
|
|
}
|
|
}
|