diff --git a/templates/user/settings/security/accountlinks.tmpl b/templates/user/settings/security/accountlinks.tmpl index 0820844547..77a525f4f6 100644 --- a/templates/user/settings/security/accountlinks.tmpl +++ b/templates/user/settings/security/accountlinks.tmpl @@ -27,10 +27,11 @@ {{range $loginSource, $provider := .AccountLinks}}
- {{$providerData := index $.OAuth2Providers $loginSource.Name}} -
- {{$providerData.IconHTML 20}} -
+ {{with index $.OAuth2Providers $loginSource.Name}} +
+ {{.IconHTML 20}} +
+ {{end}}
{{$loginSource.Name}} diff --git a/tests/integration/setting_test.go b/tests/integration/setting_test.go index 9dad9ca716..53c1c75c44 100644 --- a/tests/integration/setting_test.go +++ b/tests/integration/setting_test.go @@ -7,6 +7,9 @@ import ( "net/http" "testing" + auth_model "code.gitea.io/gitea/models/auth" + "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/tests" @@ -116,3 +119,38 @@ func TestSettingLandingPage(t *testing.T) { setting.LandingPageURL = landingPage } + +func TestSettingSecurityAuthSource(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) + + active := addAuthSource(t, authSourcePayloadGitLabCustom("gitlab-active")) + activeExternalLoginUser := &user_model.ExternalLoginUser{ + ExternalID: "12345", + UserID: user.ID, + LoginSourceID: active.ID, + } + err := user_model.LinkExternalToUser(user, activeExternalLoginUser) + assert.NoError(t, err) + + inactive := addAuthSource(t, authSourcePayloadGitLabCustom("gitlab-inactive")) + inactiveExternalLoginUser := &user_model.ExternalLoginUser{ + ExternalID: "5678", + UserID: user.ID, + LoginSourceID: inactive.ID, + } + err = user_model.LinkExternalToUser(user, inactiveExternalLoginUser) + assert.NoError(t, err) + + // mark the authSource as inactive + inactive.IsActive = false + err = auth_model.UpdateSource(inactive) + assert.NoError(t, err) + + session := loginUser(t, "user1") + req := NewRequest(t, "GET", "user/settings/security") + resp := session.MakeRequest(t, req, http.StatusOK) + assert.Contains(t, resp.Body.String(), `gitlab-active`) + assert.Contains(t, resp.Body.String(), `gitlab-inactive`) +}