示例#1
0
        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));
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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));
        }
示例#5
0
        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);
        }
示例#6
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);
        }
示例#7
0
        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);
        }
示例#8
0
        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));
        }