public async Task ReturnCustomErrorMessageDuringFormPost() { // Arrange var fixture = new OwinTestFixture { Options = new StormpathOwinOptions { PreRegistrationHandler = (ctx, ct) => { ctx.Result = new PreRegistrationResult() { Success = false, ErrorMessage = "Nice try, rebel scum!" }; return(Task.FromResult(0)); } } }; var server = Helpers.CreateServer(fixture); var csrfToken = await CsrfToken.GetTokenForRoute(server, "/register"); // Act var payload = new Dictionary <string, string>() { ["email"] = $"its-{fixture.TestKey}@testmail.stormpath.com", ["password"] = "******", ["givenName"] = "Jyn", ["surname"] = "Erso", ["st"] = csrfToken, }; var request = new HttpRequestMessage(HttpMethod.Post, "/register") { Content = new FormUrlEncodedContent(payload) }; request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html")); var response = await server.SendAsync(request); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); (await response.Content.ReadAsStringAsync()).Should().Contain("Nice try, rebel scum!"); }
public async Task RedirectToLogin() { // Arrange var fixture = new OwinTestFixture(); // all default settings var server = Helpers.CreateServer(fixture); using (var cleanup = new AutoCleanup(fixture.Client)) { var application = await fixture.Client.GetApplicationAsync(fixture.ApplicationHref); var csrfToken = await CsrfToken.GetTokenForRoute(server, "/register"); var email = $"its-{fixture.TestKey}@testmail.stormpath.com"; var payload = new Dictionary <string, string>() { ["email"] = email, ["password"] = "******", ["givenName"] = nameof(RedirectToLogin), ["surname"] = nameof(RegisterRouteShould), ["st"] = csrfToken, }; var request = new HttpRequestMessage(HttpMethod.Post, "/register") { Content = new FormUrlEncodedContent(payload) }; request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html")); // Act var response = await server.SendAsync(request); var foundAccount = await application.GetAccounts().Where(a => a.Email == email).SingleOrDefaultAsync(); if (foundAccount != null) { cleanup.MarkForDeletion(foundAccount); } // Assert response.StatusCode.Should().Be(HttpStatusCode.Redirect); response.Headers.Location.ToString().Should().StartWith("/login?status=created"); } }
public async Task RejectUnknownCustomFieldOnFormPost() { // Arrange var fixture = new OwinTestFixture(); var server = Helpers.CreateServer(fixture); var csrfToken = await CsrfToken.GetTokenForRoute(server, "/register"); using (var cleanup = new AutoCleanup(fixture.Client)) { var application = await fixture.Client.GetApplicationAsync(fixture.ApplicationHref); // Act var email = $"its-{fixture.TestKey}@testmail.stormpath.com"; // Act var payload = new Dictionary <string, string>() { ["email"] = email, ["password"] = "******", ["givenName"] = "Galen", ["surname"] = "Erso", ["codename"] = "stardust", ["st"] = csrfToken, }; var request = new HttpRequestMessage(HttpMethod.Post, "/register") { Content = new FormUrlEncodedContent(payload) }; request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html")); await server.SendAsync(request); var account = await application.GetAccounts().Where(a => a.Email == email).SingleOrDefaultAsync(); if (account != null) { cleanup.MarkForDeletion(account); } // Assert account.Should().BeNull(); } }
public async Task ReturnDefaultErrorMessageDuringFormPost() { // Arrange var fixture = new OwinTestFixture { Options = new StormpathOwinOptions { PreLoginHandler = (ctx, ct) => { ctx.Result = new PreLoginResult() { Success = false }; return(Task.FromResult(0)); } } }; var server = Helpers.CreateServer(fixture); var csrfToken = await CsrfToken.GetTokenForRoute(server, "/login"); // Act var payload = new Dictionary <string, string>() { ["login"] = "******", ["password"] = "******", ["st"] = csrfToken, }; var request = new HttpRequestMessage(HttpMethod.Post, "/login") { Content = new FormUrlEncodedContent(payload) }; request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html")); var response = await server.SendAsync(request); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); (await response.Content.ReadAsStringAsync()).Should().Contain("An error has occurred. Please try again."); }
public async Task AccessPostDataDuringFormPost() { var handlerRun = false; // Arrange var fixture = new OwinTestFixture { Options = new StormpathOwinOptions { PreRegistrationHandler = (ctx, ct) => { handlerRun = true; ctx.PostData["email"].Should().Be("*****@*****.**"); ctx.PostData["custom"].Should().Be("foobar!"); // Don't actually create an account ctx.Result = new PreRegistrationResult { Success = false }; return(Task.FromResult(0)); }, Configuration = new StormpathConfiguration() { Web = new WebConfiguration() { Register = new WebRegisterRouteConfiguration() { Form = new WebRegisterRouteFormConfiguration() { Fields = new Dictionary <string, WebFieldConfiguration>() { ["custom"] = new WebFieldConfiguration() { Required = true, Enabled = true, Label = "custom", Placeholder = "custom", Type = "text", Visible = true } } } } } } }, }; var server = Helpers.CreateServer(fixture); var csrfToken = await CsrfToken.GetTokenForRoute(server, "/register"); // Act var payload = new Dictionary <string, string>() { ["email"] = "*****@*****.**", ["password"] = "******", ["givenName"] = "Chewbacca", ["surname"] = "Wookie", ["custom"] = "foobar!", ["st"] = csrfToken, }; var request = new HttpRequestMessage(HttpMethod.Post, "/register") { Content = new FormUrlEncodedContent(payload) }; request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html")); await server.SendAsync(request); handlerRun.Should().BeTrue(); }
public async Task RedirectToNextUriIfAutologinIsEnabled() { // Arrange var config = new StormpathConfiguration() { Web = new WebConfiguration() { Register = new WebRegisterRouteConfiguration() { AutoLogin = true, // default NextUri } } }; var fixture = new OwinTestFixture() { Options = new StormpathOwinOptions() { Configuration = config } }; var server = Helpers.CreateServer(fixture); using (var cleanup = new AutoCleanup(fixture.Client)) { var application = await fixture.Client.GetApplicationAsync(fixture.ApplicationHref); var csrfToken = await CsrfToken.GetTokenForRoute(server, "/register"); var email = $"its-{fixture.TestKey}@testmail.stormpath.com"; var payload = new Dictionary <string, string>() { ["email"] = email, ["password"] = "******", ["givenName"] = nameof(RedirectToLogin), ["surname"] = nameof(RegisterRouteShould), ["st"] = csrfToken, }; var request = new HttpRequestMessage(HttpMethod.Post, "/register") { Content = new FormUrlEncodedContent(payload) }; request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html")); // Act var response = await server.SendAsync(request); var foundAccount = await application.GetAccounts().Where(a => a.Email == email).SingleOrDefaultAsync(); if (foundAccount != null) { cleanup.MarkForDeletion(foundAccount); } // Assert response.StatusCode.Should().Be(HttpStatusCode.Redirect); response.Headers.Location.ToString().Should().StartWith("/"); // default NextUri response.Headers.GetValues("Set-Cookie").Should().Contain(x => x.StartsWith("access_token=")); response.Headers.GetValues("Set-Cookie").Should().Contain(x => x.StartsWith("refresh_token=")); } }
public async Task AcceptCustomFieldsOnFormPost() { // Arrange var fixture = new OwinTestFixture { Options = new StormpathOwinOptions { Configuration = new StormpathConfiguration() { Web = new WebConfiguration() { Register = new WebRegisterRouteConfiguration() { Form = new WebRegisterRouteFormConfiguration() { Fields = new Dictionary <string, WebFieldConfiguration>() { ["codename"] = new WebFieldConfiguration() { Required = true, Enabled = true, Label = "custom", Placeholder = "custom", Type = "text", Visible = true } } } } } } }, }; var server = Helpers.CreateServer(fixture); var csrfToken = await CsrfToken.GetTokenForRoute(server, "/register"); using (var cleanup = new AutoCleanup(fixture.Client)) { var application = await fixture.Client.GetApplicationAsync(fixture.ApplicationHref); // Act var email = $"its-{fixture.TestKey}@testmail.stormpath.com"; // Act var payload = new Dictionary <string, string>() { ["email"] = email, ["password"] = "******", ["givenName"] = "Galen", ["surname"] = "Erso", ["codename"] = "stardust", ["st"] = csrfToken, }; var request = new HttpRequestMessage(HttpMethod.Post, "/register") { Content = new FormUrlEncodedContent(payload) }; request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html")); await server.SendAsync(request); var account = await application.GetAccounts().Where(a => a.Email == email).SingleAsync(); cleanup.MarkForDeletion(account); var customData = await account.GetCustomDataAsync(); // Assert customData["codename"].ToString().Should().Be("stardust"); } }