From d49c116ce58748a65b1f9c99c673ccfc939a0ea0 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Mon, 11 Mar 2024 11:29:54 +0100 Subject: [PATCH] [PORT] Test /user/settings/security auth sources --- tests/integration/setting_test.go | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/integration/setting_test.go b/tests/integration/setting_test.go index 9dad9ca71..283070ec8 100644 --- a/tests/integration/setting_test.go +++ b/tests/integration/setting_test.go @@ -7,6 +7,10 @@ import ( "net/http" "testing" + auth_model "code.gitea.io/gitea/models/auth" + "code.gitea.io/gitea/models/db" + "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 +120,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(db.DefaultContext, 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(db.DefaultContext, user, inactiveExternalLoginUser) + assert.NoError(t, err) + + // mark the authSource as inactive + inactive.IsActive = false + err = auth_model.UpdateSource(db.DefaultContext, 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`) +}