public static UserInformationFieldIds DetermineUserInformationFieldIds(LabUser user)
        {
            UserInformationFieldIds userInformationFieldIds = new UserInformationFieldIds();

            userInformationFieldIds.DetermineFieldIds(user);
            return(userInformationFieldIds);
        }
Пример #2
0
        private static void EnterUsername(IWebDriver driver, LabUser user, bool withLoginHint, bool adfsOnly, UserInformationFieldIds fields)
        {
            if (adfsOnly && !withLoginHint)
            {
                Trace.WriteLine("Logging in ... Entering username");
                driver.FindElement(By.Id(CoreUiTestConstants.AdfsV4UsernameInputdId)).SendKeys(user.Upn);
            }
            else
            {
                if (!withLoginHint)
                {
                    Trace.WriteLine("Logging in ... Entering username");
                    driver.FindElementById(fields.AADUsernameInputId).SendKeys(user.Upn.Contains("EXT") ? user.HomeUPN : user.Upn);

                    Trace.WriteLine("Logging in ... Clicking <Next> after username");
                    driver.WaitForElementToBeVisibleAndEnabled(By.Id(fields.AADSignInButtonId)).Click();

                    try
                    {
                        driver.FindElementById(fields.AADSignInButtonId).Click();
                        Trace.WriteLine("Yes, workaround ok");
                    }
                    catch
                    {
                        Trace.WriteLine("No, workaround failed");
                    }
                }

                if (user.FederationProvider == FederationProvider.AdfsV2 && (user.UserType == UserType.Federated))
                {
                    Trace.WriteLine("Logging in ... AFDSv2 - Entering the username again, this time in the ADFSv2 form");
                    driver.FindElementById(CoreUiTestConstants.AdfsV2WebUsernameInputId).SendKeys(user.Upn);
                }
            }
        }
        public async Task AuthorityMigrationAsync()
        {
            LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync().ConfigureAwait(false);

            LabUser user = labResponse.User;

            IPublicClientApplication pca = PublicClientApplicationBuilder
                                           .Create(labResponse.App.AppId)
                                           .WithTestLogging()
                                           .Build();

            Trace.WriteLine("Acquire a token using a not so common authority alias");

            AuthenticationResult authResult = await pca.AcquireTokenByUsernamePassword(
                s_scopes,
                user.Upn,
                new NetworkCredential("", user.GetOrFetchPassword()).SecurePassword)
                                              // BugBug https://identitydivision.visualstudio.com/Engineering/_workitems/edit/776308/
                                              // sts.windows.net fails when doing instance discovery, e.g.:
                                              // https://sts.windows.net/common/discovery/instance?api-version=1.1&authorization_endpoint=https%3A%2F%2Fsts.windows.net%2Ff645ad92-e38d-4d1a-b510-d1b09a74a8ca%2Foauth2%2Fv2.0%2Fauthorize
                                              .WithAuthority("https://login.windows.net/" + labResponse.Lab.TenantId + "/")
                                              .ExecuteAsync()
                                              .ConfigureAwait(false);

            Assert.IsNotNull(authResult.AccessToken);

            Trace.WriteLine("Acquire a token silently using the common authority alias");

            authResult = await pca.AcquireTokenSilent(s_scopes, (await pca.GetAccountsAsync().ConfigureAwait(false)).First())
                         .WithAuthority(AadAuthorityAudience.AzureAdMultipleOrgs)
                         .ExecuteAsync()
                         .ConfigureAwait(false);

            Assert.IsNotNull(authResult.AccessToken);
        }
Пример #4
0
        public void PerformB2CSignInFlow(ITestController controller, LabUser user, B2CIdentityProvider b2CIdentityProvider, bool isB2CLoginAuthority)
        {
            SetB2CAuthority(controller, true);

            UserInformationFieldIds userInformationFieldIds = DetermineUserInformationFieldIds(user);

            controller.Tap(_acquirePageId);

            //Acquire token flow
            controller.Tap(CoreUiTestConstants.AcquireTokenButtonId);

            switch (b2CIdentityProvider)
            {
            case B2CIdentityProvider.Local:
                PerformB2CLocalAccountSignInFlow(controller, user, userInformationFieldIds);
                break;

            case B2CIdentityProvider.Google:
                PerformB2CGoogleProviderSignInFlow(controller, user, userInformationFieldIds);
                break;

            case B2CIdentityProvider.Facebook:
                PerformB2CFacebookProviderSignInFlow(controller, user, userInformationFieldIds);
                break;

            default:
                throw new InvalidOperationException("B2CIdentityProvider unknown");
            }
            VerifyResult(controller);
        }
