示例#1
0
        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);
        }
示例#2
0
        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();
        }
示例#3
0
        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");
        }
示例#4
0
        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);
        }
示例#5
0
 public static Response LoginAndRedirect(this INancyModule module, Guid userIdentifier, DateTime?cookieExpiry = null, string fallbackRedirectUrl = "/main")
 {
     return(FormsAuthentication.UserLoggedInRedirectResponse(module.Context, userIdentifier, cookieExpiry, fallbackRedirectUrl));
 }