Exemplo n.º 1
0
    def test_post_content_types(self):
        response = _response()
        request = _request(method="POST", headers={"Content-Type": "application/json"})

        with self.assertRaises(preflight.AccessControlError) as context:
            preflight.check_headers(response, request)

        self.assertRegexpMatches(
            context.exception.message,
            "Headers .+ not allowed for resource '.*'")
Exemplo n.º 2
0
    def test_post_content_types(self):
        response = _response()
        request = _request(method="POST",
                           headers={"Content-Type": "application/json"})

        with self.assertRaises(preflight.AccessControlError) as context:
            preflight.check_headers(response, request)

        self.assertRegexpMatches(context.exception.message,
                                 "Headers .+ not allowed for resource '.*'")
Exemplo n.º 3
0
    def test_simple_headers(self):
        preflight.check_method(_response(), _request(headers={"Accept": "foo"}))
        preflight.check_method(_response(), _request(headers={"Content-Type": "application/json"}))

        with self.assertRaises(preflight.AccessControlError) as context:
            preflight.check_headers(
                _response(),
                _request(headers={"X-Auth-Token": "foo"}))

        self.assertRegexpMatches(
            context.exception.message,
            "Headers .* not allowed")
Exemplo n.º 4
0
    def test_simple_headers(self):
        preflight.check_method(_response(),
                               _request(headers={"Accept": "foo"}))
        preflight.check_method(
            _response(),
            _request(headers={"Content-Type": "application/json"}))

        with self.assertRaises(preflight.AccessControlError) as context:
            preflight.check_headers(_response(),
                                    _request(headers={"X-Auth-Token": "foo"}))

        self.assertRegexpMatches(context.exception.message,
                                 "Headers .* not allowed")
Exemplo n.º 5
0
    def test_post_simple_content_type(self):
        response = _response()
        request = _request(method="POST",
                           headers={"Content-Type": "text/plain"})

        self.assertIsNone(preflight.check_headers(response, request))
Exemplo n.º 6
0
    def test_allowed_headers(self):
        response = _response(
            headers={"Access-Control-Allow-Headers": "X-Auth-Token"})
        request = _request(headers={"X-Auth-Token": "foo"})

        self.assertIsNone(preflight.check_headers(response, request))
Exemplo n.º 7
0
    def test_allowed_headers(self):
        response = _response(headers={"Access-Control-Allow-Headers": "X-Auth-Token"})
        request = _request(headers={"X-Auth-Token": "foo"})

        self.assertIsNone(preflight.check_headers(response, request))
Exemplo n.º 8
0
    def test_post_simple_content_type(self):
        response = _response()
        request = _request(method="POST", headers={"Content-Type": "text/plain"})

        self.assertIsNone(preflight.check_headers(response, request))