1
0
mirror of https://github.com/XFox111/SimpleOTP.git synced 2026-04-22 08:00:45 +03:00

Fixed invalid code generation on formatted secrets

This commit is contained in:
2021-12-05 20:44:17 +00:00
committed by GitHub
parent 4c63be6389
commit 42f968171b
3 changed files with 28 additions and 4 deletions
+25
View File
@@ -41,6 +41,31 @@ namespace SimpleOTP.Test
Assert.AreEqual(293657, code.Code);
}
/// <summary>
/// Test time-based OTP generator with customly formatted secret.
/// </summary>
[TestMethod("Secret format test")]
public void FormatTest()
{
Console.Write("Uppercase space-separated: ");
var config = totpConfig with { Secret = "JBSW Y3DP EHPK 3PXP" };
var code = OTPService.GenerateCode(ref config, time);
Assert.AreEqual(160102, code.Code);
Console.WriteLine("Passed.");
Console.Write("Lowercase space-separated: ");
config = totpConfig with { Secret = "jbsw y3dp ehpk 3pxp" };
code = OTPService.GenerateCode(ref config, time);
Assert.AreEqual(160102, code.Code);
Console.WriteLine("Passed.");
Console.Write("Lowercase: ");
config = totpConfig with { Secret = "jbswy3dpehpk3pxp" };
code = OTPService.GenerateCode(ref config, time);
Assert.AreEqual(160102, code.Code);
Console.WriteLine("Passed.");
}
/// <summary>
/// Test HOTP generator with pre-calculated code.
/// </summary>