66 "testing"
77
88 "github.com/gotify/server/v2/mode"
9+ "github.com/rs/zerolog"
910 "github.com/stretchr/testify/assert"
1011)
1112
@@ -21,7 +22,6 @@ func TestConfigEnv(t *testing.T) {
2122 t .Setenv ("GOTIFY_SERVER_CORS_ALLOWMETHODS" , "GET,POST" )
2223 t .Setenv ("GOTIFY_SERVER_CORS_ALLOWHEADERS" , "Authorization,content-type" )
2324 t .Setenv ("GOTIFY_SERVER_STREAM_ALLOWEDORIGINS" , ".+.example.com,otherdomain.com" )
24- t .Setenv (EnvLocalAuthEnabled , "false" )
2525
2626 conf , _ := Get ()
2727 assert .Equal (t , 80 , conf .Server .Port , "should use defaults" )
@@ -33,17 +33,53 @@ func TestConfigEnv(t *testing.T) {
3333 assert .Equal (t , []string {"GET" , "POST" }, conf .Server .Cors .AllowMethods )
3434 assert .Equal (t , []string {"Authorization" , "content-type" }, conf .Server .Cors .AllowHeaders )
3535 assert .Equal (t , []string {".+.example.com" , "otherdomain.com" }, conf .Server .Stream .AllowedOrigins )
36- assert .False (t , conf .LocalAuthEnabled )
3736}
3837
39- func TestRegistrationRequiresLocalAuth (t * testing.T ) {
40- mode .Set (mode .TestDev )
41- t .Setenv (EnvLocalAuthEnabled , "false" )
42- t .Setenv (EnvOIDCEnabled , "true" )
43- t .Setenv (EnvRegistration , "true" )
38+ func TestLocalAuthDisabled (t * testing.T ) {
39+ tests := []struct {
40+ name string
41+ env map [string ]string
42+ fatals []FutureLog
43+ }{
44+ {
45+ name : "with oidc" ,
46+ env : map [string ]string {EnvLocalAuthEnabled : "false" , EnvOIDCEnabled : "true" },
47+ },
48+ {
49+ name : "without oidc" ,
50+ env : map [string ]string {EnvLocalAuthEnabled : "false" },
51+ fatals : []FutureLog {futureFatal ("either local authentication or OIDC must be enabled" )},
52+ },
53+ {
54+ name : "with registration" ,
55+ env : map [string ]string {
56+ EnvLocalAuthEnabled : "false" ,
57+ EnvOIDCEnabled : "true" ,
58+ EnvRegistration : "true" ,
59+ },
60+ fatals : []FutureLog {futureFatal ("registration requires local authentication to be enabled" )},
61+ },
62+ }
4463
45- _ , logs := Get ()
46- assert .Contains (t , logs , futureFatal ("registration requires local authentication to be enabled" ))
64+ for _ , tc := range tests {
65+ t .Run (tc .name , func (t * testing.T ) {
66+ mode .Set (mode .TestDev )
67+ for key , value := range tc .env {
68+ t .Setenv (key , value )
69+ }
70+
71+ conf , logs := Get ()
72+ assert .False (t , conf .LocalAuthEnabled )
73+
74+ var fatals []FutureLog
75+ for _ , entry := range logs {
76+ if entry .Level == zerolog .FatalLevel {
77+ fatals = append (fatals , entry )
78+ }
79+ }
80+ assert .Equal (t , tc .fatals , fatals )
81+ })
82+ }
4783}
4884
4985func TestFile (t * testing.T ) {
0 commit comments