Update password generated account IDs (#1290)
This commit is contained in:
1 parent
4d27b58d2d
commit
054c0aa538
20 files changed
+225
-67
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/accounts"
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/boundary/internal/intglobals"
|
||||
"github.com/hashicorp/boundary/internal/perms"
|
||||
"github.com/hashicorp/boundary/internal/requests"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/common"
|
||||
@@ -926,7 +927,7 @@ func validateGetRequest(req *pbs.GetAccountRequest) error {
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, password.AccountPrefix, oidc.AccountPrefix)
|
||||
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix, oidc.AccountPrefix)
|
||||
}
|
||||
|
||||
func validateCreateRequest(req *pbs.CreateAccountRequest) error {
|
||||
@@ -1022,7 +1023,7 @@ func validateUpdateRequest(req *pbs.UpdateAccountRequest) error {
|
||||
}
|
||||
}
|
||||
return badFields
|
||||
}, password.AccountPrefix, oidc.AccountPrefix)
|
||||
}, intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix, oidc.AccountPrefix)
|
||||
}
|
||||
|
||||
func validateDeleteRequest(req *pbs.DeleteAccountRequest) error {
|
||||
@@ -1030,7 +1031,7 @@ func validateDeleteRequest(req *pbs.DeleteAccountRequest) error {
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, password.AccountPrefix, oidc.AccountPrefix)
|
||||
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix, oidc.AccountPrefix)
|
||||
}
|
||||
|
||||
func validateListRequest(req *pbs.ListAccountsRequest) error {
|
||||
@@ -1057,7 +1058,7 @@ func validateChangePasswordRequest(req *pbs.ChangePasswordRequest) error {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(handlers.Id(req.GetId()), password.AccountPrefix) {
|
||||
if !handlers.ValidId(handlers.Id(req.GetId()), intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix) {
|
||||
badFields[idField] = "Improperly formatted identifier."
|
||||
}
|
||||
if req.GetVersion() == 0 {
|
||||
@@ -1081,7 +1082,7 @@ func validateSetPasswordRequest(req *pbs.SetPasswordRequest) error {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(handlers.Id(req.GetId()), password.AccountPrefix) {
|
||||
if !handlers.ValidId(handlers.Id(req.GetId()), intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix) {
|
||||
badFields[idField] = "Improperly formatted identifier."
|
||||
}
|
||||
if req.GetVersion() == 0 {
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
scopepb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/scopes"
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/intglobals"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/common"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
|
||||
@@ -184,8 +185,14 @@ func TestGet(t *testing.T) {
|
||||
res: &pbs.GetAccountResponse{Item: &oidcWireAccount},
|
||||
},
|
||||
{
|
||||
name: "Get a non existing password account",
|
||||
req: &pbs.GetAccountRequest{Id: password.AccountPrefix + "_DoesntExis"},
|
||||
name: "Get a non existing old password account",
|
||||
req: &pbs.GetAccountRequest{Id: intglobals.OldPasswordAccountPrefix + "_DoesntExis"},
|
||||
res: nil,
|
||||
err: handlers.ApiErrorWithCode(codes.NotFound),
|
||||
},
|
||||
{
|
||||
name: "Get a non existing new password account",
|
||||
req: &pbs.GetAccountRequest{Id: intglobals.NewPasswordAccountPrefix + "_DoesntExis"},
|
||||
res: nil,
|
||||
err: handlers.ApiErrorWithCode(codes.NotFound),
|
||||
},
|
||||
@@ -575,9 +582,16 @@ func TestDelete(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Delete bad pw account id",
|
||||
name: "Delete bad old pw account id",
|
||||
req: &pbs.DeleteAccountRequest{
|
||||
Id: password.AccountPrefix + "_doesntexis",
|
||||
Id: intglobals.OldPasswordAccountPrefix + "_doesntexis",
|
||||
},
|
||||
err: handlers.ApiErrorWithCode(codes.NotFound),
|
||||
},
|
||||
{
|
||||
name: "Delete bad new pw account id",
|
||||
req: &pbs.DeleteAccountRequest{
|
||||
Id: intglobals.NewPasswordAccountPrefix + "_doesntexis",
|
||||
},
|
||||
err: handlers.ApiErrorWithCode(codes.NotFound),
|
||||
},
|
||||
@@ -693,7 +707,7 @@ func TestCreatePassword(t *testing.T) {
|
||||
},
|
||||
},
|
||||
res: &pbs.CreateAccountResponse{
|
||||
Uri: fmt.Sprintf("accounts/%s_", password.AccountPrefix),
|
||||
Uri: fmt.Sprintf("accounts/%s_", intglobals.NewPasswordAccountPrefix),
|
||||
Item: &pb.Account{
|
||||
AuthMethodId: defaultAccount.GetAuthMethodId(),
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
@@ -715,7 +729,7 @@ func TestCreatePassword(t *testing.T) {
|
||||
},
|
||||
},
|
||||
res: &pbs.CreateAccountResponse{
|
||||
Uri: fmt.Sprintf("accounts/%s_", password.AccountPrefix),
|
||||
Uri: fmt.Sprintf("accounts/%s_", intglobals.NewPasswordAccountPrefix),
|
||||
Item: &pb.Account{
|
||||
AuthMethodId: defaultAccount.GetAuthMethodId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
|
||||
@@ -737,7 +751,7 @@ func TestCreatePassword(t *testing.T) {
|
||||
},
|
||||
},
|
||||
res: &pbs.CreateAccountResponse{
|
||||
Uri: fmt.Sprintf("accounts/%s_", password.AccountPrefix),
|
||||
Uri: fmt.Sprintf("accounts/%s_", intglobals.NewPasswordAccountPrefix),
|
||||
Item: &pb.Account{
|
||||
AuthMethodId: defaultAccount.GetAuthMethodId(),
|
||||
Name: &wrapperspb.StringValue{Value: "name_with_password"},
|
||||
@@ -767,7 +781,7 @@ func TestCreatePassword(t *testing.T) {
|
||||
req: &pbs.CreateAccountRequest{
|
||||
Item: &pb.Account{
|
||||
AuthMethodId: defaultAccount.GetAuthMethodId(),
|
||||
Id: password.AccountPrefix + "_notallowed",
|
||||
Id: intglobals.NewPasswordAccountPrefix + "_notallowed",
|
||||
Type: "password",
|
||||
Attributes: createAttr("cantprovideid", ""),
|
||||
},
|
||||
@@ -823,7 +837,7 @@ func TestCreatePassword(t *testing.T) {
|
||||
}
|
||||
if got != nil {
|
||||
assert.Contains(got.GetUri(), tc.res.Uri)
|
||||
assert.True(strings.HasPrefix(got.GetItem().GetId(), password.AccountPrefix+"_"))
|
||||
assert.True(strings.HasPrefix(got.GetItem().GetId(), intglobals.NewPasswordAccountPrefix+"_"))
|
||||
gotCreateTime := got.GetItem().GetCreatedTime()
|
||||
require.NoError(err, "Error converting proto to timestamp.")
|
||||
gotUpdateTime := got.GetItem().GetUpdatedTime()
|
||||
@@ -1304,9 +1318,23 @@ func TestUpdatePassword(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Update a Non Existing Account",
|
||||
name: "Update a Non Existing Old ID Account",
|
||||
req: &pbs.UpdateAccountRequest{
|
||||
Id: password.AccountPrefix + "_DoesntExis",
|
||||
Id: intglobals.OldPasswordAccountPrefix + "_DoesntExis",
|
||||
UpdateMask: &field_mask.FieldMask{
|
||||
Paths: []string{globals.DescriptionField},
|
||||
},
|
||||
Item: &pb.Account{
|
||||
Name: &wrapperspb.StringValue{Value: "new"},
|
||||
Description: &wrapperspb.StringValue{Value: "desc"},
|
||||
},
|
||||
},
|
||||
err: handlers.ApiErrorWithCode(codes.NotFound),
|
||||
},
|
||||
{
|
||||
name: "Update a Non Existing New ID Account",
|
||||
req: &pbs.UpdateAccountRequest{
|
||||
Id: intglobals.NewPasswordAccountPrefix + "_DoesntExis",
|
||||
UpdateMask: &field_mask.FieldMask{
|
||||
Paths: []string{globals.DescriptionField},
|
||||
},
|
||||
@@ -1324,7 +1352,7 @@ func TestUpdatePassword(t *testing.T) {
|
||||
Paths: []string{"id"},
|
||||
},
|
||||
Item: &pb.Account{
|
||||
Id: password.AccountPrefix + "_somethinge",
|
||||
Id: intglobals.NewPasswordAccountPrefix + "_somethinge",
|
||||
Name: &wrapperspb.StringValue{Value: "new"},
|
||||
Description: &wrapperspb.StringValue{Value: "new desc"},
|
||||
},
|
||||
@@ -1663,7 +1691,7 @@ func TestUpdateOidc(t *testing.T) {
|
||||
{
|
||||
name: "Update a Non Existing Account",
|
||||
req: &pbs.UpdateAccountRequest{
|
||||
Id: password.AccountPrefix + "_DoesntExis",
|
||||
Id: intglobals.NewPasswordAccountPrefix + "_DoesntExis",
|
||||
UpdateMask: &field_mask.FieldMask{
|
||||
Paths: []string{globals.DescriptionField},
|
||||
},
|
||||
@@ -1681,7 +1709,7 @@ func TestUpdateOidc(t *testing.T) {
|
||||
Paths: []string{"id"},
|
||||
},
|
||||
Item: &pb.Account{
|
||||
Id: password.AccountPrefix + "_somethinge",
|
||||
Id: intglobals.NewPasswordAccountPrefix + "_somethinge",
|
||||
Name: &wrapperspb.StringValue{Value: "new"},
|
||||
Description: &wrapperspb.StringValue{Value: "new desc"},
|
||||
},
|
||||
@@ -1908,8 +1936,14 @@ func TestSetPassword(t *testing.T) {
|
||||
password: "somepassword",
|
||||
},
|
||||
{
|
||||
name: "notfound account id",
|
||||
accountId: password.AccountPrefix + "_DoesntExis",
|
||||
name: "notfound old account id",
|
||||
accountId: intglobals.OldPasswordAccountPrefix + "_DoesntExis",
|
||||
version: defaultAcct.GetVersion(),
|
||||
password: "anewpassword",
|
||||
},
|
||||
{
|
||||
name: "notfound new account id",
|
||||
accountId: intglobals.NewPasswordAccountPrefix + "_DoesntExis",
|
||||
version: defaultAcct.GetVersion(),
|
||||
password: "anewpassword",
|
||||
},
|
||||
@@ -2069,9 +2103,17 @@ func TestChangePassword(t *testing.T) {
|
||||
newPW: "somepassword",
|
||||
},
|
||||
{
|
||||
name: "notfound account id",
|
||||
name: "notfound old account id",
|
||||
authMethodId: defaultAcct.GetAuthMethodId(),
|
||||
accountId: password.AccountPrefix + "_DoesntExis",
|
||||
accountId: intglobals.OldPasswordAccountPrefix + "_DoesntExis",
|
||||
version: defaultAcct.GetVersion(),
|
||||
oldPW: "somepassword",
|
||||
newPW: "anewpassword",
|
||||
},
|
||||
{
|
||||
name: "notfound new account id",
|
||||
authMethodId: defaultAcct.GetAuthMethodId(),
|
||||
accountId: intglobals.NewPasswordAccountPrefix + "_DoesntExis",
|
||||
version: defaultAcct.GetVersion(),
|
||||
oldPW: "somepassword",
|
||||
newPW: "anewpassword",
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/auth/password"
|
||||
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/accounts"
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/boundary/internal/intglobals"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/types/known/fieldmaskpb"
|
||||
@@ -154,9 +155,19 @@ func TestValidateUpdateRequest(t *testing.T) {
|
||||
errContains string
|
||||
}{
|
||||
{
|
||||
name: "password to oidc change type",
|
||||
name: "password to oidc change type, old prefix",
|
||||
req: &pbs.UpdateAccountRequest{
|
||||
Id: password.AccountPrefix + "_1234567890",
|
||||
Id: intglobals.OldPasswordAccountPrefix + "_1234567890",
|
||||
Item: &pb.Account{
|
||||
Type: auth.OidcSubtype.String(),
|
||||
},
|
||||
},
|
||||
errContains: fieldError(typeField, "Cannot modify the resource type."),
|
||||
},
|
||||
{
|
||||
name: "password to oidc change type, new prefix",
|
||||
req: &pbs.UpdateAccountRequest{
|
||||
Id: intglobals.NewPasswordAccountPrefix + "_1234567890",
|
||||
Item: &pb.Account{
|
||||
Type: auth.OidcSubtype.String(),
|
||||
},
|
||||
@@ -174,9 +185,21 @@ func TestValidateUpdateRequest(t *testing.T) {
|
||||
errContains: fieldError(typeField, "Cannot modify the resource type."),
|
||||
},
|
||||
{
|
||||
name: "password bad attributes",
|
||||
name: "password bad attributes old prefix",
|
||||
req: &pbs.UpdateAccountRequest{
|
||||
Id: password.AccountPrefix + "_1234567890",
|
||||
Id: intglobals.OldPasswordAccountPrefix + "_1234567890",
|
||||
Item: &pb.Account{
|
||||
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
|
||||
"test": structpb.NewStringValue("something"),
|
||||
}},
|
||||
},
|
||||
},
|
||||
errContains: fieldError(attributesField, "Attribute fields do not match the expected format."),
|
||||
},
|
||||
{
|
||||
name: "password bad attributes new prefix",
|
||||
req: &pbs.UpdateAccountRequest{
|
||||
Id: intglobals.NewPasswordAccountPrefix + "_1234567890",
|
||||
Item: &pb.Account{
|
||||
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
|
||||
"test": structpb.NewStringValue("something"),
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/auth"
|
||||
"github.com/hashicorp/boundary/internal/auth/oidc"
|
||||
"github.com/hashicorp/boundary/internal/auth/password"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/users"
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/iam/store"
|
||||
"github.com/hashicorp/boundary/internal/intglobals"
|
||||
"github.com/hashicorp/boundary/internal/perms"
|
||||
"github.com/hashicorp/boundary/internal/requests"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/common"
|
||||
@@ -714,7 +714,11 @@ func validateAddUserAccountsRequest(req *pbs.AddUserAccountsRequest) error {
|
||||
}
|
||||
for _, a := range req.GetAccountIds() {
|
||||
// TODO: Increase the type of auth accounts that can be added to a user.
|
||||
if !handlers.ValidId(handlers.Id(a), password.AccountPrefix, oidc.AccountPrefix) {
|
||||
if !handlers.ValidId(handlers.Id(a),
|
||||
intglobals.OldPasswordAccountPrefix,
|
||||
intglobals.NewPasswordAccountPrefix,
|
||||
oidc.AccountPrefix,
|
||||
) {
|
||||
badFields["account_ids"] = "Values must be valid account ids."
|
||||
break
|
||||
}
|
||||
@@ -735,7 +739,11 @@ func validateSetUserAccountsRequest(req *pbs.SetUserAccountsRequest) error {
|
||||
}
|
||||
for _, a := range req.GetAccountIds() {
|
||||
// TODO: Increase the type of auth accounts that can be added to a user.
|
||||
if !handlers.ValidId(handlers.Id(a), password.AccountPrefix, oidc.AccountPrefix) {
|
||||
if !handlers.ValidId(handlers.Id(a),
|
||||
intglobals.OldPasswordAccountPrefix,
|
||||
intglobals.NewPasswordAccountPrefix,
|
||||
oidc.AccountPrefix,
|
||||
) {
|
||||
badFields["account_ids"] = "Values must be valid account ids."
|
||||
break
|
||||
}
|
||||
@@ -759,7 +767,11 @@ func validateRemoveUserAccountsRequest(req *pbs.RemoveUserAccountsRequest) error
|
||||
}
|
||||
for _, a := range req.GetAccountIds() {
|
||||
// TODO: Increase the type of auth accounts that can be added to a user.
|
||||
if !handlers.ValidId(handlers.Id(a), password.AccountPrefix, oidc.AccountPrefix) {
|
||||
if !handlers.ValidId(handlers.Id(a),
|
||||
intglobals.OldPasswordAccountPrefix,
|
||||
intglobals.NewPasswordAccountPrefix,
|
||||
oidc.AccountPrefix,
|
||||
) {
|
||||
badFields["account_ids"] = "Values must be valid account ids."
|
||||
break
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/cmd/config"
|
||||
"github.com/hashicorp/boundary/internal/db/schema"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/intglobals"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/servers"
|
||||
"github.com/hashicorp/boundary/sdk/strutil"
|
||||
@@ -33,9 +34,9 @@ const (
|
||||
DefaultTestUnprivilegedLoginName = "user"
|
||||
DefaultTestPassword = "passpass"
|
||||
DefaultTestUserId = "u_1234567890"
|
||||
DefaultTestPasswordAccountId = "apw_1234567890"
|
||||
DefaultTestPasswordAccountId = intglobals.NewPasswordAccountPrefix + "_1234567890"
|
||||
DefaultTestOidcAccountId = "acctoidc_1234567890"
|
||||
DefaultTestUnprivilegedPasswordAccountId = "apw_0987654321"
|
||||
DefaultTestUnprivilegedPasswordAccountId = intglobals.NewPasswordAccountPrefix + "_0987654321"
|
||||
DefaultTestUnprivilegedOidcAccountId = "acctoidc_0987654321"
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user