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

49 lines
1.6 KiB
Go

package feature_test
import (
"testing"
"go.laravel.com/auth/social"
"go.laravel.com/laraveltest"
"app/tests"
)
func TestDexLoginRequiresAnAllowedVerifiedOperator(t *testing.T) {
t.Setenv("OPSPROOF_OPERATOR_EMAILS", "operator@example.test")
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")
client.Get("/login").AssertOK().AssertInertia("SignIn").AssertProp("provider", "Dex")
allowed := client.FakeSocial("dex", &social.Profile{
ID: "dex-operator",
Name: "Homelab Operator",
Email: "operator@example.test",
EmailVerified: true,
})
allowed.WithoutRedirects().Get("/auth/dex").AssertRedirect()
allowed.WithoutRedirects().Get("/auth/dex/callback").AssertRedirect("http://example.com/incidents/cluster/n8n")
allowed.Get("/").AssertOK().AssertInertia("Welcome").AssertProp("operator.authenticated", true)
}
func TestDexLoginRejectsAnUnlistedIdentity(t *testing.T) {
t.Setenv("OPSPROOF_OPERATOR_EMAILS", "operator@example.test")
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()
}