private async Task RunTestSyncOrAsync(TestMethod testMethod, TestMethodAsync testMethodAsync, StsType stsType) { this.AppendText(string.Format("{0}: ", (testMethod != NullTestMethod) ? testMethod.Method.Name : testMethodAsync.Method.Name)); try { Sts sts = StsFactory.CreateSts(stsType); AdalTests.InitializeTest(); AdalTests.EndBrowserDialogSession(); if (testMethod != NullTestMethod) { testMethod(sts); } if (testMethodAsync != NullTestMethodAsync) { await testMethodAsync(sts); } this.AppendText("PASSED.\n", Color.Green); } catch (AssertFailedException) { this.AppendText("FAILED!\n", Color.Red); } catch (Exception ex) { this.AppendText(string.Format("FAILED with exception '{0}'!\n", ex), Color.Red); } }
public void AcquireTokenWithPromptBehaviorNeverTestAsync() { // TODO: Not fully working at this point due to session cookies being deleted between WAB calls. Sts sts = Sts; // Should not be able to get a token silently passing redirectUri. var context = new AuthenticationContextProxy(sts.Authority, sts.ValidateAuthority); AuthenticationResultProxy result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, sts.ValidDefaultRedirectUri, PromptBehaviorProxy.Never); AdalTests.VerifyErrorResult(result, Sts.InvalidArgumentError, "SSO"); AuthenticationContextProxy.SetCredentials(sts.ValidUserName, sts.ValidPassword); result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, sts.ValidDefaultRedirectUri); AdalTests.VerifySuccessResult(sts, result); AuthenticationContextProxy.ClearDefaultCache(); result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, sts.ValidDefaultRedirectUri); AdalTests.VerifySuccessResult(sts, result); // Should not be able to get a token silently on first try. result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, null, PromptBehaviorProxy.Never); AdalTests.VerifyErrorResult(result, Sts.UserInteractionRequired, null); AuthenticationContextProxy.SetCredentials(sts.ValidUserName, sts.ValidPassword); // Obtain a token interactively. result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, null); AdalTests.VerifySuccessResult(sts, result); // Obtain a token interactively. AuthenticationContextProxy.ClearDefaultCache(); result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, null); AdalTests.VerifySuccessResult(sts, result); AuthenticationContextProxy.SetCredentials(null, null); // Now there should be a token available in the cache so token should be available silently. result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, null, PromptBehaviorProxy.Never); AdalTests.VerifySuccessResult(sts, result); // Clear the cache and silent auth should work via session cookies. AuthenticationContextProxy.ClearDefaultCache(); result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, null, PromptBehaviorProxy.Never); AdalTests.VerifySuccessResult(sts, result); // Clear the cache and cookies and silent auth should fail. AuthenticationContextProxy.ClearDefaultCache(); AdalTests.EndBrowserDialogSession(); result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, null, PromptBehaviorProxy.Never); AdalTests.VerifyErrorResult(result, Sts.UserInteractionRequired, null); }
public void TestMethodSetup() { AdalTests.InitializeTest(); StsType stsType = this.GetStsTypeFromContext(); try { AuthenticationContextProxy.CallSync = bool.Parse((string)TestContext.DataRow["CallSync"]); } catch (ArgumentException) { AuthenticationContextProxy.CallSync = false; } Sts = SetupStsService(stsType); RecorderSettings.SetMockModeByTestContext(TestContext); AdalTests.EndBrowserDialogSession(); }