Exemplo n.º 1
0
        public void Should_return_null_response_when_request_url_is_secure_method_is_post_and_requires_https()
        {
            // Given
            var module  = new FakeHookedModule(new BeforePipeline());
            var url     = GetFakeUrl(true);
            var context = new NancyContext
            {
                Request = new Request("POST", url)
            };

            module.RequiresHttps();

            // When
            var result = module.Before.Invoke(context);

            // Then
            result.ShouldBeNull();
        }
Exemplo n.º 2
0
        public void Should_return_forbidden_response_when_request_url_is_non_secure_method_is_post_and_requires_https_and_redirect_is_false()
        {
            // Given
            var module  = new FakeHookedModule(new BeforePipeline());
            var url     = GetFakeUrl(false);
            var context = new NancyContext
            {
                Request = new Request("POST", url)
            };

            module.RequiresHttps(false);

            // When
            var result = module.Before.Invoke(context);

            // Then
            result.ShouldNotBeNull();
            result.StatusCode.ShouldEqual(HttpStatusCode.Forbidden);
        }
Exemplo n.º 3
0
        public void Should_return_redirect_response_when_request_url_is_non_secure_method_is_get_and_requires_https()
        {
            // Given
            var module  = new FakeHookedModule(new BeforePipeline());
            var url     = GetFakeUrl(false);
            var context = new NancyContext
            {
                Request = new Request("GET", url)
            };

            module.RequiresHttps();

            // When
            var result = module.Before.Invoke(context);

            // Then
            result.ShouldNotBeNull();
            result.ShouldBeOfType <RedirectResponse>();

            url.Scheme = "https";
            result.Headers["Location"].ShouldEqual(url.ToString());
        }