Skip to content

Commit

Permalink
fix(testing:bolt:inmem): add org admin permissions during onboarding …
Browse files Browse the repository at this point in the history
…generate
  • Loading branch information
desa committed Jan 9, 2019
1 parent bef148f commit 0ec2295
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
9 changes: 9 additions & 0 deletions bolt/onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ func (c *Client) Generate(ctx context.Context, req *platform.OnboardingRequest)

perms := platform.OperPermissions()
perms = append(perms, platform.OrgAdminPermissions(o.ID)...)
writeBucketPerm, err := platform.NewPermissionAtID(bucket.ID, platform.WriteAction, platform.BucketsResource)
if err != nil {
return nil, err
}
readBucketPerm, err := platform.NewPermissionAtID(bucket.ID, platform.ReadAction, platform.BucketsResource)
if err != nil {
return nil, err
}
perms = append(perms, *writeBucketPerm, *readBucketPerm)

auth := &platform.Authorization{
UserID: u.ID,
Expand Down
2 changes: 1 addition & 1 deletion bolt/onboarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ func initOnboardingService(f platformtesting.OnboardingFields, t *testing.T) (pl
}
}

func TestGenerate(t *testing.T) {
func TestOnboardingService_Generate(t *testing.T) {
platformtesting.Generate(initOnboardingService, t)
}
15 changes: 14 additions & 1 deletion inmem/onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,24 @@ func (s *Service) Generate(ctx context.Context, req *platform.OnboardingRequest)
if err = s.CreateBucket(ctx, bucket); err != nil {
return nil, err
}

perms := platform.OperPermissions()
perms = append(perms, platform.OrgAdminPermissions(o.ID)...)
writeBucketPerm, err := platform.NewPermissionAtID(bucket.ID, platform.WriteAction, platform.BucketsResource)
if err != nil {
return nil, err
}
readBucketPerm, err := platform.NewPermissionAtID(bucket.ID, platform.ReadAction, platform.BucketsResource)
if err != nil {
return nil, err
}
perms = append(perms, *writeBucketPerm, *readBucketPerm)

auth := &platform.Authorization{
UserID: u.ID,
Description: fmt.Sprintf("%s's Token", u.Name),
OrgID: o.ID,
Permissions: platform.OperPermissions(),
Permissions: perms,
}
if err = s.CreateAuthorization(ctx, auth); err != nil {
return nil, err
Expand Down
18 changes: 17 additions & 1 deletion testing/onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func Generate(
UserID: MustIDBase16(oneID),
Description: "admin's Token",
OrgID: MustIDBase16(twoID),
Permissions: platform.OperPermissions(),
Permissions: mustGeneratePermissions(MustIDBase16(twoID), MustIDBase16(threeID)),
},
},
},
Expand Down Expand Up @@ -203,6 +203,22 @@ func Generate(

}

func mustGeneratePermissions(orgID, bucketID platform.ID) []platform.Permission {
perms := platform.OperPermissions()
perms = append(perms, platform.OrgAdminPermissions(orgID)...)
writeBucketPerm, err := platform.NewPermissionAtID(bucketID, platform.WriteAction, platform.BucketsResource)
if err != nil {
panic(err)
}
readBucketPerm, err := platform.NewPermissionAtID(bucketID, platform.ReadAction, platform.BucketsResource)
if err != nil {
panic(err)
}
perms = append(perms, *writeBucketPerm, *readBucketPerm)

return perms
}

const (
oneID = "020f755c3c082000"
twoID = "020f755c3c082001"
Expand Down

0 comments on commit 0ec2295

Please sign in to comment.