public void Too_Late_Returns_False() { // Arrange var key = Rnd.ByteF.Get(8); var interval = TotpF.GetCurrentInterval(30) - 1; var code = TotpF.GenerateCode(key, interval, 6); // Act var result = TotpF.VerifyCode(key, code, TotpSettings.Default with { IntervalTolerance = false });
public void Incorrect_Key_Returns_False() { // Arrange var key = Rnd.ByteF.Get(8); var code = TotpF.GenerateCode(key, TotpSettings.Default); // Act var result = TotpF.VerifyCode(Rnd.ByteF.Get(8), code, TotpSettings.Default); // Assert Assert.False(result); }
public void Returns_Correct_Interval(int period) { // Arrange var seconds = (ulong)(DateTime.UtcNow - DateTime.UnixEpoch).TotalSeconds; var expected = seconds / (ulong)period; // Act var result = TotpF.GetCurrentInterval(period); // Assert Assert.Equal(expected, result); }
public void Generates_Same_Hash_For_Same_Inputs() { // Arrange var key = Rnd.ByteF.Get(8); var counter = Rnd.ByteF.Get(8); // Act var r0 = TotpF.ComputeHash(key, counter); var r1 = TotpF.ComputeHash(key, counter); // Assert Assert.Equal(r0, r1); }
public void Generates_Different_Hash_For_Different_Counters() { // Arrange var key = Rnd.ByteF.Get(8); var c0 = Rnd.ByteF.Get(8); var c1 = Rnd.ByteF.Get(8); // Act var r0 = TotpF.ComputeHash(key, c0); var r1 = TotpF.ComputeHash(key, c1); // Assert Assert.NotEqual(r0, r1); }
public void Generates_Different_Hash_For_Different_Keys() { // Arrange var k0 = Rnd.ByteF.Get(8); var k1 = Rnd.ByteF.Get(8); var counter = Rnd.ByteF.Get(8); // Act var r0 = TotpF.ComputeHash(k0, counter); var r1 = TotpF.ComputeHash(k1, counter); // Assert Assert.NotEqual(r0, r1); }
public void Generates_256bit_Hash() { // Arrange var key = Rnd.ByteF.Get(8); var counter = Rnd.ByteF.Get(8); var expected = new HMACSHA256(key).ComputeHash(counter); // Act var result = TotpF.ComputeHash(key, counter); // Assert Assert.Equal(expected, result); Assert.Equal(32, result.Length); }
public void Uses_Correct_Period() { // Arrange var key = Rnd.ByteF.Get(8); var period = Rnd.Int; var settings = TotpSettings.Default with { PeriodSeconds = period }; var interval = TotpF.GetCurrentInterval(period); var expected = TotpF.GenerateCode(key, interval, TotpSettings.Default.CodeLength); // Act var result = TotpF.GenerateCode(key, settings); // Assert Assert.Equal(expected, result); }
public void Uses_Correct_Code_Length(int length) { // Arrange var key = Rnd.ByteF.Get(8); var settings = TotpSettings.Default with { CodeLength = length }; var interval = TotpF.GetCurrentInterval(TotpSettings.Default.PeriodSeconds); var expected = TotpF.GenerateCode(key, interval, length); // Act var result = TotpF.GenerateCode(key, settings); // Assert Assert.Equal(expected, result); } }