Пример #5
0
        public void PerformB2CSignInFlow(
            ITestController controller,
            LabUser user,
            B2CIdentityProvider b2CIdentityProvider,
            string testToRun)
        {
            UserInformationFieldIds userInformationFieldIds = DetermineUserInformationFieldIds(user);

            controller.Tap(CoreUiTestConstants.TestsToRunPicker);
            controller.Tap(testToRun);

            switch (b2CIdentityProvider)
            {
            case B2CIdentityProvider.Local:
                PerformB2CLocalAccountSignInFlow(controller, user, userInformationFieldIds);
                break;

            case B2CIdentityProvider.Google:
                PerformB2CGoogleProviderSignInFlow(controller, user, userInformationFieldIds);
                break;

            case B2CIdentityProvider.Facebook:
                PerformB2CFacebookProviderSignInFlow(controller, user, userInformationFieldIds);
                break;

            default:
                throw new InvalidOperationException("B2CIdentityProvider unknown");
            }
        }
Пример #6
0
        public void PerformSignInFlow(
            ITestController controller,
            LabUser user,
            string testToRun)
        {
            UserInformationFieldIds userInformationFieldIds = DetermineUserInformationFieldIds(user);

            controller.Tap(CoreUiTestConstants.TestsToRunPicker);
            controller.Tap(testToRun);

            try
            {
                controller.WaitForWebElementByCssId(CoreUiTestConstants.WebUPNInputId);
                //i0116 = UPN text field on AAD sign in endpoint
                controller.EnterText(CoreUiTestConstants.WebUPNInputId, 20, user.Upn, XamarinSelector.ByHtmlIdAttribute);
                //idSIButton9 = Sign in button
                controller.Tap(CoreUiTestConstants.WebSubmitId, XamarinSelector.ByHtmlIdAttribute);
                //i0118 = password text field
                controller.WaitForWebElementByCssId(userInformationFieldIds.GetPasswordInputId());
                controller.EnterText(userInformationFieldIds.GetPasswordInputId(), user.GetOrFetchPassword(), XamarinSelector.ByHtmlIdAttribute);
                controller.Tap(userInformationFieldIds.GetPasswordSignInButtonId(), XamarinSelector.ByHtmlIdAttribute);
            }
            catch
            {
                Console.WriteLine("Failed to find UPN input. Attempting to click on UPN from select account screen");
                controller.Tap(user.Upn, XamarinSelector.ByHtmlValue);
            }
        }
        public async Task FailedAuthorityValidationTestAsync()
        {
            LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync().ConfigureAwait(false);

            LabUser user = labResponse.User;

            IPublicClientApplication pca = PublicClientApplicationBuilder
                                           .Create(labResponse.App.AppId)
                                           .WithAuthority("https://bogus.microsoft.com/common")
                                           .WithTestLogging()
                                           .Build();

            Trace.WriteLine("Acquire a token using a not so common authority alias");

            MsalServiceException exception = await AssertException.TaskThrowsAsync <MsalServiceException>(() =>
                                                                                                          pca.AcquireTokenByUsernamePassword(
                                                                                                              s_scopes,
                                                                                                              user.Upn,
                                                                                                              new NetworkCredential("", user.GetOrFetchPassword()).SecurePassword)
                                                                                                          .ExecuteAsync())
                                             .ConfigureAwait(false);

            Assert.IsTrue(exception.Message.Contains("AADSTS50049"));
            Assert.AreEqual("invalid_instance", exception.ErrorCode);
        }
