feat(api): ResetPassword admin — TempPasswordGenerator, handler, endpoint POST /{id}/password/reset [UDT-008]
Batch 7: POST /api/v1/users/{id}/password/reset (admin only).
- TempPasswordGenerator: RandomNumberGenerator.Fill, 12-char min, full charset diversity, never logs result
- ResetUsuarioPasswordCommandHandler: self-reset guard, 404, hash, mustChangePassword=true, revoke all tokens
- ExceptionFilter: CannotSelfResetException → 400 {error: cannot-self-reset}
- Unit tests: TempPasswordGeneratorTests (8), ResetUsuarioPasswordCommandHandlerTests (5)
- Integration tests: ResetPasswordEndpointTests (6) — 200/length/self-reset/404/401/403
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
using SIGCM2.Application.Common;
|
||||
|
||||
namespace SIGCM2.Application.Tests.Common;
|
||||
|
||||
public class TempPasswordGeneratorTests
|
||||
{
|
||||
[Fact]
|
||||
public void Generate_Default_Length_Is_12()
|
||||
{
|
||||
var pwd = TempPasswordGenerator.Generate();
|
||||
Assert.Equal(12, pwd.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generate_Always_Has_Uppercase_Letter()
|
||||
{
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
var pwd = TempPasswordGenerator.Generate();
|
||||
Assert.True(pwd.Any(char.IsUpper), $"No uppercase found in: {pwd}");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generate_Always_Has_Lowercase_Letter()
|
||||
{
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
var pwd = TempPasswordGenerator.Generate();
|
||||
Assert.True(pwd.Any(char.IsLower), $"No lowercase found in: {pwd}");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generate_Always_Has_Digit()
|
||||
{
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
var pwd = TempPasswordGenerator.Generate();
|
||||
Assert.True(pwd.Any(char.IsDigit), $"No digit found in: {pwd}");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generate_Always_Has_Special_Char()
|
||||
{
|
||||
const string symbols = "!@#$%&*+-=?";
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
var pwd = TempPasswordGenerator.Generate();
|
||||
Assert.True(pwd.Any(c => symbols.Contains(c)), $"No symbol found in: {pwd}");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generate_Below_8_Throws_ArgumentOutOfRangeException()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => TempPasswordGenerator.Generate(7));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generate_100_Samples_All_Pass_Diversity()
|
||||
{
|
||||
const string symbols = "!@#$%&*+-=?";
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
var pwd = TempPasswordGenerator.Generate(12);
|
||||
Assert.True(pwd.Length >= 12);
|
||||
Assert.True(pwd.Any(char.IsUpper));
|
||||
Assert.True(pwd.Any(char.IsLower));
|
||||
Assert.True(pwd.Any(char.IsDigit));
|
||||
Assert.True(pwd.Any(c => symbols.Contains(c)));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generate_Custom_Length_Respects_Length()
|
||||
{
|
||||
var pwd = TempPasswordGenerator.Generate(16);
|
||||
Assert.Equal(16, pwd.Length);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user