示例#1
0
        public void ValidateToken_ReturnsValidateTokenResultExpiredIfTokenIsExpiredTest()
        {
            // Arrange
            Mock <IOptions <TokenServiceOptions> > mockOptions = new Mock <IOptions <TokenServiceOptions> >();
            TokenServiceOptions dataProtectionServiceOptions   = new TokenServiceOptions();

            mockOptions.Setup(o => o.Value).Returns(dataProtectionServiceOptions);

            Mock <ITimeService> mockTimeService = new Mock <ITimeService>();

            mockTimeService.SetupSequence(t => t.UtcNow).
            Returns(DateTimeOffset.MinValue).
            Returns(DateTimeOffset.UtcNow);

            DataProtectionTokenService <StubAccount> dataProtectionTokenService =
                new DataProtectionTokenService <StubAccount>(_dataProtectionProvider,
                                                             mockOptions.Object,
                                                             mockTimeService.Object);

            string token = dataProtectionTokenService.GenerateToken(_testInvalidPurpose, _testAccount);

            // Act
            ValidateTokenResult result = dataProtectionTokenService.ValidateToken(_testValidPurpose, token, _testAccount);

            // Assert
            Assert.Equal(ValidateTokenResult.Expired, result);
        }
示例#2
0
        public void GenerateToken_GeneratesTokenTest()
        {
            // Arrange
            DataProtectionTokenService <StubAccount> dataProtectionTokenService =
                new DataProtectionTokenService <StubAccount>(_dataProtectionProvider,
                                                             CreateTokenServiceOptions().Object,
                                                             _testTimeService);

            // Act
            string token = dataProtectionTokenService.GenerateToken(_testValidPurpose, _testAccount);

            // Assert
            Assert.NotNull(token);
        }
示例#3
0
        public void ValidateToken_ReturnsValidateTokenResultInvalidIfTokenIsInvalidTest()
        {
            // Arrange
            DataProtectionTokenService <StubAccount> dataProtectionTokenService =
                new DataProtectionTokenService <StubAccount>(_dataProtectionProvider,
                                                             CreateTokenServiceOptions().Object,
                                                             _testTimeService);

            string token = dataProtectionTokenService.GenerateToken(_testInvalidPurpose, _testAccount);

            // Act
            ValidateTokenResult result = dataProtectionTokenService.ValidateToken(_testValidPurpose, token, _testAccount);

            // Assert
            Assert.Equal(ValidateTokenResult.Invalid, result);
        }