Add PairingService with safe alphabet and 10-min TTL
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using backend.Pairing;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace backend.tests;
|
||||
|
||||
public class PairingServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void Generated_codes_use_only_safe_alphabet_and_are_8_chars()
|
||||
{
|
||||
var svc = new PairingService();
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var code = svc.GenerateCode();
|
||||
code.Length.Should().Be(8);
|
||||
code.Should().MatchRegex("^[A-HJ-KM-NP-Z2-9]+$");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generated_codes_are_not_all_identical()
|
||||
{
|
||||
var svc = new PairingService();
|
||||
var codes = Enumerable.Range(0, 20).Select(_ => svc.GenerateCode()).ToHashSet();
|
||||
codes.Count.Should().BeGreaterThan(15);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user