mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-28 20:26:19 +01:00
[PORT] Test /user/settings/security auth sources
This commit is contained in:
parent
4dbf2d7c11
commit
d49c116ce5
1 changed files with 39 additions and 0 deletions
|
@ -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`)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue