Ejemplo n.º 1
0
        public void Should_Not_Be_Expired()
        {
            // Arrange
            var refreshToken = new RefreshToken("token", DateTime.MaxValue, "ip", Guid.Empty, FakeDateTime.UtcNow);

            // Assert
            refreshToken.IsExpired(FakeDateTime.UtcNow).Should().BeFalse();
            refreshToken.IsActive(FakeDateTime.UtcNow).Should().BeTrue();
        }
Ejemplo n.º 2
0
        private string ValidateRefreshToken(RefreshToken token)
        {
            if (token == null)
            {
                return("Invalid refresh token");
            }

            return(token.IsExpired() ? "Expired refresh token" : null);
        }
Ejemplo n.º 3
0
        public void IsExpired_ReturnsTrue_WhenTokenIsExpired()
        {
            //Arrange
            JsonWebToken token = new RefreshToken("token", 100);

            //Act
            var result = token.IsExpired();

            //Assert
            Assert.True(result);
        }
Ejemplo n.º 4
0
        public void IsExpired_ReturnsFalse_WhenTokenIsNotExpired()
        {
            //Arrange
            JsonWebToken token = new RefreshToken("token", DateTime.Now.AddSeconds(60).Ticks);

            //Act
            var result = token.IsExpired();

            //Assert
            Assert.False(result);
        }
Ejemplo n.º 5
0
        public void Should_Revoke()
        {
            // Arrange
            var refreshToken = new RefreshToken("token", DateTime.MaxValue, "ip", Guid.Empty, FakeDateTime.UtcNow);
            var command      = new RevokeRefreshToken.Command()
            {
                RefreshToken = "token", RemoteIpAddress = "ip2"
            };

            // Act
            refreshToken.Revoke(command, FakeDateTime.UtcNow);

            // Assert
            refreshToken.RevokedByIp.Should().BeEquivalentTo("ip2");
            refreshToken.RevokedOn.Should().BeMoreThan(TimeSpan.Zero);
            refreshToken.IsActive(FakeDateTime.UtcNow).Should().BeFalse();
            refreshToken.IsExpired(FakeDateTime.UtcNow).Should().BeFalse();
        }