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
8 changes: 8 additions & 0 deletions Api/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public async Task<ActionResult> DeleteUserAsync([FromBody] DeletionModel deletio
}
}

[Authorize]
[RequiresPermission(UserClaimsProvider.AUTO_TESTS_ONLY_IsSetUserPasswordBypassingEmailConfirmationAllowed)]
[HttpPost("set-password")]
public Task SetPassword([FromBody] PasswordSetModel passwordSetModel)
{
return _usersService.SetPasswordBypassingEmailConfirmationAsync(passwordSetModel);
}

[HttpPost("reset")]
public Task RegisterUser([FromQuery] string corporateEmail)
{
Expand Down
8 changes: 8 additions & 0 deletions Api/Services/Models/PasswordSetModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Api.Services.Models;

public readonly struct PasswordSetModel
{
public string CorporateEmail { get; init; }

public string NewPassword { get; init; }
}
16 changes: 15 additions & 1 deletion Api/Services/UsersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task ResetPasswordAsync(string corporateEmail)
var user = await _findUserQuery.FindUserByCorporateEmailAsync(corporateEmail);
if (user == null)
{
throw new NullReferenceException("User doesn't exists");
throw new NullReferenceException("User doesn't exist");
}

var resetToken = await _userManager.GeneratePasswordResetTokenAsync(user);
Expand Down Expand Up @@ -126,5 +126,19 @@ public async Task ChangePasswordAsync(PasswordChangeModel passwordChangeModel)
await _userManager.ResetPasswordAsync(user, passwordChangeModel.PasswordResetToken,
passwordChangeModel.NewPassword);
}

public async Task SetPasswordBypassingEmailConfirmationAsync(PasswordSetModel passwordSetModel)
{
var user = await _findUserQuery.FindUserByCorporateEmailAsync(passwordSetModel.CorporateEmail);

if (user == null)
{
throw new NullReferenceException($"User with the corporate email [{passwordSetModel.CorporateEmail}] doesn't exist");
}

var resetToken = await _userManager.GeneratePasswordResetTokenAsync(user);

await _userManager.ResetPasswordAsync(user, resetToken, passwordSetModel.NewPassword);
}
}
}
2 changes: 2 additions & 0 deletions Api/UserClaimsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class UserClaimsProvider : IUserClaimsProvider

public const string IsAccountsHardDeleteAllowed = "IsAccountsHardDeleteAllowed";

public const string AUTO_TESTS_ONLY_IsSetUserPasswordBypassingEmailConfirmationAllowed = "AUTO_TESTS_ONLY_IsSetUserPasswordBypassingEmailConfirmationAllowed";

public Task<List<Claim>> GetUserClaimsAsync(string login)
{
throw new NotImplementedException();
Expand Down
6 changes: 3 additions & 3 deletions e2e/KarateDockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM openjdk:11-jre-slim
FROM eclipse-temurin:17-jre-noble

RUN apt-get update && apt-get install -y curl

RUN apt-get install -y unzip

RUN curl -o /karate.jar -L 'https://github.com/intuit/karate/releases/download/v1.4.1/karate-1.4.1.jar'
RUN curl -o /karate.jar -L 'https://github.com/intuit/karate/releases/download/v1.5.1/karate-1.5.1.jar'

COPY ./e2e/js-utils.js .

ENTRYPOINT ["java", "-jar", "karate.jar"]
ENTRYPOINT ["java", "-jar", "karate.jar"]