Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
TokenResponse token = await this.GetToken(cancellationToken);
SendEmailRequest emailRequest = this.BuildEmailConfirmationRequest(newIdentityUser, uri);
sendEmailResult = await this.MessagingServiceClient.SendEmail(token.AccessToken, emailRequest, cancellationToken);
// TODO: not so fussed if this fails, maybe just some logging that can be alerted on???
if (sendEmailResult.IsFailed)
Logger.LogWarning($"Error sending email to {newIdentityUser.Email} as part of user creation {sendEmailResult}");
}

if (createResult.IsFailed || addRolesToUserResult.IsFailed || addClaimsToUserResult.IsFailed) {
Expand Down Expand Up @@ -526,7 +527,7 @@

public static class PasswordGenerator
{
public static Result<string> GenerateRandomPassword(PasswordOptions? opts = null)

Check warning on line 530 in SecurityService.BusinessLogic/RequestHandlers/UserRequestHandler.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Firefox UI

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 530 in SecurityService.BusinessLogic/RequestHandlers/UserRequestHandler.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Non UI

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
opts ??= DefaultOptions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,40 @@ await this.AuthenticationDbContext.Roles.AddAsync(new IdentityRole{
await this.AuthenticationDbContext.SaveChangesAsync();

this.SetupRequestHandlers.UserValidator.Setup(s => s.ValidateAsync(It.IsAny<UserManager<ApplicationUser>>(), It.IsAny<ApplicationUser>())).ReturnsAsync(IdentityResult.Success);
this.SetupRequestHandlers.MessagingServiceClient.Setup(m => m.SendEmail(It.IsAny<String>(), It.IsAny<SendEmailRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success);

Result result = await this.RequestHandler.Handle(command, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();

Int32 userCount = await this.AuthenticationDbContext.Users.CountAsync();
userCount.ShouldBe(1);
}

[Fact]
public async Task UserRequestHandler_CreateUserCommand_EmailSendFailed_RequestIsHandled()
{
SecurityServiceCommands.CreateUserCommand command = new(Guid.Parse(TestData.UserId),
TestData.GivenName,
TestData.MiddleName,
TestData.FamilyName,
TestData.UserName,
"password",
TestData.EmailAddress,
TestData.PhoneNumber,
TestData.Claims,
TestData.Roles);


await this.AuthenticationDbContext.Roles.AddAsync(new IdentityRole
{
Id = Guid.NewGuid().ToString(),
Name = "TESTROLE1",
NormalizedName = "TESTROLE1"
});
await this.AuthenticationDbContext.SaveChangesAsync();

this.SetupRequestHandlers.UserValidator.Setup(s => s.ValidateAsync(It.IsAny<UserManager<ApplicationUser>>(), It.IsAny<ApplicationUser>())).ReturnsAsync(IdentityResult.Success);
this.SetupRequestHandlers.MessagingServiceClient.Setup(m => m.SendEmail(It.IsAny<String>(), It.IsAny<SendEmailRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure);

Result result = await this.RequestHandler.Handle(command, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
Expand Down Expand Up @@ -231,6 +265,7 @@ public async Task UserRequestHandler_CreateUserCommand_NullRoles_RequestIsHandle
command = command with { Roles = null };

this.SetupRequestHandlers.UserValidator.Setup(s => s.ValidateAsync(It.IsAny<UserManager<ApplicationUser>>(), It.IsAny<ApplicationUser>())).ReturnsAsync(IdentityResult.Success);
this.SetupRequestHandlers.MessagingServiceClient.Setup(m => m.SendEmail(It.IsAny<String>(), It.IsAny<SendEmailRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success);

var result = await this.RequestHandler.Handle(command, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
Expand All @@ -244,8 +279,9 @@ public async Task UserRequestHandler_CreateUserCommand_EmptyRoles_RequestIsHandl
SecurityServiceCommands.CreateUserCommand command = TestData.CreateUserCommand;
command = command with { Roles = new List<String>() };
this.SetupRequestHandlers.UserValidator.Setup(s => s.ValidateAsync(It.IsAny<UserManager<ApplicationUser>>(), It.IsAny<ApplicationUser>())).ReturnsAsync(IdentityResult.Success);

var result = await this.RequestHandler.Handle(command, CancellationToken.None);
this.SetupRequestHandlers.MessagingServiceClient.Setup(m => m.SendEmail(It.IsAny<String>(), It.IsAny<SendEmailRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success);

Result result = await this.RequestHandler.Handle(command, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();

Int32 userCount = await this.AuthenticationDbContext.Users.CountAsync();
Expand Down
2 changes: 1 addition & 1 deletion SecurityService/Controllers/ApiResourceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public async Task<IActionResult> GetApiResources(CancellationToken cancellationT
/// <summary>
/// The controller name
/// </summary>
public const String ControllerName = "apiresources";
private const String ControllerName = "apiresources";

/// <summary>
/// The controller route
Expand Down
2 changes: 1 addition & 1 deletion SecurityService/Controllers/ApiScopeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public async Task<IActionResult> GetApiScopes(CancellationToken cancellationToke
/// <summary>
/// The controller name
/// </summary>
public const String ControllerName = "apiscopes";
private const String ControllerName = "apiscopes";

/// <summary>
/// The controller route
Expand Down
2 changes: 1 addition & 1 deletion SecurityService/Controllers/ClientController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public async Task<IActionResult> GetClients(CancellationToken cancellationToken)
/// <summary>
/// The controller name
/// </summary>
public const String ControllerName = "clients";
private const String ControllerName = "clients";

/// <summary>
/// The controller route
Expand Down
2 changes: 1 addition & 1 deletion SecurityService/Controllers/DeveloperController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task<IActionResult> GetLastSMSMessage(CancellationToken cancellatio
/// <summary>
/// The controller name
/// </summary>
public const String ControllerName = "developer";
private const String ControllerName = "developer";

/// <summary>
/// The controller route
Expand Down
2 changes: 1 addition & 1 deletion SecurityService/Controllers/IdentityResourceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public async Task<IActionResult> GetIdentityResources(CancellationToken cancella
/// <summary>
/// The controller name
/// </summary>
public const String ControllerName = "identityresources";
private const String ControllerName = "identityresources";

/// <summary>
/// The controller route
Expand Down
2 changes: 1 addition & 1 deletion SecurityService/Controllers/RoleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public async Task<IActionResult> GetRoles(CancellationToken cancellationToken)
/// <summary>
/// The controller name
/// </summary>
public const String ControllerName = "roles";
private const String ControllerName = "roles";

/// <summary>
/// The controller route
Expand Down
2 changes: 1 addition & 1 deletion SecurityService/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public async Task<IActionResult> GetUsers([FromQuery] String userName,
/// <summary>
/// The controller name
/// </summary>
public const String ControllerName = "users";
private const String ControllerName = "users";

/// <summary>
/// The controller route
Expand Down
Loading