This commit is contained in:
@@ -4,7 +4,7 @@ namespace Messenger.Api.Tests;
|
||||
|
||||
public class PasswordHasherTests
|
||||
{
|
||||
private readonly Argon2PasswordHasher _hasher = new();
|
||||
private readonly Argon2PasswordHasher _hasher = new(new PasswordHashingSettings(4, TimeSpan.FromSeconds(30)));
|
||||
|
||||
[Fact]
|
||||
public async Task Hash_IsArgon2idPhcString_WithoutPlaintext()
|
||||
@@ -45,6 +45,22 @@ public class PasswordHasherTests
|
||||
Assert.False(await _hasher.VerifyAsync(hash, prefix + "B", CancellationToken.None));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Hash_WhenAllSlotsAreBusy_FailsWithBusyException()
|
||||
{
|
||||
// Один слот и почти нулевое ожидание: параллельные вызовы не копят память, лишние получают исключение (→ 503).
|
||||
var hasher = new Argon2PasswordHasher(new PasswordHashingSettings(1, TimeSpan.FromMilliseconds(20)));
|
||||
|
||||
var attempts = await Task.WhenAll(Enumerable.Range(0, 6).Select(async _ =>
|
||||
{
|
||||
try { await hasher.HashAsync("some-long-enough-password", CancellationToken.None); return true; }
|
||||
catch (PasswordHasherBusyException) { return false; }
|
||||
}));
|
||||
|
||||
Assert.Contains(true, attempts); // кто-то получил слот
|
||||
Assert.Contains(false, attempts); // остальные получили контролируемый отказ
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Verify_UnknownUser_ReturnsFalse()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user