my-homelab-configs/apps/opsproof/overlay/tests/feature/authentication_test.go

45 lines
1.3 KiB
Go

package feature_test
import (
"testing"
"go.laravel.com/auth/social"
"go.laravel.com/laraveltest"
"app/tests"
)
func TestDexLoginRequiresAnAllowedVerifiedOperator(t *testing.T) {
client := tests.New(t, laraveltest.Env(map[string]string{
"OPSPROOF_DEX_ISSUER": "https://auth.example.test",
"OPSPROOF_DEX_CLIENT_SECRET": "test-secret",
"OPSPROOF_OPERATOR_EMAILS": "operator@example.test",
}))
client.WithoutRedirects().Get("/incidents/cluster/n8n").AssertRedirect("/login")
allowed := client.FakeSocial("dex", &social.Profile{
ID: "dex-operator",
Name: "Homelab Operator",
Email: "operator@example.test",
EmailVerified: true,
})
allowed.WithoutRedirects().Get("/auth/dex/callback").AssertRedirect("/")
allowed.Get("/").AssertOK().AssertInertia("Welcome").AssertProp("operator.authenticated", true)
}
func TestDexLoginRejectsAnUnlistedIdentity(t *testing.T) {
client := tests.New(t, laraveltest.Env(map[string]string{
"OPSPROOF_DEX_ISSUER": "https://auth.example.test",
"OPSPROOF_DEX_CLIENT_SECRET": "test-secret",
"OPSPROOF_OPERATOR_EMAILS": "operator@example.test",
})).FakeSocial("dex", &social.Profile{
ID: "dex-other",
Name: "Other User",
Email: "other@example.test",
EmailVerified: true,
})
client.Get("/auth/dex/callback").AssertForbidden()
}