mirror of
https://github.com/argoproj/argo-cd
synced 2026-05-24 01:38:43 +00:00
fix: return 401 error code if username does not exist (#3369)
This commit is contained in:
parent
9fdd782854
commit
e5452ff70e
3 changed files with 35 additions and 6 deletions
|
|
@ -27,7 +27,7 @@ func NewServer(mgr *sessionmgr.SessionManager, authenticator Authenticator) *Ser
|
|||
|
||||
// Create generates a JWT token signed by Argo CD intended for web/CLI logins of the admin user
|
||||
// using username/password
|
||||
func (s *Server) Create(ctx context.Context, q *session.SessionCreateRequest) (*session.SessionResponse, error) {
|
||||
func (s *Server) Create(_ context.Context, q *session.SessionCreateRequest) (*session.SessionResponse, error) {
|
||||
if q.Token != "" {
|
||||
return nil, status.Errorf(codes.Unauthenticated, "token-based session creation no longer supported. please upgrade argocd cli to v0.7+")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,15 +4,15 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/argoproj/argo-cd/pkg/apiclient/session"
|
||||
"github.com/argoproj/argo-cd/util"
|
||||
|
||||
argocdclient "github.com/argoproj/argo-cd/pkg/apiclient"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/argoproj/argo-cd/errors"
|
||||
argocdclient "github.com/argoproj/argo-cd/pkg/apiclient"
|
||||
"github.com/argoproj/argo-cd/pkg/apiclient/session"
|
||||
. "github.com/argoproj/argo-cd/test/e2e/fixture"
|
||||
"github.com/argoproj/argo-cd/util"
|
||||
)
|
||||
|
||||
func TestCreateAndUseAccount(t *testing.T) {
|
||||
|
|
@ -50,3 +50,29 @@ test true login, apiKey`, output)
|
|||
|
||||
assert.Equal(t, info.Username, "test")
|
||||
}
|
||||
|
||||
func TestLoginBadCredentials(t *testing.T) {
|
||||
EnsureCleanState(t)
|
||||
|
||||
closer, sessionClient := ArgoCDClientset.NewSessionClientOrDie()
|
||||
defer util.Close(closer)
|
||||
|
||||
requests := []session.SessionCreateRequest{{
|
||||
Username: "user-does-not-exist", Password: "some-password",
|
||||
}, {
|
||||
Username: "admin", Password: "bad-password",
|
||||
}}
|
||||
|
||||
for _, r := range requests {
|
||||
_, err := sessionClient.Create(context.Background(), &r)
|
||||
if !assert.Error(t, err) {
|
||||
return
|
||||
}
|
||||
errStatus, ok := status.FromError(err)
|
||||
if !assert.True(t, ok) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, codes.Unauthenticated, errStatus.Code())
|
||||
assert.Equal(t, "Invalid username or password", errStatus.Message())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,6 +156,9 @@ func (mgr *SessionManager) Parse(tokenString string) (jwt.Claims, error) {
|
|||
func (mgr *SessionManager) VerifyUsernamePassword(username string, password string) error {
|
||||
account, err := mgr.settingsMgr.GetAccount(username)
|
||||
if err != nil {
|
||||
if errStatus, ok := status.FromError(err); ok && errStatus.Code() == codes.NotFound {
|
||||
err = status.Errorf(codes.Unauthenticated, invalidLoginError)
|
||||
}
|
||||
return err
|
||||
}
|
||||
if !account.Enabled {
|
||||
|
|
|
|||
Loading…
Reference in a new issue