From 6936ced93ee568295636278066fa57f38bbdfc36 Mon Sep 17 00:00:00 2001 From: Marc Ole Bulling Date: Sat, 20 Jan 2024 11:55:19 +0100 Subject: [PATCH] Fixed setup not saving recheck interval, fixed tests --- internal/configuration/setup/Setup.go | 5 +++++ internal/configuration/setup/Setup_test.go | 2 ++ .../configuration/setup/templates/setup.tmpl | 2 +- internal/models/Configuration_test.go | 2 +- .../sessionmanager/SessionManager_test.go | 18 ++++++++++-------- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/internal/configuration/setup/Setup.go b/internal/configuration/setup/Setup.go index b3a9480..3f132b8 100644 --- a/internal/configuration/setup/Setup.go +++ b/internal/configuration/setup/Setup.go @@ -313,6 +313,11 @@ func parseOAuthSettings(result *models.Configuration, formObjects *[]jsonFormObj return err } + result.Authentication.OAuthRecheckInterval, err = getFormValueInt(formObjects, "oauth_recheck_interval") + if err != nil { + return err + } + scopeUsers, err := getFormValueString(formObjects, "oauth_scope_users") if err != nil { return err diff --git a/internal/configuration/setup/Setup_test.go b/internal/configuration/setup/Setup_test.go index e1c80ec..dd20f29 100644 --- a/internal/configuration/setup/Setup_test.go +++ b/internal/configuration/setup/Setup_test.go @@ -601,6 +601,7 @@ func createInputInternalAuth() setupValues { values.SaveIp.Value = "0" values.OAuthRestrictUser.Value = "false" values.OAuthRestrictGroups.Value = "false" + values.OAuthRecheckInterval.Value = "12" return values } @@ -623,6 +624,7 @@ func createInputHeaderAuth() setupValues { values.SaveIp.Value = "1" values.OAuthRestrictUser.Value = "false" values.OAuthRestrictGroups.Value = "false" + values.OAuthRecheckInterval.Value = "12" return values } diff --git a/internal/configuration/setup/templates/setup.tmpl b/internal/configuration/setup/templates/setup.tmpl index fe8a220..aaf4abb 100644 --- a/internal/configuration/setup/templates/setup.tmpl +++ b/internal/configuration/setup/templates/setup.tmpl @@ -695,6 +695,7 @@ function TestAWS(button) { document.getElementById("oauth_provider").value = "{{ .Auth.OAuthProvider }}"; document.getElementById("oauth_id").value = "{{ .Auth.OAuthClientId }}"; document.getElementById("oauth_secret").value = "{{ .Auth.OAuthClientSecret }}"; + document.getElementById("oauth_recheck_interval").value = "{{ .Auth.OAuthRecheckInterval }}"; {{ if ne .OAuthUsers "" }} document.getElementById("oauth_restrict_users").checked = true; document.getElementById("oauth_scope_users").disabled = false; @@ -708,7 +709,6 @@ function TestAWS(button) { document.getElementById("oauth_scope_groups").value = "{{ .Auth.OAuthGroupScope }}"; document.getElementById("oauth_allowed_groups").disabled = false; document.getElementById("oauth_allowed_groups").value = "{{ .OAuthGroups }}"; - document.getElementById("oauth_recheck_interval").value = "{{ .Auth.OAuthRecheckInterval }}"; {{ end }} break; case 2: diff --git a/internal/models/Configuration_test.go b/internal/models/Configuration_test.go index 6b98f38..14eae16 100644 --- a/internal/models/Configuration_test.go +++ b/internal/models/Configuration_test.go @@ -48,4 +48,4 @@ func TestConfiguration_ToString(t *testing.T) { test.IsEqualString(t, testConfig.ToString(), exptectedUnidentedOutput) } -const exptectedUnidentedOutput = `{"Authentication":{"Method":0,"SaltAdmin":"saltadmin","SaltFiles":"saltfiles","Username":"admin","Password":"adminpwhashed","HeaderKey":"","OauthProvider":"","OAuthClientId":"","OAuthClientSecret":"","OauthUserScope":"","OauthGroupScope":"","HeaderUsers":null,"OAuthGroups":null,"OauthUsers":null},"Port":":12345","ServerUrl":"https://testserver.com/","RedirectUrl":"https://test.com","PublicName":"public-name","ConfigVersion":14,"LengthId":5,"DataDir":"test","MaxMemory":50,"UseSsl":true,"MaxFileSizeMB":20,"Encryption":{"Level":1,"Cipher":"AA==","Salt":"encsalt","Checksum":"encsum","ChecksumSalt":"encsumsalt"},"PicturesAlwaysLocal":true,"SaveIp":false}` +const exptectedUnidentedOutput = `{"Authentication":{"Method":0,"SaltAdmin":"saltadmin","SaltFiles":"saltfiles","Username":"admin","Password":"adminpwhashed","HeaderKey":"","OauthProvider":"","OAuthClientId":"","OAuthClientSecret":"","OauthUserScope":"","OauthGroupScope":"","OAuthRecheckInterval":0,"HeaderUsers":null,"OAuthGroups":null,"OauthUsers":null},"Port":":12345","ServerUrl":"https://testserver.com/","RedirectUrl":"https://test.com","PublicName":"public-name","ConfigVersion":14,"LengthId":5,"DataDir":"test","MaxMemory":50,"UseSsl":true,"MaxFileSizeMB":20,"Encryption":{"Level":1,"Cipher":"AA==","Salt":"encsalt","Checksum":"encsum","ChecksumSalt":"encsumsalt"},"PicturesAlwaysLocal":true,"SaveIp":false}` diff --git a/internal/webserver/authentication/sessionmanager/SessionManager_test.go b/internal/webserver/authentication/sessionmanager/SessionManager_test.go index e49880d..dd43ba6 100644 --- a/internal/webserver/authentication/sessionmanager/SessionManager_test.go +++ b/internal/webserver/authentication/sessionmanager/SessionManager_test.go @@ -20,8 +20,9 @@ func TestMain(m *testing.M) { os.Exit(exitVal) } -func getRecorder(cookies []test.Cookie) (*httptest.ResponseRecorder, *http.Request) { - return test.GetRecorder("GET", "/", cookies, nil, nil) +func getRecorder(cookies []test.Cookie) (*httptest.ResponseRecorder, *http.Request, bool, int) { + w, r := test.GetRecorder("GET", "/", cookies, nil, nil) + return w, r, false, 1 } func TestIsValidSession(t *testing.T) { @@ -38,11 +39,11 @@ func TestIsValidSession(t *testing.T) { Name: "session_token", Value: "validsession"}, })), true) - w, r := getRecorder([]test.Cookie{{ + w, r, _, _ := getRecorder([]test.Cookie{{ Name: "session_token", Value: "needsRenewal"}, }) - test.IsEqualBool(t, IsValidSession(w, r), true) + test.IsEqualBool(t, IsValidSession(w, r, false, 1), true) cookies := w.Result().Cookies() test.IsEqualInt(t, len(cookies), 1) test.IsEqualString(t, cookies[0].Name, "session_token") @@ -52,8 +53,8 @@ func TestIsValidSession(t *testing.T) { } func TestCreateSession(t *testing.T) { - w, _ := getRecorder(nil) - CreateSession(w) + w, _, _, _ := getRecorder(nil) + CreateSession(w, false, 1) cookies := w.Result().Cookies() test.IsEqualInt(t, len(cookies), 1) test.IsEqualString(t, cookies[0].Name, "session_token") @@ -70,10 +71,11 @@ func TestLogoutSession(t *testing.T) { Name: "session_token", Value: newSession}, })), true) - LogoutSession(getRecorder([]test.Cookie{{ + w, r, _, _ := getRecorder([]test.Cookie{{ Name: "session_token", Value: newSession}, - })) + }) + LogoutSession(w, r) test.IsEqualBool(t, IsValidSession(getRecorder([]test.Cookie{{ Name: "session_token", Value: newSession},