Skip to content

Commit

Permalink
fix: validate scm auth info problem (#1502)
Browse files Browse the repository at this point in the history
only check token type auth, also need to check password type auth.

Co-authored-by: zhujian <zhujian@caicloud.io>
  • Loading branch information
caicloud-bot and zhujian7 committed Sep 20, 2020
1 parent 936a120 commit 15c7958
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions pkg/server/biz/scm/scm.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,21 @@ func GenerateSCMToken(config *v1alpha1.SCMSource) error {

if generatedToken != "" && config.AuthType == v1alpha1.AuthTypePassword {
config.Token = generatedToken
} else {
err := provider.CheckToken()
if err != nil {
return err
}
}

// Cleanup the password for security.
config.Password = ""

// recreate the scm provider and check auth
provider, err = GetSCMProvider(config)
if err != nil {
return err
}
err = provider.CheckToken()
if err != nil {
return err
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/util/cerr/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var (

// ErrorExternalAuthorizationFailed defines error that authorization failed for external system, Unauthorized 401.
ErrorExternalAuthorizationFailed = nerror.InternalServerError.Build(ReasonAuthorizationFailed,
"authentication failed: ${error}")
"authorization failed: ${error}")

// ErrorExternalAuthenticationFailed defines error that authentication failed for external system, Forbidden 403.
ErrorExternalAuthenticationFailed = nerror.InternalServerError.Build(ReasonAuthenticationFailed,
Expand Down

0 comments on commit 15c7958

Please sign in to comment.