@@ -142,12 +142,49 @@ public async Task WhenPostPermissionsWithReservedSystemNameInNonMasterRealm_Shou
142142 Assert . NotNull ( realm ) ;
143143 Assert . Equal ( HttpStatusCode . Created , realmResponse . StatusCode ) ;
144144
145- /* arrange: authenticate realm via OAuth 2.0 client_credentials */
145+ /* arrange: create a client scoped to the new realm */
146+ var clientCollection = factory . Services . GetRequiredService < IClientCollection > ( ) ;
147+ var realmAdminClient = factory . HttpClient
148+ . WithRealmHeader ( realm . Name )
149+ . WithAuthorization ( masterAuthenticationResult . AccessToken ) ;
150+
151+ var clientPayload = _fixture . Build < ClientCreationScheme > ( )
152+ . With ( client => client . Name , "nubank" )
153+ . With ( client => client . Flows , [ Grant . ClientCredentials ] )
154+ . With ( client => client . RedirectUris , [ ] )
155+ . Create ( ) ;
156+
157+ var clientResponse = await realmAdminClient . PostAsJsonAsync ( "api/v1/clients" , clientPayload ) ;
158+
159+ Assert . NotNull ( clientResponse ) ;
160+ Assert . Equal ( HttpStatusCode . Created , clientResponse . StatusCode ) ;
161+
162+ var clientFilters = ClientFilters . WithSpecifications ( )
163+ . WithName ( clientPayload . Name )
164+ . Build ( ) ;
165+
166+ var clients = await clientCollection . GetClientsAsync ( clientFilters ) ;
167+ var client = clients . FirstOrDefault ( ) ;
168+
169+ Assert . NotEmpty ( clients ) ;
170+ Assert . NotNull ( client ) ;
171+
172+ /* arrange: assign CreatePermission to the client using the master-scoped admin client */
173+ var assignPayload = _fixture . Build < AssignClientPermissionScheme > ( )
174+ . With ( assignment => assignment . PermissionName , Permissions . CreatePermission )
175+ . Create ( ) ;
176+
177+ var assignment = await realmAdminClient . PostAsJsonAsync ( $ "api/v1/clients/{ client . Id } /permissions", assignPayload ) ;
178+
179+ Assert . NotNull ( assignment ) ;
180+ Assert . Equal ( HttpStatusCode . OK , assignment . StatusCode ) ;
181+
182+ /* arrange: authenticate via OAuth 2.0 client_credentials using the created client */
146183 var oauthCredentials = new Dictionary < string , string >
147184 {
148185 { "grant_type" , "client_credentials" } ,
149- { "client_id" , realm . ClientId } ,
150- { "client_secret" , realm . ClientSecret }
186+ { "client_id" , client . ClientId } ,
187+ { "client_secret" , client . Secret }
151188 } ;
152189
153190 var oauthContent = new FormUrlEncodedContent ( oauthCredentials ) ;
0 commit comments