public void Should_set_Domain_when_config_provides_domain_value() { //Given FormsAuthentication.Enable(A.Fake <IPipelines>(), this.domainPathConfig); //When var result = FormsAuthentication.UserLoggedInRedirectResponse(context, userGuid); //Then var cookie = result.Cookies.Where(c => c.Name == FormsAuthentication.FormsAuthenticationCookieName).First(); cookie.Domain.ShouldEqual(domain); }
public void Should_set_authentication_cookie_to_secure_when_config_requires_ssl_and_logging_in_with_redirect() { //Given FormsAuthentication.Enable(A.Fake <IPipelines>(), this.secureConfig); //When var result = FormsAuthentication.UserLoggedInRedirectResponse(context, userGuid); //Then result.Cookies .Where(c => c.Name == FormsAuthentication.FormsAuthenticationCookieName) .First() .Secure.ShouldBeTrue(); }
public void Should_retain_querystring_when_redirecting_after_successfull_login() { // Given var queryContext = new NancyContext() { Request = new FakeRequest("GET", "/secure", "returnUrl=/secure%3Ffoo%3Dbar") }; FormsAuthentication.Enable(A.Fake <IPipelines>(), this.config); // When var result = FormsAuthentication.UserLoggedInRedirectResponse(queryContext, userGuid, DateTime.Now.AddDays(1)); // Then result.Headers["Location"].ShouldEqual("/secure?foo=bar"); }
public void Should_generate_hmac_for_cookie_from_encrypted_cookie_when_logging_in_with_redirect() { var fakeEncrypter = A.Fake <IEncryptionProvider>(); var fakeCryptoText = "FakeText"; A.CallTo(() => fakeEncrypter.Encrypt(A <string> .Ignored)) .Returns(fakeCryptoText); var mockHmac = A.Fake <IHmacProvider>(); this.config.CryptographyConfiguration = new CryptographyConfiguration(fakeEncrypter, mockHmac); FormsAuthentication.Enable(A.Fake <IPipelines>(), this.config); FormsAuthentication.UserLoggedInRedirectResponse(context, userGuid, DateTime.Now.AddDays(1)); A.CallTo(() => mockHmac.GenerateHmac(fakeCryptoText)) .MustHaveHappened(Repeated.Exactly.Once); }
public static Response LoginAndRedirect(this INancyModule module, Guid userIdentifier, DateTime?cookieExpiry = null, string fallbackRedirectUrl = "/main") { return(FormsAuthentication.UserLoggedInRedirectResponse(module.Context, userIdentifier, cookieExpiry, fallbackRedirectUrl)); }