1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-28 09:21:13 -05:00

[PORT] Test /user/settings/security auth sources

This commit is contained in:
oliverpool 2024-03-11 11:29:54 +01:00
parent 4dbf2d7c11
commit d49c116ce5

View file

@ -7,6 +7,10 @@ import (
"net/http" "net/http"
"testing" "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/modules/setting"
"code.gitea.io/gitea/tests" "code.gitea.io/gitea/tests"
@ -116,3 +120,38 @@ func TestSettingLandingPage(t *testing.T) {
setting.LandingPageURL = landingPage 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`)
}