Skip to content

Commit b2dae35

Browse files
bosorawisdkanney
authored andcommitted
test: credentials store grants (#5592)
* first test with all the required setup * v1 of test * add primitive func and more test * refactor read tests into a single top level * move token generation to a function * add test for creates * add delete tests * add update test * only check for version and update_time * move setup resource into testcase to support grants with specific ID * add member tests * add group-member test example with multiple actions * remove duplicate group membership tests * ran make gen * fix missing parentID bug * fix typo * fix test names and add test cases * switch from google/uuid to hashicorp/go-uuid * add comment to groupmember tests * small comment change * pull shared test utility code from PR #5418 * refactor role grants out of authtoken package * unexport utility function * Remove dead code * lint and make gen * fix role cration logic * fix password TestAccountFunc implementation * implement TestAccountFunc for LDAP * implement TestAccountFunc for OIDC * implement TestUserFunc for managed groups * use managed groups in grants test * undo removal of authtoken.TestAuthTokenWithRoles for future refactor * switch from list to map based test case for create tests * undo merge mistakes * fix merge mistakes * lint * add setup examples * add output fields tests for getgroup * reimplement with reflect * add test for CreateGroup * add all single resource action tests * add list test * rename function argument * move AssertOutputFields to handlers package * fix lint * make gen * use proto.Message instead of custom interface * switch to hashicorp/go-uuid * fix typo * fix error message * id= to ids= * make generating test accounts more randomized * Trigger CI checks * refactor auth/iam grants test setup * lint * minor comment fix * use Id instead of ID * make user/account setup in iam returns account instead of just account ID * missed one change * save * add list tests * add get test * add create and delete test * add delete and update tests * more tests * fix collection_authorized_actions grants not resolving * complete output_fields tests * fix import groups * make gen * fixed broken tests * fix rebase * switch all tests to TestUserGroupGrantsFunc * remove duplicate test
1 parent 26caa44 commit b2dae35

File tree

2 files changed

+1717
-95
lines changed

2 files changed

+1717
-95
lines changed

internal/daemon/controller/handlers/credentialstores/credentialstore_service.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func (s Service) GetCredentialStore(ctx context.Context, req *pbs.GetCredentialS
330330
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, cs.GetPublicId(), IdActions).Strings()))
331331
}
332332
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
333-
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, cs.GetPublicId())
333+
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, authResults.Scope, cs.GetPublicId())
334334
if err != nil {
335335
return nil, err
336336
}
@@ -375,7 +375,7 @@ func (s Service) CreateCredentialStore(ctx context.Context, req *pbs.CreateCrede
375375
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, cs.GetPublicId(), IdActions).Strings()))
376376
}
377377
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
378-
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, cs.GetPublicId())
378+
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, authResults.Scope, cs.GetPublicId())
379379
if err != nil {
380380
return nil, err
381381
}
@@ -423,7 +423,7 @@ func (s Service) UpdateCredentialStore(ctx context.Context, req *pbs.UpdateCrede
423423
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, cs.GetPublicId(), IdActions).Strings()))
424424
}
425425
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
426-
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, cs.GetPublicId())
426+
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, authResults.Scope, cs.GetPublicId())
427427
if err != nil {
428428
return nil, err
429429
}
@@ -703,7 +703,7 @@ func newOutputOpts(
703703
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authorizedActions))
704704
}
705705
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
706-
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, item.GetPublicId())
706+
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, authzScopes[item.GetProjectId()], item.GetPublicId())
707707
if err != nil {
708708
return nil, false, err
709709
}
@@ -1006,15 +1006,15 @@ func validateListRequest(ctx context.Context, req *pbs.ListCredentialStoresReque
10061006
return nil
10071007
}
10081008

1009-
func calculateAuthorizedCollectionActions(ctx context.Context, authResults auth.VerifyResults, id string) (map[string]*structpb.ListValue, error) {
1009+
func calculateAuthorizedCollectionActions(ctx context.Context, authResults auth.VerifyResults, itemScopeInfo *scopes.ScopeInfo, itemId string) (map[string]*structpb.ListValue, error) {
10101010
var collectionActions map[string]*structpb.ListValue
10111011
var err error
1012-
switch globals.ResourceInfoFromPrefix(id).Subtype {
1012+
switch globals.ResourceInfoFromPrefix(itemId).Subtype {
10131013
case vault.Subtype:
1014-
collectionActions, err = auth.CalculateAuthorizedCollectionActions(ctx, authResults, vaultCollectionTypeMap, authResults.Scope, id)
1014+
collectionActions, err = auth.CalculateAuthorizedCollectionActions(ctx, authResults, vaultCollectionTypeMap, itemScopeInfo, itemId)
10151015

10161016
case static.Subtype:
1017-
collectionActions, err = auth.CalculateAuthorizedCollectionActions(ctx, authResults, staticCollectionTypeMap, authResults.Scope, id)
1017+
collectionActions, err = auth.CalculateAuthorizedCollectionActions(ctx, authResults, staticCollectionTypeMap, itemScopeInfo, itemId)
10181018
}
10191019
if err != nil {
10201020
return nil, err

0 commit comments

Comments
 (0)