This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/server/auth/oidc_test.go
Jeffrey Smith f0dd43144e rebrand: Switchboard Core → Armature
- Rename Go module switchboard-core → armature (155+ files)
- Rename Docker image → gobha/armature
- Rename K8s resources, secrets, deployments
- Rename Prometheus metrics switchboard_* → armature_*
- Rename env vars SWITCHBOARD_ADMIN_* → ARMATURE_ADMIN_*
- Rename DB names switchboard_core* → armature*
- Update all frontend branding, notification templates, docs
- Update CI scripts, e2e tests, Keycloak realm, nginx conf
- Rename scripts/switchboard-ca.sh → scripts/armature-ca.sh
- Rename k8s/switchboard.yaml → k8s/armature.yaml
- Rename chart alerting/dashboard files
- Fix: DockerHub push uses env: binding for secret injection
- Helm chart updated (name, labels, template functions, dashboard, alerting)
- Replace favicon/icon assets with Armature brand

No functional changes. Pure mechanical rename + CI fix.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 21:39:58 +00:00

137 lines
2.9 KiB
Go

package auth_test
import (
"testing"
"armature/auth"
)
func TestOIDCProvider_Discovery(t *testing.T) {
idp := newMockIdP()
defer idp.Close()
p, err := auth.NewOIDCProvider(auth.OIDCConfig{
IssuerURL: idp.IssuerURL(),
ClientID: "armature",
ClientSecret: "secret",
AutoActivate: true,
})
if err != nil {
t.Fatalf("NewOIDCProvider: %v", err)
}
disc := p.Discovery()
if disc == nil {
t.Fatal("discovery should not be nil")
}
if disc.JWKSUri == "" {
t.Error("JWKS URI should not be empty")
}
if disc.TokenEndpoint == "" {
t.Error("token endpoint should not be empty")
}
}
func TestOIDCProvider_Mode(t *testing.T) {
idp := newMockIdP()
defer idp.Close()
p, err := auth.NewOIDCProvider(auth.OIDCConfig{
IssuerURL: idp.IssuerURL(),
ClientID: "armature",
})
if err != nil {
t.Fatalf("NewOIDCProvider: %v", err)
}
if p.Mode() != auth.ModeOIDC {
t.Errorf("Mode() = %q, want %q", p.Mode(), auth.ModeOIDC)
}
}
func TestOIDCProvider_NoRegistration(t *testing.T) {
idp := newMockIdP()
defer idp.Close()
p, err := auth.NewOIDCProvider(auth.OIDCConfig{
IssuerURL: idp.IssuerURL(),
ClientID: "armature",
})
if err != nil {
t.Fatalf("NewOIDCProvider: %v", err)
}
if p.SupportsRegistration() {
t.Error("OIDC should not support registration")
}
}
func TestOIDCProvider_MissingIssuer(t *testing.T) {
_, err := auth.NewOIDCProvider(auth.OIDCConfig{
ClientID: "armature",
})
if err == nil {
t.Error("expected error for missing issuer URL")
}
}
func TestOIDCProvider_MissingClientID(t *testing.T) {
idp := newMockIdP()
defer idp.Close()
_, err := auth.NewOIDCProvider(auth.OIDCConfig{
IssuerURL: idp.IssuerURL(),
})
if err == nil {
t.Error("expected error for missing client ID")
}
}
func TestOIDCProvider_AuthorizationURL(t *testing.T) {
idp := newMockIdP()
defer idp.Close()
p, err := auth.NewOIDCProvider(auth.OIDCConfig{
IssuerURL: idp.IssuerURL(),
ClientID: "armature",
})
if err != nil {
t.Fatalf("NewOIDCProvider: %v", err)
}
url := p.AuthorizationURL("test-state", "test-nonce", "http://localhost/callback")
if url == "" {
t.Fatal("AuthorizationURL should not be empty")
}
// Should contain the required OIDC parameters
for _, want := range []string{"response_type=code", "client_id=armature", "state=test-state", "nonce=test-nonce"} {
if !containsStr(url, want) {
t.Errorf("AuthorizationURL missing %q in %q", want, url)
}
}
}
func TestOIDCProvider_UnreachableIssuer(t *testing.T) {
_, err := auth.NewOIDCProvider(auth.OIDCConfig{
IssuerURL: "http://127.0.0.1:1/unreachable",
ClientID: "armature",
})
if err == nil {
t.Error("expected error for unreachable issuer")
}
}
func containsStr(s, substr string) bool {
return len(s) >= len(substr) && (s == substr || len(s) > 0 && containsSubstring(s, substr))
}
func containsSubstring(s, sub string) bool {
for i := 0; i <= len(s)-len(sub); i++ {
if s[i:i+len(sub)] == sub {
return true
}
}
return false
}