mirror of
https://github.com/Forceu/Gokapi.git
synced 2026-01-07 01:19:34 -06:00
Fixed setup not saving recheck interval, fixed tests
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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}`
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user