Added skoruba user service integration test
This commit is contained in:
@@ -32,7 +32,7 @@ public interface IUserService
|
||||
|
||||
[Log]
|
||||
[Audit]
|
||||
Task<Result> AddUserRoleAsync(Guid targetUserId, string roleId, Guid userId, CancellationToken cancellationToken = default);
|
||||
Task<Result> AddUserRoleAsync(Guid targetUserId, Guid roleId, Guid userId, CancellationToken cancellationToken = default);
|
||||
|
||||
[Log]
|
||||
[Audit]
|
||||
@@ -57,5 +57,5 @@ public interface IUserService
|
||||
|
||||
[Log]
|
||||
[Audit]
|
||||
Task<Result> DeleteUserRoleAsync(Guid targetUserId, string roleId, Guid userId, CancellationToken cancellationToken = default);
|
||||
Task<Result> DeleteUserRoleAsync(Guid targetUserId, Guid roleId, Guid userId, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
@@ -24,23 +24,20 @@ public static class Security
|
||||
|
||||
if (!authOptions.Authority.EndsWith('/')) authOptions.Authority += "/";
|
||||
|
||||
services.AddClientCredentialsTokenManagement()
|
||||
services.AddClientCredentialsTokenManagement()
|
||||
.AddClient(SkorubaCredentialClient, client =>
|
||||
{
|
||||
client.TokenEndpoint = new Uri($"{authOptions.Authority}connect/token");
|
||||
client.ClientId = ClientId.Parse(authOptions.ClientId!);
|
||||
client.ClientSecret = ClientSecret.Parse(authOptions.ClientSecret!);
|
||||
client.Scope = Duende.AccessTokenManagement.Scope.ParseOrDefault(authOptions.Scope);
|
||||
});
|
||||
});
|
||||
|
||||
services.AddHttpClient(SkorubaHttpClient, client =>
|
||||
{
|
||||
client.BaseAddress = new Uri(configuration.GetConnectionString("SkorubaApi")!);
|
||||
}).AddClientCredentialsTokenHandler(ClientCredentialsClientName.Parse(SkorubaCredentialClient));
|
||||
|
||||
services.AddKeyedScoped(SkorubaHttpClient, (provider, key) =>
|
||||
provider.GetRequiredService<IHttpClientFactory>());
|
||||
|
||||
services.AddScoped<AuditInterceptor>();
|
||||
services.AddScoped<LoggingInterceptor>();
|
||||
services.AddSingleton<ProxyGenerator>();
|
||||
|
||||
@@ -14,7 +14,7 @@ public sealed class UserCacheService(UserService service, IDistributedCache cach
|
||||
public async Task<Result> AddUserClaimAsync(AddUserClaimRequest request, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
await service.AddUserClaimAsync(request, userId, cancellationToken);
|
||||
|
||||
public async Task<Result> AddUserRoleAsync(Guid targetUserId, string roleId, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
public async Task<Result> AddUserRoleAsync(Guid targetUserId, Guid roleId, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
await service.AddUserRoleAsync(targetUserId, roleId, userId, cancellationToken);
|
||||
|
||||
public async Task<Result> CreateUserAsync(string tenantIdHash, string idNumberHash, CreateUserRequest request, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
@@ -23,7 +23,7 @@ public sealed class UserCacheService(UserService service, IDistributedCache cach
|
||||
public async Task<Result> DeleteUserClaimAsync(string claimIdHash, Guid targetUserId, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
await service.DeleteUserClaimAsync(claimIdHash, targetUserId, userId, cancellationToken);
|
||||
|
||||
public async Task<Result> DeleteUserRoleAsync(Guid targetUserId, string roleId, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
public async Task<Result> DeleteUserRoleAsync(Guid targetUserId, Guid roleId, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
await service.DeleteUserRoleAsync(targetUserId, roleId, userId, cancellationToken);
|
||||
|
||||
public async Task<Result<Role[]>> GetSystemRolesAsync(Guid userId, CancellationToken cancellationToken = default) =>
|
||||
|
||||
@@ -164,7 +164,7 @@ public sealed class UserService(IDbContextFactory<ApplicationDbContext> contextF
|
||||
if (defaultRole == null)
|
||||
return Result.Fail(NotFoundError.Create("Role 'Contributor' not found."));
|
||||
|
||||
var roleAssignmentResult = await skorubaService.AddRoleAsync(newUserId, defaultRole.Id, cancellationToken);
|
||||
var roleAssignmentResult = await skorubaService.AddRoleAsync(newUserId, Guid.Parse(defaultRole.Id), cancellationToken);
|
||||
|
||||
if (roleAssignmentResult.IsFailed)
|
||||
return Result.Fail(UpdateError.Create("Failed to assign role to user."));
|
||||
@@ -255,7 +255,7 @@ public sealed class UserService(IDbContextFactory<ApplicationDbContext> contextF
|
||||
await Result.Try((Func<Task<Result<Role[]>>>)(async () =>
|
||||
await skorubaService.GetAvailableRolesAsync(cancellationToken: cancellationToken)));
|
||||
|
||||
public async Task<Result> DeleteUserRoleAsync(Guid targetUserId, string roleId, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
public async Task<Result> DeleteUserRoleAsync(Guid targetUserId, Guid roleId, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
await Result.Try((Func<Task<Result>>)(async () =>
|
||||
{
|
||||
await using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||
@@ -278,7 +278,7 @@ public sealed class UserService(IDbContextFactory<ApplicationDbContext> contextF
|
||||
.CausedBy(addClaimResult.Errors));
|
||||
}));
|
||||
|
||||
public async Task<Result> AddUserRoleAsync(Guid targetUserId, string roleId, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
public async Task<Result> AddUserRoleAsync(Guid targetUserId, Guid roleId, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
await Result.Try((Func<Task<Result>>)(async () =>
|
||||
{
|
||||
var userRolesResult = await skorubaService.GetUserRolesAsync(targetUserId, cancellationToken: cancellationToken);
|
||||
@@ -289,7 +289,7 @@ public sealed class UserService(IDbContextFactory<ApplicationDbContext> contextF
|
||||
|
||||
foreach (var role in userRolesResult.Value)
|
||||
{
|
||||
var deleteRoleResult = await skorubaService.RemoveRoleAsync(targetUserId, role.Id, cancellationToken);
|
||||
var deleteRoleResult = await skorubaService.RemoveRoleAsync(targetUserId, Guid.Parse(role.Id), cancellationToken);
|
||||
|
||||
if (deleteRoleResult.IsFailed)
|
||||
return Result.Fail(UpdateError.Create("Failed to remove existing user role.")
|
||||
@@ -308,7 +308,7 @@ public sealed class UserService(IDbContextFactory<ApplicationDbContext> contextF
|
||||
return Result.Fail(NotFoundError.Create("Failed to retrieve system roles.")
|
||||
.CausedBy(systemRoles.Errors));
|
||||
|
||||
var targetRole = systemRoles.Value.FirstOrDefault(r => r.Id == roleId);
|
||||
var targetRole = systemRoles.Value.FirstOrDefault(r => r.Id == roleId.ToString());
|
||||
|
||||
if (targetRole == null)
|
||||
return Result.Fail(NotFoundError.Create("Role not found."));
|
||||
|
||||
Reference in New Issue
Block a user