@@ -8,8 +8,10 @@ import (
8
8
"testing"
9
9
10
10
"github.com/hashicorp/boundary/globals"
11
+ "github.com/hashicorp/boundary/internal/auth"
12
+ "github.com/hashicorp/boundary/internal/auth/oidc"
11
13
"github.com/hashicorp/boundary/internal/authtoken"
12
- "github.com/hashicorp/boundary/internal/daemon/controller/auth"
14
+ controllerauth "github.com/hashicorp/boundary/internal/daemon/controller/auth"
13
15
"github.com/hashicorp/boundary/internal/daemon/controller/handlers/roles"
14
16
"github.com/hashicorp/boundary/internal/db"
15
17
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
@@ -46,21 +48,24 @@ func TestGrants_ReadActions(t *testing.T) {
46
48
kmsCache := kms .TestKms (t , conn , wrap )
47
49
s , err := roles .NewService (ctx , repoFn , 1000 )
48
50
require .NoError (t , err )
51
+ rw := db .New (conn )
52
+ atRepo , err := authtoken .NewRepository (ctx , rw , rw , kmsCache )
53
+ require .NoError (t , err )
49
54
50
55
org1 , _ := iam .TestScopes (t , iamRepo )
51
56
org2 , proj2 := iam .TestScopes (t , iamRepo )
52
57
proj3 := iam .TestProject (t , iamRepo , org2 .PublicId )
53
58
54
59
var defaultOrg1Roles []string
55
- org1Roles , err := s .ListRoles (auth .DisabledAuthTestContext (repoFn , org1 .GetPublicId ()), & pbs.ListRolesRequest {
60
+ org1Roles , err := s .ListRoles (controllerauth .DisabledAuthTestContext (repoFn , org1 .GetPublicId ()), & pbs.ListRolesRequest {
56
61
ScopeId : org1 .GetPublicId (),
57
62
})
58
63
require .NoError (t , err )
59
64
for _ , r := range org1Roles .Items {
60
65
defaultOrg1Roles = append (defaultOrg1Roles , r .GetId ())
61
66
}
62
67
63
- org2Roles , err := s .ListRoles (auth .DisabledAuthTestContext (repoFn , org2 .GetPublicId ()), & pbs.ListRolesRequest {
68
+ org2Roles , err := s .ListRoles (controllerauth .DisabledAuthTestContext (repoFn , org2 .GetPublicId ()), & pbs.ListRolesRequest {
64
69
ScopeId : org2 .GetPublicId (),
65
70
})
66
71
require .NoError (t , err )
@@ -69,7 +74,7 @@ func TestGrants_ReadActions(t *testing.T) {
69
74
defaultOrg2Roles = append (defaultOrg2Roles , r .GetId ())
70
75
}
71
76
72
- proj2Roles , err := s .ListRoles (auth .DisabledAuthTestContext (repoFn , proj2 .GetPublicId ()), & pbs.ListRolesRequest {
77
+ proj2Roles , err := s .ListRoles (controllerauth .DisabledAuthTestContext (repoFn , proj2 .GetPublicId ()), & pbs.ListRolesRequest {
73
78
ScopeId : proj2 .GetPublicId (),
74
79
})
75
80
require .NoError (t , err )
@@ -78,7 +83,7 @@ func TestGrants_ReadActions(t *testing.T) {
78
83
defaultProj2Roles = append (defaultProj2Roles , r .GetId ())
79
84
}
80
85
81
- proj3Roles , err := s .ListRoles (auth .DisabledAuthTestContext (repoFn , proj3 .GetPublicId ()), & pbs.ListRolesRequest {
86
+ proj3Roles , err := s .ListRoles (controllerauth .DisabledAuthTestContext (repoFn , proj3 .GetPublicId ()), & pbs.ListRolesRequest {
82
87
ScopeId : proj3 .GetPublicId (),
83
88
})
84
89
require .NoError (t , err )
@@ -97,7 +102,7 @@ func TestGrants_ReadActions(t *testing.T) {
97
102
testcases := []struct {
98
103
name string
99
104
input * pbs.ListRolesRequest
100
- rolesToCreate []authtoken. TestRoleGrantsForToken
105
+ userFunc func () ( * iam. User , auth. Account )
101
106
wantErr error
102
107
addRolesAtThisScope bool
103
108
wantIDs []string
@@ -108,13 +113,13 @@ func TestGrants_ReadActions(t *testing.T) {
108
113
ScopeId : globals .GlobalPrefix ,
109
114
Recursive : true ,
110
115
},
111
- rolesToCreate : []authtoken. TestRoleGrantsForToken {
116
+ userFunc : iam . TestUserManagedGroupGrantsFunc ( t , conn , kmsCache , globals . GlobalPrefix , oidc . TestAuthMethodWithAccountInManagedGroup , []iam. TestRoleGrantsRequest {
112
117
{
113
- RoleScopeId : globals .GlobalPrefix ,
114
- GrantStrings : []string {"ids=*;type=role;actions=list,read" },
115
- GrantScopes : []string {globals .GrantScopeThis , globals .GrantScopeChildren },
118
+ RoleScopeId : globals .GlobalPrefix ,
119
+ Grants : []string {"ids=*;type=role;actions=list,read" },
120
+ GrantScopes : []string {globals .GrantScopeThis , globals .GrantScopeChildren },
116
121
},
117
- },
122
+ }) ,
118
123
addRolesAtThisScope : true ,
119
124
wantErr : nil ,
120
125
wantIDs : append (append ([]string {
@@ -128,13 +133,13 @@ func TestGrants_ReadActions(t *testing.T) {
128
133
ScopeId : org2 .PublicId ,
129
134
Recursive : true ,
130
135
},
131
- rolesToCreate : []authtoken. TestRoleGrantsForToken {
136
+ userFunc : iam . TestUserManagedGroupGrantsFunc ( t , conn , kmsCache , globals . GlobalPrefix , oidc . TestAuthMethodWithAccountInManagedGroup , []iam. TestRoleGrantsRequest {
132
137
{
133
- RoleScopeId : org2 .PublicId ,
134
- GrantStrings : []string {"ids=*;type=role;actions=list,read" },
135
- GrantScopes : []string {globals .GrantScopeThis , globals .GrantScopeChildren },
138
+ RoleScopeId : org2 .PublicId ,
139
+ Grants : []string {"ids=*;type=role;actions=list,read" },
140
+ GrantScopes : []string {globals .GrantScopeThis , globals .GrantScopeChildren },
136
141
},
137
- },
142
+ }) ,
138
143
addRolesAtThisScope : true ,
139
144
wantErr : nil ,
140
145
wantIDs : append (append ([]string {
@@ -146,15 +151,17 @@ func TestGrants_ReadActions(t *testing.T) {
146
151
147
152
for _ , tc := range testcases {
148
153
t .Run (tc .name , func (t * testing.T ) {
149
- tok := authtoken .TestAuthTokenWithRoles (t , conn , kmsCache , globals .GlobalPrefix , tc .rolesToCreate )
150
- fullGrantAuthCtx := auth .TestAuthContextFromToken (t , conn , wrap , tok , iamRepo )
154
+ user , account := tc .userFunc ()
155
+ tok , err := atRepo .CreateAuthToken (ctx , user , account .GetPublicId ())
156
+ require .NoError (t , err )
157
+ fullGrantAuthCtx := controllerauth .TestAuthContextFromToken (t , conn , wrap , tok , iamRepo )
151
158
152
159
// TestAuthTokenWithRoles creates a default role, so we need to add it to the expected list
153
160
// if the grant scope contains 'this'
154
161
// This will add the default roles to the expected list of roles
155
162
if tc .addRolesAtThisScope {
156
163
var rolesAtThisScope []string
157
- rolesAtThisScopeList , err := s .ListRoles (auth .DisabledAuthTestContext (repoFn , tc .input .ScopeId ), & pbs.ListRolesRequest {
164
+ rolesAtThisScopeList , err := s .ListRoles (controllerauth .DisabledAuthTestContext (repoFn , tc .input .ScopeId ), & pbs.ListRolesRequest {
158
165
ScopeId : tc .input .ScopeId ,
159
166
})
160
167
require .NoError (t , err )
0 commit comments