Пример #8
0
        public async Task AuthorityMigrationAsync()
        {
            LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync().ConfigureAwait(false);

            LabUser user = labResponse.User;

            IPublicClientApplication pca = PublicClientApplicationBuilder
                                           .Create(labResponse.AppId)
                                           .Build();

            Trace.WriteLine("Acquire a token using a not so common authority alias");

            AuthenticationResult authResult = await pca.AcquireTokenByUsernamePassword(
                s_scopes,
                user.Upn,
                new NetworkCredential("", user.GetOrFetchPassword()).SecurePassword)
                                              .WithAuthority("https://sts.windows.net/" + user.CurrentTenantId + "/")
                                              .ExecuteAsync()
                                              .ConfigureAwait(false);

            Assert.IsNotNull(authResult.AccessToken);

            Trace.WriteLine("Acquire a token silently using the common authority alias");

            authResult = await pca.AcquireTokenSilent(s_scopes, (await pca.GetAccountsAsync().ConfigureAwait(false)).First())
                         .WithAuthority(AadAuthorityAudience.AzureAdMultipleOrgs)
                         .ExecuteAsync()
                         .ConfigureAwait(false);

            Assert.IsNotNull(authResult.AccessToken);
        }
        private void RunAutomatedDeviceCodeFlow(DeviceCodeResult deviceCodeResult, LabUser user, bool isAdfs = false)
        {
            try
            {
                var fields = new UserInformationFieldIds(user);

                Trace.WriteLine("Browser is open. Navigating to the Device Code url and entering the code");

                string codeId     = isAdfs ? "userCodeInput" : "code";
                string continueId = isAdfs ? "confirmationButton" : "continueBtn";

                _seleniumDriver.Navigate().GoToUrl(deviceCodeResult.VerificationUrl);
                _seleniumDriver
                // Device Code Flow web ui is undergoing A/B testing and is sometimes different - use 2 IDs
                .FindElement(SeleniumExtensions.ByIds("otc", codeId))
                .SendKeys(deviceCodeResult.UserCode);

                IWebElement continueBtn = _seleniumDriver.WaitForElementToBeVisibleAndEnabled(
                    SeleniumExtensions.ByIds(fields.AADSignInButtonId, continueId));
                continueBtn?.Click();

                _seleniumDriver.PerformLogin(user, Prompt.SelectAccount, isAdfs);

                Trace.WriteLine("Authentication complete");
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Browser automation failed " + ex);
                _seleniumDriver.SaveScreenshot(TestContext);
                throw;
            }
        }
        public async Task <IActionResult> Register([FromBody] LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new LabUser {
                    UserName = model.UserName
                };
                var result = await _signInManager.UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    //await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                    //    "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(Ok(result));
                }

                return(BadRequest(result));
            }

            // If we got this far, something failed, redisplay form
            return(BadRequest(ModelState));
        }
        public async Task AuthorityValidationTestWithFalseValidateAuthorityAsync()
        {
            LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync().ConfigureAwait(false);

            LabUser user = labResponse.User;

            IPublicClientApplication pca = PublicClientApplicationBuilder
                                           .Create(labResponse.App.AppId)
                                           .WithAuthority("https://bogus.microsoft.com/common", false)
                                           .WithTestLogging()
                                           .Build();

            Trace.WriteLine("Acquire a token using a not so common authority alias");

            HttpRequestException exception = await AssertException.TaskThrowsAsync <HttpRequestException>(() =>
                                                                                                          pca.AcquireTokenByUsernamePassword(
                                                                                                              s_scopes,
                                                                                                              user.Upn,
                                                                                                              new NetworkCredential("", user.GetOrFetchPassword()).SecurePassword)
                                                                                                          .ExecuteAsync())
                                             .ConfigureAwait(false);

#if NET_CORE
            Assert.IsTrue(((System.Net.Sockets.SocketException)exception.InnerException).SocketErrorCode == System.Net.Sockets.SocketError.HostNotFound);
#else
            Assert.IsTrue(((System.Net.WebException)exception.InnerException).Status == System.Net.WebExceptionStatus.NameResolutionFailure);
#endif
        }
