From 66071d7942594023dba4e4084964aac3208248d9 Mon Sep 17 00:00:00 2001 From: zhujian Date: Wed, 16 Sep 2020 22:16:04 +0800 Subject: [PATCH] fix: validate scm auth info problem only check token type auth, also need to check password type auth. --- pkg/server/biz/scm/scm.go | 15 ++++++++++----- pkg/util/cerr/error.go | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/server/biz/scm/scm.go b/pkg/server/biz/scm/scm.go index 7b27a3abe..b45a0b278 100644 --- a/pkg/server/biz/scm/scm.go +++ b/pkg/server/biz/scm/scm.go @@ -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 } diff --git a/pkg/util/cerr/error.go b/pkg/util/cerr/error.go index ca184dfb7..488fe56c2 100644 --- a/pkg/util/cerr/error.go +++ b/pkg/util/cerr/error.go @@ -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,