mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-17 21:52:53 +02:00
fix tests
This commit is contained in:
parent
b5ae054554
commit
3332475a42
@ -87,6 +87,14 @@ func oauthCLIFlags() []cli.Flag {
|
|||||||
Value: nil,
|
Value: nil,
|
||||||
Usage: "Scopes to request when to authenticate against this OAuth2 source",
|
Usage: "Scopes to request when to authenticate against this OAuth2 source",
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "attribute-ssh-public-key",
|
||||||
|
Usage: "Claim name that provides SSH public keys",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "attribute-full-name",
|
||||||
|
Usage: "Claim name that provides user's full name",
|
||||||
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "required-claim-name",
|
Name: "required-claim-name",
|
||||||
Value: "",
|
Value: "",
|
||||||
@ -177,6 +185,8 @@ func parseOAuth2Config(c *cli.Command) *oauth2.Source {
|
|||||||
RestrictedGroup: c.String("restricted-group"),
|
RestrictedGroup: c.String("restricted-group"),
|
||||||
GroupTeamMap: c.String("group-team-map"),
|
GroupTeamMap: c.String("group-team-map"),
|
||||||
GroupTeamMapRemoval: c.Bool("group-team-map-removal"),
|
GroupTeamMapRemoval: c.Bool("group-team-map-removal"),
|
||||||
|
AttributeSSHPublicKey: c.String("attribute-ssh-public-key"),
|
||||||
|
AttributeFullName: c.String("attribute-full-name"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,6 +278,12 @@ func (a *authService) runUpdateOauth(ctx context.Context, c *cli.Command) error
|
|||||||
if c.IsSet("group-team-map-removal") {
|
if c.IsSet("group-team-map-removal") {
|
||||||
oAuth2Config.GroupTeamMapRemoval = c.Bool("group-team-map-removal")
|
oAuth2Config.GroupTeamMapRemoval = c.Bool("group-team-map-removal")
|
||||||
}
|
}
|
||||||
|
if c.IsSet("attribute-ssh-public-key") {
|
||||||
|
oAuth2Config.AttributeSSHPublicKey = c.String("attribute-ssh-public-key")
|
||||||
|
}
|
||||||
|
if c.IsSet("attribute-full-name") {
|
||||||
|
oAuth2Config.AttributeFullName = c.String("attribute-full-name")
|
||||||
|
}
|
||||||
|
|
||||||
// update custom URL mapping
|
// update custom URL mapping
|
||||||
customURLMapping := &oauth2.CustomURLMapping{}
|
customURLMapping := &oauth2.CustomURLMapping{}
|
||||||
|
@ -88,6 +88,8 @@ func TestAddOauth(t *testing.T) {
|
|||||||
"--restricted-group", "restricted",
|
"--restricted-group", "restricted",
|
||||||
"--group-team-map", `{"group1": [1,2]}`,
|
"--group-team-map", `{"group1": [1,2]}`,
|
||||||
"--group-team-map-removal=true",
|
"--group-team-map-removal=true",
|
||||||
|
"--attribute-ssh-public-key", "attr_ssh_pub_key",
|
||||||
|
"--attribute-full-name", "attr_full_name",
|
||||||
},
|
},
|
||||||
source: &auth_model.Source{
|
source: &auth_model.Source{
|
||||||
Type: auth_model.OAuth2,
|
Type: auth_model.OAuth2,
|
||||||
@ -104,15 +106,17 @@ func TestAddOauth(t *testing.T) {
|
|||||||
EmailURL: "https://example.com/email",
|
EmailURL: "https://example.com/email",
|
||||||
Tenant: "some_tenant",
|
Tenant: "some_tenant",
|
||||||
},
|
},
|
||||||
IconURL: "https://example.com/icon",
|
IconURL: "https://example.com/icon",
|
||||||
Scopes: []string{"scope1", "scope2"},
|
Scopes: []string{"scope1", "scope2"},
|
||||||
RequiredClaimName: "claim_name",
|
RequiredClaimName: "claim_name",
|
||||||
RequiredClaimValue: "claim_value",
|
RequiredClaimValue: "claim_value",
|
||||||
GroupClaimName: "group_name",
|
GroupClaimName: "group_name",
|
||||||
AdminGroup: "admin",
|
AdminGroup: "admin",
|
||||||
RestrictedGroup: "restricted",
|
RestrictedGroup: "restricted",
|
||||||
GroupTeamMap: `{"group1": [1,2]}`,
|
GroupTeamMap: `{"group1": [1,2]}`,
|
||||||
GroupTeamMapRemoval: true,
|
GroupTeamMapRemoval: true,
|
||||||
|
AttributeSSHPublicKey: "attr_ssh_pub_key",
|
||||||
|
AttributeFullName: "attr_full_name",
|
||||||
},
|
},
|
||||||
TwoFactorPolicy: "skip",
|
TwoFactorPolicy: "skip",
|
||||||
},
|
},
|
||||||
@ -223,15 +227,17 @@ func TestUpdateOauth(t *testing.T) {
|
|||||||
EmailURL: "https://old.example.com/email",
|
EmailURL: "https://old.example.com/email",
|
||||||
Tenant: "old_tenant",
|
Tenant: "old_tenant",
|
||||||
},
|
},
|
||||||
IconURL: "https://old.example.com/icon",
|
IconURL: "https://old.example.com/icon",
|
||||||
Scopes: []string{"old_scope1", "old_scope2"},
|
Scopes: []string{"old_scope1", "old_scope2"},
|
||||||
RequiredClaimName: "old_claim_name",
|
RequiredClaimName: "old_claim_name",
|
||||||
RequiredClaimValue: "old_claim_value",
|
RequiredClaimValue: "old_claim_value",
|
||||||
GroupClaimName: "old_group_name",
|
GroupClaimName: "old_group_name",
|
||||||
AdminGroup: "old_admin",
|
AdminGroup: "old_admin",
|
||||||
RestrictedGroup: "old_restricted",
|
RestrictedGroup: "old_restricted",
|
||||||
GroupTeamMap: `{"old_group1": [1,2]}`,
|
GroupTeamMap: `{"old_group1": [1,2]}`,
|
||||||
GroupTeamMapRemoval: true,
|
GroupTeamMapRemoval: true,
|
||||||
|
AttributeSSHPublicKey: "old_ssh_pub_key",
|
||||||
|
AttributeFullName: "old_full_name",
|
||||||
},
|
},
|
||||||
TwoFactorPolicy: "",
|
TwoFactorPolicy: "",
|
||||||
},
|
},
|
||||||
@ -257,6 +263,8 @@ func TestUpdateOauth(t *testing.T) {
|
|||||||
"--restricted-group", "restricted",
|
"--restricted-group", "restricted",
|
||||||
"--group-team-map", `{"group1": [1,2]}`,
|
"--group-team-map", `{"group1": [1,2]}`,
|
||||||
"--group-team-map-removal=false",
|
"--group-team-map-removal=false",
|
||||||
|
"--attribute-ssh-public-key", "new_ssh_pub_key",
|
||||||
|
"--attribute-full-name", "new_full_name",
|
||||||
},
|
},
|
||||||
authSource: &auth_model.Source{
|
authSource: &auth_model.Source{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
@ -274,15 +282,17 @@ func TestUpdateOauth(t *testing.T) {
|
|||||||
EmailURL: "https://example.com/email",
|
EmailURL: "https://example.com/email",
|
||||||
Tenant: "new_tenant",
|
Tenant: "new_tenant",
|
||||||
},
|
},
|
||||||
IconURL: "https://example.com/icon",
|
IconURL: "https://example.com/icon",
|
||||||
Scopes: []string{"scope1", "scope2"},
|
Scopes: []string{"scope1", "scope2"},
|
||||||
RequiredClaimName: "claim_name",
|
RequiredClaimName: "claim_name",
|
||||||
RequiredClaimValue: "claim_value",
|
RequiredClaimValue: "claim_value",
|
||||||
GroupClaimName: "group_name",
|
GroupClaimName: "group_name",
|
||||||
AdminGroup: "admin",
|
AdminGroup: "admin",
|
||||||
RestrictedGroup: "restricted",
|
RestrictedGroup: "restricted",
|
||||||
GroupTeamMap: `{"group1": [1,2]}`,
|
GroupTeamMap: `{"group1": [1,2]}`,
|
||||||
GroupTeamMapRemoval: false,
|
GroupTeamMapRemoval: false,
|
||||||
|
AttributeSSHPublicKey: "new_ssh_pub_key",
|
||||||
|
AttributeFullName: "new_full_name",
|
||||||
},
|
},
|
||||||
TwoFactorPolicy: "skip",
|
TwoFactorPolicy: "skip",
|
||||||
},
|
},
|
||||||
|
@ -334,7 +334,7 @@ func UpdateSource(ctx context.Context, source *Source) error {
|
|||||||
|
|
||||||
err = registerableSource.RegisterSource()
|
err = registerableSource.RegisterSource()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// restore original values since we cannot update the provider it self
|
// restore original values since we cannot update the provider itself
|
||||||
if _, err := db.GetEngine(ctx).ID(source.ID).AllCols().Update(originalSource); err != nil {
|
if _, err := db.GetEngine(ctx).ID(source.ID).AllCols().Update(originalSource); err != nil {
|
||||||
log.Error("UpdateSource: Error while wrapOpenIDConnectInitializeError: %v", err)
|
log.Error("UpdateSource: Error while wrapOpenIDConnectInitializeError: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,10 @@ func LinkAccountPostSignIn(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func oauth2LinkAccount(ctx *context.Context, u *user_model.User, linkAccountData *LinkAccountData, remember bool) {
|
func oauth2LinkAccount(ctx *context.Context, u *user_model.User, linkAccountData *LinkAccountData, remember bool) {
|
||||||
// no need to call updateAvatarIfNeed(ctx, gothUser.AvatarURL, u) be cause
|
oauth2SignInSync(ctx, &linkAccountData.AuthSource, u, linkAccountData.GothUser)
|
||||||
|
if ctx.Written() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// If this user is enrolled in 2FA, we can't sign the user in just yet.
|
// If this user is enrolled in 2FA, we can't sign the user in just yet.
|
||||||
// Instead, redirect them to the 2FA authentication page.
|
// Instead, redirect them to the 2FA authentication page.
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
@ -17,6 +18,7 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/translation"
|
"code.gitea.io/gitea/modules/translation"
|
||||||
"code.gitea.io/gitea/modules/web"
|
"code.gitea.io/gitea/modules/web"
|
||||||
"code.gitea.io/gitea/routers"
|
"code.gitea.io/gitea/routers"
|
||||||
|
"code.gitea.io/gitea/routers/web/auth"
|
||||||
"code.gitea.io/gitea/services/context"
|
"code.gitea.io/gitea/services/context"
|
||||||
"code.gitea.io/gitea/tests"
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
@ -104,7 +106,7 @@ func TestEnablePasswordSignInFormAndEnablePasskeyAuth(t *testing.T) {
|
|||||||
|
|
||||||
mockLinkAccount := func(ctx *context.Context) {
|
mockLinkAccount := func(ctx *context.Context) {
|
||||||
gothUser := goth.User{Email: "invalid-email", Name: "."}
|
gothUser := goth.User{Email: "invalid-email", Name: "."}
|
||||||
_ = ctx.Session.Set("linkAccountGothUser", gothUser)
|
_ = ctx.Session.Set("linkAccountData", auth.LinkAccountData{auth_model.Source{ID: 1}, gothUser})
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("EnablePasswordSignInForm=false", func(t *testing.T) {
|
t.Run("EnablePasswordSignInForm=false", func(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user