Пример #12
0
        private static void HandleConsent(IWebDriver driver, LabUser user, UserInformationFieldIds fields, Prompt prompt)
        {
            // For MSA, a special consent screen seems to come up every now and then
            if (user.Upn.Contains("outlook.com"))
            {
                try
                {
                    Trace.WriteLine("Finding accept prompt");
                    var acceptBtn = driver.WaitForElementToBeVisibleAndEnabled(
                        ByIds(CoreUiTestConstants.ConsentAcceptId, fields.AADSignInButtonId),
                        waitTime: ShortExplicitTimespan,
                        ignoreFailures: true);
                    acceptBtn?.Click();
                }
                catch
                {
                    Trace.WriteLine("No accept prompt found accept prompt");
                }
            }

            if (prompt == Prompt.Consent)
            {
                Trace.WriteLine("Consenting...");
                driver.WaitForElementToBeVisibleAndEnabled(By.Id(fields.AADSignInButtonId)).Click();
            }
        }
Пример #13
0
        public static void PerformLogin(this IWebDriver driver, LabUser user, Prompt prompt, bool withLoginHint = false)
        {
            UserInformationFieldIds fields = new UserInformationFieldIds(user);

            if (!withLoginHint)
            {
                Trace.WriteLine("Logging in ... Entering username");
                driver.FindElement(By.Id(fields.AADUsernameInputId)).SendKeys(user.Upn);

                Trace.WriteLine("Logging in ... Clicking <Next> after username");
                driver.FindElement(By.Id(fields.AADSignInButtonId)).Click();
            }

            if (user.FederationProvider == FederationProvider.AdfsV2)
            {
                Trace.WriteLine("Logging in ... AFDSv2 - Entering the username again, this time in the ADFSv2 form");
                driver.FindElement(By.Id(CoreUiTestConstants.AdfsV2WebUsernameInputId)).SendKeys(user.Upn);
            }

            Trace.WriteLine("Logging in ... Entering password");
            driver.WaitForElementToBeVisibleAndEnabled(By.Id(fields.PasswordInputId)).SendKeys(user.GetOrFetchPassword());

            Trace.WriteLine("Logging in ... Clicking next after password");
            driver.WaitForElementToBeVisibleAndEnabled(By.Id(fields.PasswordSignInButtonId)).Click();

            if (prompt == Prompt.Consent)
            {
                Trace.WriteLine("Consenting...");
                driver.WaitForElementToBeVisibleAndEnabled(By.Id(fields.AADSignInButtonId)).Click();
            }
        }
