Exemplo n.º 1
0
        public void Validate_ValidToken_DeosNotThrowException()
        {
            var timeProvider = new UtcTimeProviderStub(DateTime.UtcNow);
            var userSession  = CreateActiveSession();

            var token = userSession.GenerateToken(timeProvider.UtcNow);

            userSession.Validate(token, timeProvider);
        }
Exemplo n.º 2
0
        public void Validate_ExpiredToken_ThrowsException()
        {
            var timeProvider = new UtcTimeProviderStub(DateTime.UtcNow);

            var userSession = CreateActiveSession();
            var token       = userSession.GenerateToken(timeProvider.UtcNow);

            timeProvider.UtcNow += UserSession.TokenExpirationPeriod + TimeSpan.FromSeconds(1);

            Assert.Throws <InvalidTokenException>(() => userSession.Validate(token, timeProvider));
        }
Exemplo n.º 3
0
        public void Validate_InvalidToken_ThrowsException()
        {
            var timeProvider = new UtcTimeProviderStub(DateTime.UtcNow);

            var userSession1 = CreateActiveSession("some1");
            var userSession2 = CreateActiveSession("some2");

            var token = userSession2.GenerateToken(timeProvider.UtcNow);

            Assert.Throws <InvalidTokenException>(() => userSession1.Validate(token, timeProvider));
        }