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

Updated validation methods signatures (#13)

Improved code coverage results
This commit is contained in:
2021-05-30 18:12:45 +03:00
committed by GitHub
parent f669201554
commit f866fb2c80
6 changed files with 38 additions and 28 deletions
@@ -26,7 +26,8 @@ namespace SimpleOTP.Test.Models
public void TestShortLinkGenerator()
{
OTPConfiguration config = OTPConfiguration.GenerateConfiguration("FoxDev Studio", "eugene@xfox111.net");
System.Diagnostics.Debug.WriteLine(config.Id);
var testId = config.Id;
System.Diagnostics.Debug.WriteLine(testId);
Uri uri = config.GetUri();
Assert.AreEqual($"otpauth://totp/FoxDev+Studio:eugene@xfox111.net?secret={config.Secret}&issuer=FoxDev+Studio", uri.AbsoluteUri);
}
+2 -1
View File
@@ -29,7 +29,8 @@ namespace SimpleOTP.Test
OTPConfiguration config = OTPConfiguration.GetConfiguration("ESQVTYRM2CWZC3NX24GRRWIAUUWVHWQH", "FoxDev Studio", "eugene@xfox111.net");
config.Period = TimeSpan.FromSeconds(3);
using OTPFactory factory = new (config, 1500);
System.Diagnostics.Debug.WriteLine(factory.Configuration);
var testGetConfig = factory.Configuration;
System.Diagnostics.Debug.WriteLine(testGetConfig);
var code = factory.CurrentCode;
factory.Configuration = config;
+15 -11
View File
@@ -66,13 +66,15 @@ namespace SimpleOTP.Test
OTPService.GenerateCode(ref totpConfig, DateTime.UtcNow.AddSeconds(15)).Code,
OTPService.GenerateCode(ref totpConfig, DateTime.UtcNow.AddSeconds(45)).Code,
};
Assert.IsFalse(OTPService.ValidateCode(codes[0], totpConfig));
Assert.IsTrue(OTPService.ValidateCode(codes[1], totpConfig));
Assert.IsTrue(OTPService.ValidateCode(codes[2], totpConfig));
Assert.IsTrue(OTPService.ValidateCode(codes[3], totpConfig));
Assert.IsFalse(OTPService.ValidateCode(codes[4], totpConfig));
Assert.IsFalse(OTPService.ValidateTotp(codes[0], totpConfig));
Assert.IsTrue(OTPService.ValidateTotp(codes[1], totpConfig));
Assert.IsTrue(OTPService.ValidateTotp(codes[2], totpConfig));
Assert.IsTrue(OTPService.ValidateTotp(codes[3], totpConfig));
Assert.IsFalse(OTPService.ValidateTotp(codes[4], totpConfig));
Assert.IsTrue(OTPService.ValidateCode(codes[0], totpConfig, TimeSpan.FromSeconds(60)));
Assert.IsTrue(OTPService.ValidateTotp(codes[0], totpConfig, TimeSpan.FromSeconds(60)));
Assert.ThrowsException<ArgumentException>(() => OTPService.ValidateTotp(0, hotpConfig));
}
/// <summary>
@@ -92,19 +94,21 @@ namespace SimpleOTP.Test
};
hotpConfig.Counter = 10002;
Assert.IsFalse(OTPService.ValidateCode(codes[0], ref hotpConfig, 1, true));
Assert.IsFalse(OTPService.ValidateHotp(codes[0], ref hotpConfig, 1, true));
Assert.AreEqual(10002, hotpConfig.Counter);
Assert.IsTrue(OTPService.ValidateCode(codes[1], ref hotpConfig, 1, true));
Assert.IsTrue(OTPService.ValidateHotp(codes[1], ref hotpConfig, 1, true));
Assert.AreEqual(10001, hotpConfig.Counter);
hotpConfig.Counter = 10002;
Assert.IsTrue(OTPService.ValidateCode(codes[2], ref hotpConfig, 1, true));
Assert.IsTrue(OTPService.ValidateHotp(codes[2], ref hotpConfig, 1, true));
Assert.AreEqual(10002, hotpConfig.Counter);
hotpConfig.Counter = 10002;
Assert.IsTrue(OTPService.ValidateCode(codes[3], ref hotpConfig, 1, true));
Assert.IsTrue(OTPService.ValidateHotp(codes[3], ref hotpConfig, 1, true));
Assert.AreEqual(10003, hotpConfig.Counter);
hotpConfig.Counter = 10002;
Assert.IsFalse(OTPService.ValidateCode(codes[4], ref hotpConfig, 1, true));
Assert.IsFalse(OTPService.ValidateHotp(codes[4], ref hotpConfig, 1, true));
Assert.AreEqual(10002, hotpConfig.Counter);
Assert.ThrowsException<ArgumentException>(() => OTPService.ValidateHotp(0, ref totpConfig, 1, true));
}
}
}