Пример #14
0
        private async Task <IConfidentialClientApplication> RunOnBehalfOfTestAsync(LabUser user, bool silentCallShouldSucceed)
        {
            SecureString         securePassword = new NetworkCredential("", user.GetOrFetchPassword()).SecurePassword;
            AuthenticationResult authResult;

            var pca = PublicClientApplicationBuilder
                      .Create(PublicClientID)
                      .WithAuthority(AadAuthorityAudience.AzureAdMultipleOrgs)
                      .Build();

            s_inMemoryTokenCache.Bind(pca.UserTokenCache);

            try
            {
                authResult = await pca
                             .AcquireTokenSilent(s_oboServiceScope, user.Upn)
                             .ExecuteAsync()
                             .ConfigureAwait(false);
            }
            catch (MsalUiRequiredException)
            {
                Assert.IsFalse(silentCallShouldSucceed, "ATS should have found a token, but it didn't");
                authResult = await pca
                             .AcquireTokenByUsernamePassword(s_oboServiceScope, user.Upn, securePassword)
                             .ExecuteAsync(CancellationToken.None)
                             .ConfigureAwait(false);
            }

            MsalAssert.AssertAuthResult(authResult, user);
            Assert.IsTrue(authResult.Scopes.Any(s => string.Equals(s, s_oboServiceScope.Single(), StringComparison.OrdinalIgnoreCase)));

            var cca = ConfidentialClientApplicationBuilder
                      .Create(OboConfidentialClientID)
                      .WithAuthority(new Uri("https://login.microsoftonline.com/" + authResult.TenantId), true)
                      .WithClientSecret(_confidentialClientSecret)
                      .Build();

            s_inMemoryTokenCache.Bind(cca.UserTokenCache);

            try
            {
                authResult = await cca
                             .AcquireTokenSilent(s_scopes, user.Upn)
                             .ExecuteAsync()
                             .ConfigureAwait(false);
            }
            catch (MsalUiRequiredException)
            {
                Assert.IsFalse(silentCallShouldSucceed, "ATS should have found a token, but it didn't");

                authResult = await cca.AcquireTokenOnBehalfOf(s_scopes, new UserAssertion(authResult.AccessToken))
                             .ExecuteAsync(CancellationToken.None)
                             .ConfigureAwait(false);
            }

            MsalAssert.AssertAuthResult(authResult, user);
            Assert.IsTrue(authResult.Scopes.Any(s => string.Equals(s, s_scopes.Single(), StringComparison.OrdinalIgnoreCase)));

            return(cca);
        }
        private void RunAutomatedDeviceCodeFlow(DeviceCodeResult deviceCodeResult, LabUser user)
        {
            IWebDriver driver = _seleniumWrapper.Driver;
            try
            {
                Trace.WriteLine("Browser is open. Navigating to the Device Code url and entering the code");

                driver.Navigate().GoToUrl(deviceCodeResult.VerificationUrl);
                driver.FindElement(By.Id("code")).SendKeys(deviceCodeResult.UserCode);

                IWebElement continueBtn = _seleniumWrapper.WaitForElementToBeVisibleAndEnabled(By.Id("continueBtn"));
                continueBtn?.Click();

                PerformLogin(user);

                Trace.WriteLine("Authentication complete");

            }
            catch (Exception ex)
            {
                Trace.WriteLine("Browser automation failed " + ex);
                _seleniumWrapper.SaveScreenshot(TestContext);
                throw;
            }
        }
Пример #16
0
        private async Task RunOnBehalfOfTestAsync(LabResponse labResponse)
        {
            LabUser user = labResponse.User;
            string  oboHost;
            string  secret;
            string  authority;
            string  publicClientID;
            string  confidentialClientID;

            string[] oboScope;

            switch (labResponse.User.AzureEnvironment)
            {
            case AzureEnvironment.azureusgovernment:
                oboHost              = ArlingtonCloudHost;
                secret               = _keyVault.GetSecret(TestConstants.MsalArlingtonOBOKeyVaultUri).Value;
                authority            = labResponse.Lab.Authority + "organizations";
                publicClientID       = ArlingtonPublicClientIDOBO;
                confidentialClientID = ArlingtonConfidentialClientIDOBO;
                oboScope             = s_arlingtonOBOServiceScope;
                break;

            default:
                oboHost              = PublicCloudHost;
                secret               = _keyVault.GetSecret(TestConstants.MsalOBOKeyVaultUri).Value;
                authority            = TestConstants.AuthorityOrganizationsTenant;
                publicClientID       = PublicCloudPublicClientIDOBO;
                confidentialClientID = PublicCloudConfidentialClientIDOBO;
                oboScope             = s_publicCloudOBOServiceScope;
                break;
            }

            //TODO: acquire scenario specific client ids from the lab resonse

            SecureString securePassword = new NetworkCredential("", user.GetOrFetchPassword()).SecurePassword;

            var msalPublicClient = PublicClientApplicationBuilder.Create(publicClientID)
                                   .WithAuthority(authority)
                                   .WithRedirectUri(TestConstants.RedirectUri)
                                   .Build();

            var builder = msalPublicClient.AcquireTokenByUsernamePassword(oboScope, user.Upn, securePassword);

            builder.WithAuthority(authority);

            var authResult = await builder.ExecuteAsync().ConfigureAwait(false);

            var confidentialApp = ConfidentialClientApplicationBuilder
                                  .Create(confidentialClientID)
                                  .WithAuthority(new Uri(oboHost + authResult.TenantId), true)
                                  .WithClientSecret(secret)
                                  .Build();

            authResult = await confidentialApp.AcquireTokenOnBehalfOf(s_scopes, new UserAssertion(authResult.AccessToken))
                         .ExecuteAsync(CancellationToken.None)
                         .ConfigureAwait(false);

            MsalAssert.AssertAuthResult(authResult, user);
        }
