@@ -243,4 +243,106 @@ public async Task WhenDeleteClientsWithValidClient_ShouldDeleteClientSuccessfull
243243 Assert . Equal ( HttpStatusCode . NoContent , response . StatusCode ) ;
244244 Assert . DoesNotContain ( result , current => current . Id == client . Id ) ;
245245 }
246+
247+ [ Fact ( DisplayName = "[e2e] - when DELETE /clients/{id} with non-existent client should return 404 #ERROR-2D943" ) ]
248+ public async Task WhenDeleteClientsWithNonExistentClient_ShouldReturnNotFound ( )
249+ {
250+ /* arrange: authenticate user and get access token */
251+ var httpClient = factory . HttpClient . WithRealmHeader ( "master" ) ;
252+ var credentials = new AuthenticationCredentials
253+ {
254+ Username = "federation.testing.user" ,
255+ Password = "federation.testing.password"
256+ } ;
257+
258+ var authenticationResponse = await httpClient . PostAsJsonAsync ( "api/v1/identity/authenticate" , credentials ) ;
259+ var authenticationResult = await authenticationResponse . Content . ReadFromJsonAsync < AuthenticationResult > ( ) ;
260+
261+ Assert . NotNull ( authenticationResult ) ;
262+ Assert . NotEmpty ( authenticationResult . AccessToken ) ;
263+
264+ httpClient . WithAuthorization ( authenticationResult . AccessToken ) ;
265+
266+ /* arrange: prepare request with a non-existent client ID */
267+ var nonExistentClientId = Guid . NewGuid ( ) . ToString ( ) ;
268+
269+ /* act: send DELETE request for non-existent client */
270+ var response = await httpClient . DeleteAsync ( $ "api/v1/clients/{ nonExistentClientId } ") ;
271+ var error = await response . Content . ReadFromJsonAsync < Error > ( ) ;
272+
273+ /* assert: response should be 404 Not Found */
274+ Assert . NotNull ( error ) ;
275+
276+ Assert . Equal ( HttpStatusCode . NotFound , response . StatusCode ) ;
277+ Assert . Equal ( ClientErrors . ClientDoesNotExist , error ) ;
278+ }
279+
280+ [ Fact ( DisplayName = "[e2e] - when GET /clients/{id}/permissions should return client's assigned permissions" ) ]
281+ public async Task WhenGetClientPermissions_ShouldReturnAssignedPermissions ( )
282+ {
283+ /* arrange: resolve required dependencies */
284+ var clientCollection = factory . Services . GetRequiredService < IClientCollection > ( ) ;
285+ var realmCollection = factory . Services . GetRequiredService < IRealmCollection > ( ) ;
286+
287+ /* arrange: authenticate user and get access token */
288+ var httpClient = factory . HttpClient . WithRealmHeader ( "master" ) ;
289+ var credentials = new AuthenticationCredentials
290+ {
291+ Username = "federation.testing.user" ,
292+ Password = "federation.testing.password"
293+ } ;
294+
295+ var authenticationResponse = await httpClient . PostAsJsonAsync ( "api/v1/identity/authenticate" , credentials ) ;
296+ var authenticationResult = await authenticationResponse . Content . ReadFromJsonAsync < AuthenticationResult > ( ) ;
297+
298+ Assert . NotNull ( authenticationResult ) ;
299+ Assert . NotEmpty ( authenticationResult . AccessToken ) ;
300+
301+ httpClient . WithAuthorization ( authenticationResult . AccessToken ) ;
302+
303+ /* arrange: create and insert client with assigned permissions */
304+ var realmFilters = RealmFilters . WithSpecifications ( )
305+ . WithName ( "master" )
306+ . Build ( ) ;
307+
308+ var realms = await realmCollection . GetRealmsAsync ( realmFilters , CancellationToken . None ) ;
309+ var realm = realms . FirstOrDefault ( ) ;
310+
311+ Assert . NotNull ( realm ) ;
312+
313+ var permission1 = _fixture . Build < Permission > ( )
314+ . With ( permission => permission . Name , $ "test.permission.{ Guid . NewGuid ( ) } ")
315+ . With ( permission => permission . RealmId , realm . Id )
316+ . With ( permission => permission . IsDeleted , false )
317+ . Create ( ) ;
318+
319+ var permission2 = _fixture . Build < Permission > ( )
320+ . With ( permission => permission . Name , $ "test.permission.{ Guid . NewGuid ( ) } ")
321+ . With ( permission => permission . RealmId , realm . Id )
322+ . With ( permission => permission . IsDeleted , false )
323+ . Create ( ) ;
324+
325+ var client = _fixture . Build < Client > ( )
326+ . With ( current => current . Name , $ "test-client-{ Guid . NewGuid ( ) } ")
327+ . With ( current => current . ClientId , $ "test-client-id-{ Guid . NewGuid ( ) } ")
328+ . With ( current => current . Secret , $ "test-client-secret-{ Guid . NewGuid ( ) } ")
329+ . With ( current => current . RealmId , realm . Id )
330+ . With ( current => current . IsDeleted , false )
331+ . With ( current => current . Permissions , [ permission1 , permission2 ] )
332+ . Create ( ) ;
333+
334+ await clientCollection . InsertAsync ( client ) ;
335+
336+ /* act: send GET request to retrieve client's permissions */
337+ var response = await httpClient . GetAsync ( $ "api/v1/clients/{ client . Id } /permissions") ;
338+ var permissions = await response . Content . ReadFromJsonAsync < IReadOnlyCollection < PermissionDetailsScheme > > ( ) ;
339+
340+ /* assert: response should be 200 OK */
341+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
342+ Assert . NotNull ( permissions ) ;
343+
344+ /* assert: assigned permissions should be returned */
345+ Assert . Contains ( permissions , permission => permission . Name == permission1 . Name ) ;
346+ Assert . Contains ( permissions , permission => permission . Name == permission2 . Name ) ;
347+ }
246348}
0 commit comments