Generate new version of SDK resources and Add Tests (#331)
This commit is contained in:
1 parent
96e4b1cdba
commit
c3ecea172d
93 files changed
+3414
-2826
No files matched your search
@@ -141,7 +141,7 @@ func (s Service) ChangePassword(ctx context.Context, req *pbs.ChangePasswordRequ
|
||||
if authResults.Error != nil {
|
||||
return nil, authResults.Error
|
||||
}
|
||||
u, err := s.changePasswordInRepo(ctx, authResults.Scope.GetId(), req.GetId(), req.GetVersion(), req.GetOldPassword(), req.GetNewPassword())
|
||||
u, err := s.changePasswordInRepo(ctx, authResults.Scope.GetId(), req.GetId(), req.GetVersion(), req.GetCurrentPassword(), req.GetNewPassword())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -295,12 +295,12 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]*pb.A
|
||||
return outUl, nil
|
||||
}
|
||||
|
||||
func (s Service) changePasswordInRepo(ctx context.Context, scopeId, id string, version uint32, oldPassword, newPassword string) (*pb.Account, error) {
|
||||
func (s Service) changePasswordInRepo(ctx context.Context, scopeId, id string, version uint32, currentPassword, newPassword string) (*pb.Account, error) {
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out, err := repo.ChangePassword(ctx, scopeId, id, oldPassword, newPassword, version)
|
||||
out, err := repo.ChangePassword(ctx, scopeId, id, currentPassword, newPassword, version)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Unable to change password: %v.", err)
|
||||
}
|
||||
@@ -448,8 +448,8 @@ func validateChangePasswordRequest(req *pbs.ChangePasswordRequest) error {
|
||||
if req.GetNewPassword() == "" {
|
||||
badFields["new_password"] = "This is a required field."
|
||||
}
|
||||
if req.GetOldPassword() == "" {
|
||||
badFields["old_password"] = "This is a required field."
|
||||
if req.GetCurrentPassword() == "" {
|
||||
badFields["current_password"] = "This is a required field."
|
||||
}
|
||||
if len(badFields) > 0 {
|
||||
return handlers.InvalidArgumentErrorf("Improperly formatted identifier.", badFields)
|
||||
|
||||
@@ -950,10 +950,10 @@ func TestChangePassword(t *testing.T) {
|
||||
acct := createAccount(t, "originalpassword")
|
||||
|
||||
changeResp, err := tested.ChangePassword(auth.DisabledAuthTestContext(auth.WithScopeId(o.GetPublicId())), &pbs.ChangePasswordRequest{
|
||||
Id: acct.GetId(),
|
||||
Version: acct.GetVersion(),
|
||||
OldPassword: "originalpassword",
|
||||
NewPassword: "a different password",
|
||||
Id: acct.GetId(),
|
||||
Version: acct.GetVersion(),
|
||||
CurrentPassword: "originalpassword",
|
||||
NewPassword: "a different password",
|
||||
})
|
||||
require.NoError(err)
|
||||
assert.Equal(acct.GetVersion()+1, changeResp.GetItem().GetVersion())
|
||||
@@ -969,10 +969,10 @@ func TestChangePassword(t *testing.T) {
|
||||
acct := createAccount(t, "originalpassword")
|
||||
|
||||
changeResp, err := tested.ChangePassword(auth.DisabledAuthTestContext(auth.WithScopeId(o.GetPublicId())), &pbs.ChangePasswordRequest{
|
||||
Id: acct.GetId(),
|
||||
Version: acct.GetVersion(),
|
||||
OldPassword: "thewrongpassword",
|
||||
NewPassword: "a different password",
|
||||
Id: acct.GetId(),
|
||||
Version: acct.GetVersion(),
|
||||
CurrentPassword: "thewrongpassword",
|
||||
NewPassword: "a different password",
|
||||
})
|
||||
assert.Error(err)
|
||||
assert.Nil(changeResp)
|
||||
@@ -1042,10 +1042,10 @@ func TestChangePassword(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
changeResp, err := tested.ChangePassword(auth.DisabledAuthTestContext(auth.WithScopeId(o.GetPublicId())), &pbs.ChangePasswordRequest{
|
||||
Id: tt.accountId,
|
||||
Version: tt.version,
|
||||
OldPassword: tt.oldPW,
|
||||
NewPassword: tt.newPW,
|
||||
Id: tt.accountId,
|
||||
Version: tt.version,
|
||||
CurrentPassword: tt.oldPW,
|
||||
NewPassword: tt.newPW,
|
||||
})
|
||||
assert.Error(err)
|
||||
assert.Nil(changeResp)
|
||||
|
||||
@@ -199,7 +199,7 @@ func validateAuthenticateRequest(req *pbs.AuthenticateRequest) error {
|
||||
}
|
||||
tType := strings.ToLower(strings.TrimSpace(req.GetTokenType()))
|
||||
if tType != "" && tType != "token" && tType != "cookie" {
|
||||
badFields["token_type"] = "The only accepted type is 'token'."
|
||||
badFields["token_type"] = `The only accepted types are "token" and "cookie".`
|
||||
}
|
||||
if len(badFields) > 0 {
|
||||
return handlers.InvalidArgumentErrorf("Invalid fields provided in request.", badFields)
|
||||
|
||||
@@ -36,14 +36,14 @@ func TestAuthenticationMulti(t *testing.T) {
|
||||
defer c2.Shutdown()
|
||||
|
||||
auth := authmethods.NewClient(c1.Client())
|
||||
token1, apiErr, err := auth.Authenticate(c1.Context(), amId, user, password)
|
||||
token1, apiErr, err := auth.Authenticate(c1.Context(), amId, map[string]interface{}{"login_name": user, "password": password})
|
||||
require.Nil(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(token1)
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
auth = authmethods.NewClient(c2.Client())
|
||||
token2, apiErr, err := auth.Authenticate(c2.Context(), amId, user, password)
|
||||
token2, apiErr, err := auth.Authenticate(c2.Context(), amId, map[string]interface{}{"login_name": user, "password": password})
|
||||
require.Nil(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(token2)
|
||||
@@ -51,9 +51,7 @@ func TestAuthenticationMulti(t *testing.T) {
|
||||
assert.NotEqual(token1.Token, token2.Token)
|
||||
|
||||
c1.Client().SetToken(token1.Token)
|
||||
c1.Client().SetScopeId(scope.Global.String())
|
||||
c2.Client().SetToken(token1.Token) // Same token, as it should work on both
|
||||
c2.Client().SetScopeId(scope.Global.String())
|
||||
|
||||
// Create a project, read from the other
|
||||
org, apiErr, err := scopes.NewClient(c1.Client()).Create(c1.Context(), scope.Global.String())
|
||||
|
||||
@@ -103,8 +103,10 @@ func (tc *TestController) Token() *authtokens.AuthToken {
|
||||
token, apiErr, err := authmethods.NewClient(tc.Client()).Authenticate(
|
||||
tc.Context(),
|
||||
tc.b.DevAuthMethodId,
|
||||
tc.b.DevLoginName,
|
||||
tc.b.DevPassword,
|
||||
map[string]interface{}{
|
||||
"login_name": tc.b.DevLoginName,
|
||||
"password": tc.b.DevPassword,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
tc.t.Error(fmt.Errorf("error logging in: %w", err))
|
||||
|
||||
Reference in new issue
Block a user