public GreetingServiceGreetShould() { _timeService = new TestTimeService() { Now = DateTime.Now }; _greetingService = new GreetingService(_timeService); }
public void ChangeStateTodoToDoneTimeTest() { var timeService = new TestTimeService { Time = new DateTime(2019, 10, 24, 22, 00, 00) }; var task = new TaskModel(timeService, 1, TaskStates.Todo, null, null); task.ChangeState(TaskStates.Done); Assert.AreEqual(TaskStates.Done, task.State); Assert.AreEqual(timeService.Time, task.Started); Assert.AreEqual(timeService.Time, task.Ended); }
public void ChangeStateInProgressToDoneWithDifferentTimeTest() { var timeService = new TestTimeService { Time = new DateTime(2019, 10, 24, 22, 00, 00) }; var startTime = new DateTime(2019, 10, 24, 21, 00, 00); var task = new TaskModel(timeService, 1, TaskStates.InProgress, startTime, null); task.ChangeState(TaskStates.Done); Assert.AreEqual(TaskStates.Done, task.State); Assert.AreEqual(startTime, task.Started); Assert.AreEqual(timeService.Time, task.Ended); }
public virtual void SetUp() { TimeService = new TestTimeService(ServiceStartTime, TimeSpan.FromMilliseconds(50)); }
public async Task ValidateKeyExpirationAsync() { using (var harness = CreateTestHarness()) { harness.HttpManager.AddInstanceDiscoveryMockHandler(); PoPAuthenticationConfiguration popConfig = new PoPAuthenticationConfiguration(new Uri("https://www.contoso.com/path1/path2?queryParam1=a&queryParam2=b")); popConfig.HttpMethod = HttpMethod.Get; var app = ConfidentialClientApplicationBuilder.Create(TestConstants.ClientId) .WithHttpManager(harness.HttpManager) .WithExperimentalFeatures() .WithClientSecret("some-secret") .BuildConcrete(); TokenCacheHelper.PopulateCache(app.AppTokenCacheInternal.Accessor); harness.HttpManager.AddSuccessTokenResponseMockHandlerForPost( authority: TestConstants.AuthorityCommonTenant, responseMessage: MockHelpers.CreateSuccessfulClientCredentialTokenResponseMessage(token: $"header.{Guid.NewGuid()}.signature", tokenType: "pop")); harness.HttpManager.AddSuccessTokenResponseMockHandlerForPost( authority: TestConstants.AuthorityCommonTenant, responseMessage: MockHelpers.CreateSuccessfulClientCredentialTokenResponseMessage(token: $"header.{Guid.NewGuid()}.signature", tokenType: "pop")); Guid correlationId = Guid.NewGuid(); TestTimeService testClock = new TestTimeService(); PoPProviderFactory.TimeService = testClock; var result = await app.AcquireTokenForClient(TestConstants.s_scope) .WithProofOfPossession(popConfig) .ExecuteAsync(CancellationToken.None) .ConfigureAwait(false); var initialToken = result.AccessToken; //Advance time 7 hours. Should still be the same key and token testClock.MoveToFuture(TimeSpan.FromHours(7)); PoPProviderFactory.TimeService = testClock; result = await app.AcquireTokenForClient(TestConstants.s_scope) .WithProofOfPossession(popConfig) .ExecuteAsync(CancellationToken.None) .ConfigureAwait(false); Assert.AreEqual(GetAccessTokenFromPopToken(result.AccessToken), GetAccessTokenFromPopToken(initialToken)); Assert.AreEqual(GetModulusFromPopToken(result.AccessToken), GetModulusFromPopToken(initialToken)); Assert.IsTrue(result.AuthenticationResultMetadata.TokenSource == TokenSource.Cache); //Advance time 2 hours. Should be a different key testClock.MoveToFuture(TimeSpan.FromHours(2)); PoPProviderFactory.TimeService = testClock; result = await app.AcquireTokenForClient(TestConstants.s_scope) .WithProofOfPossession(popConfig) .ExecuteAsync(CancellationToken.None) .ConfigureAwait(false); Assert.AreNotEqual(GetModulusFromPopToken(result.AccessToken), GetModulusFromPopToken(initialToken)); Assert.AreNotEqual(GetAccessTokenFromPopToken(result.AccessToken), GetAccessTokenFromPopToken(initialToken)); Assert.IsTrue(result.AuthenticationResultMetadata.TokenSource == TokenSource.IdentityProvider); } }
public GreetingServiceGreetShould() { _timeService = new TestTimeService() { Now = DateTime.Now }; _greetingService = new GreetingService(_timeService); }
public async Task CacheKey_Includes_POPKid_Async() { using (var httpManager = new MockHttpManager()) { ConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(TestConstants.ClientId) .WithClientSecret(TestConstants.ClientSecret) .WithHttpManager(httpManager) .WithExperimentalFeatures(true) .BuildConcrete(); var testTimeService = new TestTimeService(); PoPProviderFactory.TimeService = testTimeService; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, new Uri(ProtectedUrl)); var popConfig = new PoPAuthenticationConfiguration(request); var cacheAccess = app.AppTokenCache.RecordAccess(); httpManager.AddInstanceDiscoveryMockHandler(); httpManager.AddMockHandlerSuccessfulClientCredentialTokenResponseMessage(tokenType: "pop"); // Act Trace.WriteLine("1. AcquireTokenForClient "); var result = await app.AcquireTokenForClient(TestConstants.s_scope.ToArray()) .WithAuthority(TestConstants.AuthorityUtidTenant) .WithProofOfPossession(popConfig) .ExecuteAsync() .ConfigureAwait(false); // Assert Assert.AreEqual(TokenSource.IdentityProvider, result.AuthenticationResultMetadata.TokenSource); string expectedKid = GetKidFromJwk(PoPProviderFactory.GetOrCreateProvider().CannonicalPublicKeyJwk); string actualCacheKey = cacheAccess.LastBeforeAccessNotificationArgs.SuggestedCacheKey; Assert.AreEqual( string.Format( CultureInfo.InvariantCulture, "{0}{1}_{2}_AppTokenCache", expectedKid, TestConstants.ClientId, TestConstants.Utid), actualCacheKey); // Arrange - force a new key by moving to the future (PoPProviderFactory.TimeService as TestTimeService).MoveToFuture( PoPProviderFactory.KeyRotationInterval.Add(TimeSpan.FromMinutes(10))); httpManager.AddMockHandlerSuccessfulClientCredentialTokenResponseMessage(tokenType: "pop"); // Act Trace.WriteLine("1. AcquireTokenForClient again, after time passes - expect POP key rotation"); result = await app.AcquireTokenForClient(TestConstants.s_scope.ToArray()) .WithAuthority(TestConstants.AuthorityUtidTenant) .WithProofOfPossession(popConfig) .ExecuteAsync() .ConfigureAwait(false); // Assert Assert.AreEqual(TokenSource.IdentityProvider, result.AuthenticationResultMetadata.TokenSource); string expectedKid2 = GetKidFromJwk(PoPProviderFactory.GetOrCreateProvider().CannonicalPublicKeyJwk); string actualCacheKey2 = cacheAccess.LastBeforeAccessNotificationArgs.SuggestedCacheKey; Assert.AreEqual( string.Format( CultureInfo.InvariantCulture, "{0}{1}_{2}_AppTokenCache", expectedKid2, TestConstants.ClientId, TestConstants.Utid), actualCacheKey2); Assert.AreNotEqual(actualCacheKey, actualCacheKey2); } }