예제 #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);
        }
예제 #2
0
        public async Task ChangeEmail_FoceUpdate()
        {
            string confirmUrl = null;
            string cancelUrl  = null;

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

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

            TestServer server = this.CreateServer(emailServiceMock);
            HttpClient client = await server.CreateAuthenticatedClient();

            string uri = $"/useraccounts/{aliceId}/change_email";
            HttpResponseMessage response = await client.PostJsonAsync(uri, new
            {
                Email    = "nerd@localhost",
                ClientId = "mvc.hybrid",
                Force    = true
            });

            response.EnsureSuccessStatusCode();
            var json = response.Content.ReadAsStringAsync().Result;
        }
예제 #3
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();
        }
예제 #4
0
        public async Task Invite_Confirm_AddPassword_Login()
        {
            string confirmUrl = null;
            string cancelUrl  = null;

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

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

            TestServer server = this.CreateServer(emailServiceMock);
            HttpClient client = await server.CreateAuthenticatedClient();

            HttpResponseMessage response = await client
                                           .PutJsonAsync("/invitations", new
            {
                Email    = "invited@localhost",
                ClientId = "mvc.hybrid"
            });

            response.EnsureSuccessStatusCode();
            response.AssertSchema(Schemas.InvitationsPostResponse);

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

            // Call the confirmation link and fill out the form
            HttpResponseMessage confirmResponse = await client
                                                  .RegisterConfirmGetAndPostFormAsync(
                confirmUrl,
                "supersecret"
                );

            // confirmResponse.ShouldBeRedirectedToAuthorizeEndpoint();
        }
예제 #5
0
        public async Task ChangeEmail_Confirm_Login()
        {
            string confirmUrl = null;
            string cancelUrl  = null;

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

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

            TestServer server = this.CreateServer(emailServiceMock);
            HttpClient client = await server.CreateAuthenticatedClient();

            string uri = $"/useraccounts/{aliceId}/change_email";
            HttpResponseMessage response = await client.PostJsonAsync(uri, new
            {
                Email    = "nerd@localhost",
                ClientId = "mvc.hybrid",
                Force    = false
            });

            response.EnsureSuccessStatusCode();
            // response.AssertSchema(Schemas.InvitationsPostResponse);

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

            // Post password

            // Try authenticate
        }