Ejemplo n.º 1
0
        public void Should_return_forbidden_response_when_request_url_is_non_secure_method_is_delete_and_requires_https()
        {
            // Given
            var module = new FakeHookedModule(new BeforePipeline());
            var url = GetFakeUrl(false);
            var context = new NancyContext
                              {
                                  Request = new Request("DELETE", url)
                              };

            module.RequiresHttps();

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

            // Then
            result.ShouldNotBeNull();
            result.StatusCode.ShouldEqual(HttpStatusCode.Forbidden);
        }
Ejemplo n.º 2
0
        public void Should_return_redirect_response_with_specific_port_number_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(true, 999);

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

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

            url.Scheme = "https";
            url.Port = 999;
            result.Headers["Location"].ShouldEqual(url.ToString());
        }
Ejemplo n.º 3
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();
        }