Adds authorization module tests

This commit is contained in:
BinaryAlley committed 2025-01-01 22:56:07 +02:00
1 parent 718e1c49cf
commit 0114ff13e8
125 files changed
+10411 -203

No files matched your search

@@ -41,7 +41,7 @@ public class DeleteRoleEndpointSummary : Summary<DeleteRoleEndpoint, DeleteRoleR
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/roles"
instance = "/api/v1/roles/{roleId}"
},
new
{
@@ -49,7 +49,7 @@ public class DeleteRoleEndpointSummary : Summary<DeleteRoleEndpoint, DeleteRoleR
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/roles"
instance = "/api/v1/roles/{roleId}"
},
new
{
@@ -57,7 +57,7 @@ public class DeleteRoleEndpointSummary : Summary<DeleteRoleEndpoint, DeleteRoleR
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/roles"
instance = "/api/v1/roles/{roleId}"
}
}
);
@@ -71,7 +71,7 @@ public class DeleteRoleEndpointSummary : Summary<DeleteRoleEndpoint, DeleteRoleR
title = "General.Failure",
status = 403,
detail = "AdminRoleCannotBeDeleted",
instance = "/api/v1/roles",
instance = "/api/v1/roles/{roleId}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
},
new
@@ -80,7 +80,7 @@ public class DeleteRoleEndpointSummary : Summary<DeleteRoleEndpoint, DeleteRoleR
title = "General.Failure",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/roles",
instance = "/api/v1/roles/{roleId}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
}
@@ -93,7 +93,7 @@ public class DeleteRoleEndpointSummary : Summary<DeleteRoleEndpoint, DeleteRoleR
title = "General.NotFound",
status = 404,
detail = "RoleNotFound",
instance = "/api/v1/roles",
instance = "/api/v1/roles/{roleId}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
);
@@ -105,7 +105,7 @@ public class DeleteRoleEndpointSummary : Summary<DeleteRoleEndpoint, DeleteRoleR
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/roles",
instance = "/api/v1/roles/{roleId}",
errors = new Dictionary<string, string[]>
{
{
@@ -11,12 +11,12 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.GetRo
/// Class used for providing a textual description for the <see cref="GetRolesEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetPermissionsEndpointSummary : Summary<GetRolesEndpoint, EmptyRequest>
public class GetRolesEndpointSummary : Summary<GetRolesEndpoint, EmptyRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetPermissionsEndpointSummary"/> class.
/// Initializes a new instance of the <see cref="GetRolesEndpointSummary"/> class.
/// </summary>
public GetPermissionsEndpointSummary()
public GetRolesEndpointSummary()
{
Summary = "Gets the collection of authorization roles.";
Description = "Gets the entire list of authorization roles.";
@@ -42,8 +42,8 @@ public class AddLibraryEndpointSummary : Summary<AddLibraryEndpoint, AddLibraryR
ResponseParam<LibraryResponse>(r => r.Title, "The title of the media library.");
ResponseParam<LibraryResponse>(r => r.LibraryType, "The type of the media library.");
ResponseParam<LibraryResponse>(r => r.ContentLocations, "The file system paths of the directories where the media library elements are located.");
ResponseParam<LibraryResponse>(r => r.Created, "The date and time when the entity was created.");
ResponseParam<LibraryResponse>(r => r.Updated, "The date and time when the entity was last updated.");
ResponseParam<LibraryResponse>(r => r.CreatedOnUtc, "The date and time when the entity was created.");
ResponseParam<LibraryResponse>(r => r.UpdatedOnUtc, "The date and time when the entity was last updated.");
Response(201, "The media library was successfully created.", example:
@@ -53,8 +53,8 @@ public class AddLibraryEndpointSummary : Summary<AddLibraryEndpoint, AddLibraryR
Title: "TV Shows",
LibraryType: LibraryType.TvShow,
ContentLocations: ["/media/tv shows/drama/", "/media/tv shows/SCI-FI/"],
Created: DateTime.UtcNow,
Updated: default
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default
));
@@ -35,8 +35,8 @@ public class GetLibraryEndpointSummary : Summary<GetLibraryEndpoint, GetLibraryR
ResponseParam<LibraryResponse>(r => r.Title, "The title of the media library.");
ResponseParam<LibraryResponse>(r => r.LibraryType, "The type of the media library.");
ResponseParam<LibraryResponse>(r => r.ContentLocations, "The file system paths of the directories where the media library elements are located.");
ResponseParam<LibraryResponse>(r => r.Created, "The date and time when the entity was created.");
ResponseParam<LibraryResponse>(r => r.Updated, "The date and time when the entity was last updated.");
ResponseParam<LibraryResponse>(r => r.CreatedOnUtc, "The date and time when the entity was created.");
ResponseParam<LibraryResponse>(r => r.UpdatedOnUtc, "The date and time when the entity was last updated.");
Response(200, "The media library is returned.", example: new LibraryResponse(
Id: Guid.NewGuid(),
@@ -44,8 +44,8 @@ public class GetLibraryEndpointSummary : Summary<GetLibraryEndpoint, GetLibraryR
Title: "TV Shows",
LibraryType: LibraryType.TvShow,
ContentLocations: ["/media/tv shows/drama/", "/media/tv shows/SCI-FI/"],
Created: DateTime.UtcNow,
Updated: default
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default
));
@@ -46,8 +46,8 @@ public class UpdateLibraryEndpointSummary : Summary<UpdateLibraryEndpoint, Updat
ResponseParam<LibraryResponse>(r => r.Title, "The title of the media library.");
ResponseParam<LibraryResponse>(r => r.LibraryType, "The type of the media library.");
ResponseParam<LibraryResponse>(r => r.ContentLocations, "The file system paths of the directories where the media library elements are located.");
ResponseParam<LibraryResponse>(r => r.Created, "The date and time when the entity was created.");
ResponseParam<LibraryResponse>(r => r.Updated, "The date and time when the entity was last updated.");
ResponseParam<LibraryResponse>(r => r.CreatedOnUtc, "The date and time when the entity was created.");
ResponseParam<LibraryResponse>(r => r.UpdatedOnUtc, "The date and time when the entity was last updated.");
Response(200, "The media library was successfully updated.", example:
@@ -57,8 +57,8 @@ public class UpdateLibraryEndpointSummary : Summary<UpdateLibraryEndpoint, Updat
Title: "TV Shows",
LibraryType: LibraryType.TvShow,
ContentLocations: ["/media/tv shows/drama/", "/media/tv shows/SCI-FI/"],
Created: DateTime.UtcNow,
Updated: default
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default
));
@@ -169,8 +169,8 @@ public class AddLibraryEndpointSummary : Summary<AddBookEndpoint, AddBookRequest
RequestParam(r => r.Ratings, "The list of ratings for this book. Required.");
ResponseParam<BookResponse>(r => r.Id, "The unique identifier of the entity.");
ResponseParam<BookResponse>(r => r.Created, "The date and time when the entity was created.");
ResponseParam<BookResponse>(r => r.Updated, "The date and time when the entity was last updated.");
ResponseParam<BookResponse>(r => r.CreatedOnUtc, "The date and time when the entity was created.");
ResponseParam<BookResponse>(r => r.UpdatedOnUtc, "The date and time when the entity was last updated.");
ResponseParam<BookResponse>(r => r.Metadata, "The written content metadata of the book.");
ResponseParam<BookResponse>(r => r.Metadata.Title, "The title of the media item.");
ResponseParam<BookResponse>(r => r.Metadata.OriginalTitle, "The original title of the media item.");
@@ -276,8 +276,8 @@ public class AddLibraryEndpointSummary : Summary<AddBookEndpoint, AddBookRequest
VoteCount: 87654
)
],
Created: DateTime.UtcNow,
Updated: default
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default
)
);
@@ -128,8 +128,8 @@ public class GetBooksEndpointSummary : Summary<GetBooksEndpoint>
VoteCount: 87654
)
],
Created: DateTime.UtcNow,
Updated: default
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default
),
new(
Id: Guid.NewGuid(),
@@ -229,8 +229,8 @@ public class GetBooksEndpointSummary : Summary<GetBooksEndpoint>
VoteCount: 90000
)
],
Created: DateTime.UtcNow,
Updated: default
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default
)
}
);
@@ -42,7 +42,7 @@ public class GetUsersEndpoint : BaseEndpoint<EmptyRequest, IResult>
}
/// <summary>
/// Gets the list of authorization roles.
/// Gets the list of users.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(EmptyRequest _, CancellationToken cancellationToken)
@@ -0,0 +1,71 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Responses.UsersManagement.Users;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.GetUsers;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetUsersEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetUsersEndpointSummary : Summary<GetUsersEndpoint, EmptyRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetUsersEndpointSummary"/> class.
/// </summary>
public GetUsersEndpointSummary()
{
Summary = "Gets the collection of users.";
Description = "Gets the entire list of users.";
Response(200, "The list of users is returned.",
example: new[] {
new UserResponse(Id: Guid.NewGuid(), "TestUsername", DateTime.UtcNow, null)
});
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/auth/users"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/auth/users"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/auth/users"
}
}
);
Response(403, "The request failed because the current user is not an Admin.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/auth/users",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
}
}