Пример #17
0
 public static void AddUser(LabUser user)
 {
     using (var context = new DirectoryBrowserContext())
     {
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
 public static void AddUser(LabUser user)
 {
     using (var myChannelFactory = new ChannelFactory <IAlarmClockContract>("Server"))
     {
         IAlarmClockContract client = myChannelFactory.CreateChannel();
         client.AddUser(user);
     }
 }
        public void PerformB2CLocalAccountSignInFlow(ITestController controller, LabUser user, UserInformationFieldIds userInformationFieldIds)
        {
            controller.EnterText(CoreUiTestConstants.WebUpnB2CLocalInputId, 20, user.Upn, XamarinSelector.ByHtmlIdAttribute);

            controller.EnterText(userInformationFieldIds.PasswordInputId, user.GetOrFetchPassword(), XamarinSelector.ByHtmlIdAttribute);

            controller.Tap(userInformationFieldIds.PasswordSignInButtonId, XamarinSelector.ByHtmlIdAttribute);
        }
Пример #20
0
 private SeleniumWebUI CreateSeleniumCustomWebUI(LabUser user, Prompt prompt, bool withLoginHint = false, bool adfsOnly = false)
 {
     return(new SeleniumWebUI((driver) =>
     {
         Trace.WriteLine("Starting Selenium automation");
         driver.PerformLogin(user, prompt, withLoginHint, adfsOnly);
     }, TestContext));
 }
 private static SeleniumWebUI CreateSeleniumCustomWebUI(LabUser user, Prompt prompt, bool withLoginHint)
 {
     return(new SeleniumWebUI((driver) =>
     {
         Trace.WriteLine("Starting Selenium automation");
         driver.PerformLogin(user, prompt, withLoginHint);
     }));
 }
Пример #22
0
        public static void PerformLogin(this IWebDriver driver, LabUser user, Prompt prompt, bool withLoginHint = false, bool adfsOnly = false)
        {
            UserInformationFieldIds fields = new UserInformationFieldIds(user);

            EnterUsername(driver, user, withLoginHint, adfsOnly, fields);
            EnterPassword(driver, user, fields);

            HandleConsent(driver, user, fields, prompt);
        }
Пример #23
0
 public static IEnumerable <Query> GetQueriesForUser(LabUser user)
 {
     using (var context = new DirectoryBrowserContext())
     {
         var queryResult = from q in context.Queries
                           where q.User.UserId == user.UserId
                           select q;
         return(queryResult.AsEnumerable().ToList());
     }
 }
Пример #24
0
        private static void PerformLogin(
            IWebDriver driver,
            LabUser user)
        {
            UserInformationFieldIds fields = new UserInformationFieldIds();

            EnterUsername(driver, user, fields);
            EnterPassword(driver, user, fields);
            HandleStaySignedInPrompt(driver);
        }
Пример #25
0
        public void PerformB2CFacebookProviderSignInFlow(ITestController controller, LabUser user, UserInformationFieldIds userInformationFieldIds)
        {
            controller.Tap(CoreUiTestConstants.FacebookAccountID, XamarinSelector.ByHtmlIdAttribute);

            controller.EnterText(CoreUiTestConstants.WebUPNB2CFacebookInputID, 20, user.Upn, XamarinSelector.ByHtmlIdAttribute);

            controller.EnterText(userInformationFieldIds.PasswordInputId, LabUserHelper.GetUserPassword(user), XamarinSelector.ByHtmlIdAttribute);

            controller.Tap(userInformationFieldIds.SignInButtonId, XamarinSelector.ByHtmlIdAttribute);
        }
        public static void AssertAuthResult(AuthenticationResult result, LabUser user = null)
        {
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.AccessToken);

            if (user != null)
            {
                Assert.AreEqual(user.Upn, result.Account.Username);
            }
        }
        public static void PerformLogin(this IWebDriver driver, LabUser user, Prompt prompt, bool withLoginHint = false, bool adfsOnly = false)
        {
            UserInformationFieldIds fields = new UserInformationFieldIds(user);

            if (adfsOnly && !withLoginHint)
            {
                Trace.WriteLine("Logging in ... Entering username");
                driver.FindElement(By.Id(CoreUiTestConstants.AdfsV4UsernameInputdId)).SendKeys(user.Upn);
            }
            else
            {
                if (!withLoginHint)
                {
                    Trace.WriteLine("Logging in ... Entering username");
                    driver.FindElementById(fields.AADUsernameInputId).SendKeys(user.Upn.Contains("EXT") ? user.HomeUPN : user.Upn);

                    Trace.WriteLine("Logging in ... Clicking <Next> after username");
                    driver.FindElementById(fields.AADSignInButtonId).Click();

                    try
                    {
                        driver.FindElementById(fields.AADSignInButtonId).Click();
                        Trace.WriteLine("Yes, workaround ok");
                    }
                    catch
                    {
                        Trace.WriteLine("No, workaround failed");
                    }
                }

                if (user.FederationProvider == FederationProvider.AdfsV2 && user.IsFederated)
                {
                    Trace.WriteLine("Logging in ... AFDSv2 - Entering the username again, this time in the ADFSv2 form");
                    driver.FindElementById(CoreUiTestConstants.AdfsV2WebUsernameInputId).SendKeys(user.Upn);
                }
            }

            Trace.WriteLine("Logging in ... Entering password");
            driver.WaitForElementToBeVisibleAndEnabled(By.Id(fields.GetPasswordInputId())).SendKeys(user.GetOrFetchPassword());

            Trace.WriteLine("Logging in ... Clicking next after password");
            driver.WaitForElementToBeVisibleAndEnabled(By.Id(fields.GetPasswordSignInButtonId())).Click();

            if (user.HomeUPN.Contains("outlook.com"))
            {
                Trace.WriteLine("Logging in ... clicking accept prompts for outlook.com MSA user");
                driver.WaitForElementToBeVisibleAndEnabled(By.Id(CoreUiTestConstants.ConsentAcceptId)).Click();
            }

            if (prompt == Prompt.Consent)
            {
                Trace.WriteLine("Consenting...");
                driver.WaitForElementToBeVisibleAndEnabled(By.Id(fields.AADSignInButtonId)).Click();
            }
        }
Пример #28
0
        private static void EnterPassword(IWebDriver driver, LabUser user, UserInformationFieldIds fields)
        {
            Trace.WriteLine("Logging in ... Entering password");
            string password      = user.GetOrFetchPassword();
            string passwordField = fields.GetPasswordInputId();

            driver.WaitForElementToBeVisibleAndEnabled(By.Id(passwordField)).SendKeys(password);

            Trace.WriteLine("Logging in ... Clicking next after password");
            driver.WaitForElementToBeVisibleAndEnabled(By.Id(fields.GetPasswordSignInButtonId())).Click();
        }
Пример #29
0
 public static void DeserializeLastUser()
 {
     try
     {
         User = SerializationManager.Deserialize <LabUser>(FileFolderHelper.LastUserFilePath);
     }
     catch (Exception ex)
     {
         Logger.Log("Failed to Deserialize last user", ex);
     }
 }
Пример #30
0
        public void PerformB2CGoogleProviderSignInFlow(ITestController controller, LabUser user, UserInformationFieldIds userInformationFieldIds)
        {
            controller.Tap(CoreUiTestConstants.GoogleAccountId, XamarinSelector.ByHtmlIdAttribute);

            controller.EnterText(CoreUiTestConstants.WebUpnB2CGoogleInputId, 20, user.Upn, XamarinSelector.ByHtmlIdAttribute);

            controller.Tap(CoreUiTestConstants.B2CGoogleNextId, XamarinSelector.ByHtmlIdAttribute);

            controller.EnterText(userInformationFieldIds.GetPasswordInputId(true), user.GetOrFetchPassword(), XamarinSelector.ByHtmlIdAttribute);

            controller.Tap(userInformationFieldIds.GetPasswordSignInButtonId(true), XamarinSelector.ByHtmlIdAttribute);
        }