public void WhenRoundtripping_ThenSucceeds()
	{
		var offset = new DateTimeOffset(2011, 2, 7, 4, 30, 20, TimeSpan.Zero);

		Assert.Equal(0, offset.Millisecond);

		var roundtrip = offset.ToEpochTime().ToDateTimeOffsetFromEpoch();

		Assert.Equal(offset, roundtrip);
	}
Exemplo n.º 2
0
    public void WhenRoundtripping_ThenSucceeds()
    {
        var offset = new DateTimeOffset(2011, 2, 7, 4, 30, 20, TimeSpan.Zero);

        Assert.Equal(0, offset.Millisecond);

        var roundtrip = offset.ToEpochTime().ToDateTimeOffsetFromEpoch();

        Assert.Equal(offset, roundtrip);
    }
        public void WhenTokenExpiryClaimExpiresBeforeClaimsCacheDuration_CacheExpiry_ShouldUseTokenExpiryClaim()
        {
            ExpiryClaimSaysTokenExpiresInMinutes = 1;
            CacheEvictsTokensAfterMinutes        = 5;
            Arrange(() =>
            {
                // mimic the DateTimeOffset rounding that happens via serialisation/deserialisation in the actual implementation
                ExpectedCacheExpiry = ExpiryClaimSaysTokenExpiresAt.ToEpochTime().ToDateTimeOffsetFromEpoch();
            });

            // act
            Sut.AddAsync(token, Claims);

            Mock.Get(_cache).Verify(c =>
                                    c.Add(It.IsAny <string>(), It.IsAny <object>(), It.Is <DateTimeOffset>(d => d == ExpectedCacheExpiry)));
        }
		void Arrange(Action specifyExpectedCacheExpiry) {
			_cache = Mock.Of<ICache>();
			_clock = Mock.Of<IClock>(c => c.UtcNow == DateTimeOffset.Now);
			_options = new IdentityServerBearerTokenAuthenticationOptions
				{
					ValidationResultCacheDuration = TimeSpan.FromMinutes(CacheEvictsTokensAfterMinutes)
				};
			ExpiryClaimSaysTokenExpiresAt = _clock.UtcNow.AddMinutes(ExpiryClaimSaysTokenExpiresInMinutes);
			CacheExpiryEvictsTokenAt = _clock.UtcNow.Add(_options.ValidationResultCacheDuration);
			
			// setup claims to include expiry claim
			Claims = new[] {new Claim("bar","baz"), new Claim(ClaimTypes.Expiration,ExpiryClaimSaysTokenExpiresAt.ToEpochTime().ToString()) };

			specifyExpectedCacheExpiry();

			DebugToConsole(DateTime.Now, ExpiryClaimSaysTokenExpiresAt,  _options, CacheExpiryEvictsTokenAt, ExpectedCacheExpiry);
			Sut = new InMemoryValidationResultCache(_options, _clock, _cache);
		}
        void Arrange(Action specifyExpectedCacheExpiry)
        {
            _cache   = Mock.Of <ICache>();
            _clock   = Mock.Of <IClock>(c => c.UtcNow == DateTimeOffset.Now);
            _options = new IdentityServerBearerTokenAuthenticationOptions
            {
                ValidationResultCacheDuration = TimeSpan.FromMinutes(CacheEvictsTokensAfterMinutes)
            };
            ExpiryClaimSaysTokenExpiresAt = _clock.UtcNow.AddMinutes(ExpiryClaimSaysTokenExpiresInMinutes);
            CacheExpiryEvictsTokenAt      = _clock.UtcNow.Add(_options.ValidationResultCacheDuration);

            // setup claims to include expiry claim
            Claims = new[] { new Claim("bar", "baz"), new Claim(ClaimTypes.Expiration, ExpiryClaimSaysTokenExpiresAt.ToEpochTime().ToString()) };

            specifyExpectedCacheExpiry();

            DebugToConsole(DateTime.Now, ExpiryClaimSaysTokenExpiresAt, _options, CacheExpiryEvictsTokenAt, ExpectedCacheExpiry);
            Sut = new InMemoryValidationResultCache(_options, _clock, _cache);
        }