Skip to content

Commit 10c41f0

Browse files
committed
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 d4fecb5 commit 10c41f0

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
@@ -324,7 +324,7 @@ func (s Service) GetCredentialStore(ctx context.Context, req *pbs.GetCredentialS
324324
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, cs.GetPublicId(), IdActions).Strings()))
325325
}
326326
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
327-
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, cs.GetPublicId())
327+
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, authResults.Scope, cs.GetPublicId())
328328
if err != nil {
329329
return nil, err
330330
}
@@ -369,7 +369,7 @@ func (s Service) CreateCredentialStore(ctx context.Context, req *pbs.CreateCrede
369369
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, cs.GetPublicId(), IdActions).Strings()))
370370
}
371371
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
372-
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, cs.GetPublicId())
372+
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, authResults.Scope, cs.GetPublicId())
373373
if err != nil {
374374
return nil, err
375375
}
@@ -417,7 +417,7 @@ func (s Service) UpdateCredentialStore(ctx context.Context, req *pbs.UpdateCrede
417417
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, cs.GetPublicId(), IdActions).Strings()))
418418
}
419419
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
420-
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, cs.GetPublicId())
420+
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, authResults.Scope, cs.GetPublicId())
421421
if err != nil {
422422
return nil, err
423423
}
@@ -697,7 +697,7 @@ func newOutputOpts(
697697
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authorizedActions))
698698
}
699699
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
700-
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, item.GetPublicId())
700+
collectionActions, err := calculateAuthorizedCollectionActions(ctx, authResults, authzScopes[item.GetProjectId()], item.GetPublicId())
701701
if err != nil {
702702
return nil, false, err
703703
}
@@ -1000,15 +1000,15 @@ func validateListRequest(ctx context.Context, req *pbs.ListCredentialStoresReque
10001000
return nil
10011001
}
10021002

1003-
func calculateAuthorizedCollectionActions(ctx context.Context, authResults auth.VerifyResults, id string) (map[string]*structpb.ListValue, error) {
1003+
func calculateAuthorizedCollectionActions(ctx context.Context, authResults auth.VerifyResults, itemScopeInfo *scopes.ScopeInfo, itemId string) (map[string]*structpb.ListValue, error) {
10041004
var collectionActions map[string]*structpb.ListValue
10051005
var err error
1006-
switch globals.ResourceInfoFromPrefix(id).Subtype {
1006+
switch globals.ResourceInfoFromPrefix(itemId).Subtype {
10071007
case vault.Subtype:
1008-
collectionActions, err = auth.CalculateAuthorizedCollectionActions(ctx, authResults, vaultCollectionTypeMap, authResults.Scope, id)
1008+
collectionActions, err = auth.CalculateAuthorizedCollectionActions(ctx, authResults, vaultCollectionTypeMap, itemScopeInfo, itemId)
10091009

10101010
case static.Subtype:
1011-
collectionActions, err = auth.CalculateAuthorizedCollectionActions(ctx, authResults, staticCollectionTypeMap, authResults.Scope, id)
1011+
collectionActions, err = auth.CalculateAuthorizedCollectionActions(ctx, authResults, staticCollectionTypeMap, itemScopeInfo, itemId)
10121012
}
10131013
if err != nil {
10141014
return nil, err

0 commit comments

Comments
 (0)