public void ThrowsOnOld() { // Arrange var date = DateTime.Now; var nonce = Nonce.FromDate(date.Subtract(new TimeSpan(0, 0, 0, 6))); var verifier = new RequestsVerifier(1, 4); // Act & Assert Assert.Throws <AuthException>(() => verifier.VerifyAgeAndRepeatOnNewRequest(nonce)); }
public void AppenderDiffers() { // Arrange var date = DateTime.Now; // Act var appender1 = Nonce.FromDate(date).ToString().Split(':')[1]; var appender2 = Nonce.FromDate(date).ToString().Split(':')[1]; // Assert Assert.AreNotEqual(appender1, appender2); }
public void EqualsCreateFromStringAndDate() { // Arrange var expected = Nonce.FromDate(DateTime.Now); var actual = Nonce.FromString(expected.ToString()); // Act var result = actual.Equals(expected); // Assert Assert.IsTrue(result); }
public void ThrowsOnRepeat() { // Arrange var date = DateTime.Now; var nonce = Nonce.FromDate(date); var verifier = new RequestsVerifier(2, 4); // Act & Assert Assert.DoesNotThrow(() => verifier.VerifyAgeAndRepeatOnNewRequest(nonce)); Assert.Throws <AuthException>(() => verifier.VerifyAgeAndRepeatOnNewRequest(nonce)); }
public void CompareToNewerDateNonce() { // Arrange var date = DateTime.Now; var nonce1 = Nonce.FromDate(date); var nonce2 = Nonce.FromDate(date.Subtract(new TimeSpan(0, 0, 0, 1))); // Act var actual = nonce1.CompareTo(nonce2); // Assert Assert.IsTrue(actual > 0); }
public void CompareToSameDateNonce() { // Arrange var date = DateTime.Now; var nonce1 = Nonce.FromDate(date); var nonce2 = Nonce.FromDate(date); // Act var actual = nonce1.CompareTo(nonce2); // Assert Assert.AreEqual(0, actual); }
public void DateIsUnixTimeInUtc() { // Arrange var date = DateTime.Now; var nonce = Nonce.FromDate(date); var expected = ((DateTimeOffset)date.ToUniversalTime()).ToUnixTimeMilliseconds().ToString(); // Act var actual = nonce.ToString().Split(':')[0]; // Assert Assert.AreEqual(expected, actual); }
public void DoesntThrowOnRequestsInAgeAndClockTolerance() { // Arrange var date = DateTime.Now; var nonce1 = Nonce.FromDate(date.Subtract(new TimeSpan(0, 0, 0, 1))); var nonce2 = Nonce.FromDate(date.Subtract(new TimeSpan(0, 0, 0, 2))); var nonce3 = Nonce.FromDate(date.Subtract(new TimeSpan(0, 0, 0, 3))); var nonce4 = Nonce.FromDate(date.Subtract(new TimeSpan(0, 0, 0, 4))); var nonce5 = Nonce.FromDate(date.Subtract(new TimeSpan(0, 0, 0, 5))); var verifier = new RequestsVerifier(2, 4); // Act & Assert Assert.DoesNotThrow(() => verifier.VerifyAgeAndRepeatOnNewRequest(nonce1)); Assert.DoesNotThrow(() => verifier.VerifyAgeAndRepeatOnNewRequest(nonce2)); Assert.DoesNotThrow(() => verifier.VerifyAgeAndRepeatOnNewRequest(nonce3)); Assert.DoesNotThrow(() => verifier.VerifyAgeAndRepeatOnNewRequest(nonce4)); Assert.DoesNotThrow(() => verifier.VerifyAgeAndRepeatOnNewRequest(nonce5)); }