Esempio n. 1
0
        public async Task ForgotPassword_Cancel()
        {
            string cancelUrl  = null;
            string confirmUrl = null;

            // Mock the email service to intercept the outgoing email messages
            var emailServiceMock = EmailServiceHelper.GetEmailServiceMock(
                IdentityBaseConstants.EmailTemplates.UserAccountRecover,
                "alice@localhost", (templateName, emailTo, viewData, isHtml) =>
            {
                // 2. Get confirm url and call it
                confirmUrl = viewData
                             .ToDictionary()["ConfirmUrl"].ToString();

                cancelUrl = viewData
                            .ToDictionary()["CancelUrl"].ToString();
            });

            TestServer server = TestServerBuilderExtensions
                                .CreateServer(emailServiceMock);

            HttpClient client = server.CreateClient();

            // Call cancel url
            await client.RecoveryCancelGetValidAsync(cancelUrl);

            // Calling cancel url again shouldnt be possible
            await client.RecoveryCancelGetInvalidAsync(cancelUrl);

            // Calling confirm url shouldnt be possible after successfull
            // cancelation
            await client.RecoveryConfirmGetInvalidAsync(confirmUrl);
        }
Esempio n. 2
0
        public async Task Try_Recover_Without_ReturnUrl()
        {
            TestServer          server   = TestServerBuilderExtensions.CreateServer();
            HttpClient          client   = server.CreateClient();
            HttpResponseMessage response = await client.GetAsync($"/recover");

            response.StatusCode.Should().Be(HttpStatusCode.Redirect);
            response.Headers.Location.ToString().Should().StartWith("/error");
        }
Esempio n. 3
0
 private TestServer CreateServer(
     Mock <IEmailService> emailServiceMock = null)
 {
     return(TestServerBuilderExtensions
            .CreateServer(emailServiceMock, (builder) =>
     {
         builder
         .Alter("App:EnableInvitationCreateEndpoint", "true");
     }, TestServerBuilderExtensions.CreateServer().CreateHandler()));
 }
Esempio n. 4
0
        public async Task Get_LandingPage()
        {
            TestServer server = TestServerBuilderExtensions.CreateServer();

            HttpClient          client   = server.CreateClient();
            HttpResponseMessage response = await client.GetAsync("/");

            string html = await response.Content.ReadAsStringAsync();

            response.EnsureSuccessStatusCode();
        }
Esempio n. 5
0
        public async Task ForgotPassword_Confirm_AddNewPassword_Login()
        {
            string confirmUrl = null;
            string cancelUrl  = null;

            // Mock the email service to intercept the outgoing email messages
            var emailServiceMock = EmailServiceHelper.GetEmailServiceMock(
                IdentityBaseConstants.EmailTemplates.UserAccountRecover,
                "alice@localhost", (templateName, emailTo, viewData, isHtml) =>
            {
                // 2. Get confirm url and call it
                confirmUrl = viewData
                             .ToDictionary()["ConfirmUrl"].ToString();

                cancelUrl = viewData
                            .ToDictionary()["CancelUrl"].ToString();
            });

            TestServer server = TestServerBuilderExtensions
                                .CreateServer(emailServiceMock);

            HttpClient client = server.CreateClient();

            // 1. Call the recovery page and Fill out the form and submit
            HttpResponseMessage response = await client
                                           .RecoveryGetAndPostFormAsync("alice@localhost");

            Assert.NotNull(confirmUrl);
            Assert.NotNull(cancelUrl);

            // Call the confirmation link and fill out the form
            HttpResponseMessage confirmResponse = await client
                                                  .RecoveryConfirmGetAndPostFormAsync(
                confirmUrl,
                "new-password"
                );

            HttpResponseMessage consentPostResponse = await
                                                      client.ConstentPostFormAsync(false, confirmResponse);

            // Calling confirm url again shouldnt be possible
            await client.RecoveryConfirmGetInvalidAsync(cancelUrl);

            // Calling cancel url shouldnt be possible after successfull
            // confirmation
            await client.RecoveryCancelGetInvalidAsync(cancelUrl);

            HttpResponseMessage loginResponse = await client
                                                .LoginGetAndPostFormAsync("alice@localhost", "new-password");

            loginResponse.ShouldBeRedirectedToAuthorizeEndpoint();
        }
Esempio n. 6
0
        public async Task Try_Recover(
            string email,
            string[] errorMsgs)
        {
            TestServer server = TestServerBuilderExtensions.CreateServer();
            HttpClient client = server.CreateClient();

            HttpResponseMessage response = await client
                                           .RecoveryGetAndPostFormAsync(email);

            IHtmlDocument doc = await response.Content
                                .ReadAsHtmlDocumentAsync();

            doc.ShouldContainErrors(errorMsgs);
        }