Exemple #1
0
    def test_allowAllOrigins(self):
        options = cors_options.CorsOptions()
        f = filters.AllowOriginFilter(options)

        # Test with no Origin
        request = cors_handler.CorsRequest()
        response = cors_handler.CorsResponse()
        error = f.filter(request, response)
        self.assertIsNone(error)
        self.assertEquals('*', response.allow_origin)

        # Test CORS request
        request = cors_handler.CorsRequest(
            'GET', {constants.ORIGIN: 'http://foo.com'})
        response = cors_handler.CorsResponse()
        error = f.filter(request, response)
        self.assertIsNone(error)
        self.assertEquals('*', response.allow_origin)

        # Test CORS preflight request
        request = cors_handler.CorsRequest(
            'OPTIONS', {
                constants.ORIGIN: 'http://foo.com',
                constants.ACCESS_CONTROL_REQUEST_METHOD: 'GET'
            })
        response = cors_handler.CorsResponse()
        error = f.filter(request, response)
        self.assertIsNone(error)
        self.assertEquals('*', response.allow_origin)
Exemple #2
0
 def test_addHeader(self):
     options = cors_options.CorsOptions(expose_headers=["Foo"])
     response = cors_handler.CorsResponse()
     f = filters.ExposeHeadersFilter(options)
     f.filter(None, response)
     self.assertEquals(1, len(response.expose_headers))
     self.assertEquals('Foo', response.expose_headers[0])
Exemple #3
0
 def test_validOrigin(self):
     options = cors_options.CorsOptions(allow_origins=['http://foo.com'])
     f = filters.AllowOriginFilter(options)
     request = cors_handler.CorsRequest(
         'GET', {constants.ORIGIN: 'http://foo.com'})
     response = cors_handler.CorsResponse()
     error = f.filter(request, response)
     self.assertIsNone(error)
     self.assertEquals('http://foo.com', response.allow_origin)
Exemple #4
0
 def test_addHeader(self):
     options = cors_options.CorsOptions(allow_credentials=True)
     response = cors_handler.CorsResponse()
     f = filters.AllowCredentialsFilter(options)
     f.filter(None, response)
     self.assertTrue(response.allow_credentials)
Exemple #5
0
 def test_noHeader(self):
     options = cors_options.CorsOptions(vary=False)
     response = cors_handler.CorsResponse()
     filtr = filters.VaryFilter(options)
     filtr.filter(None, response)
     self.assertFalse(constants.VARY in response.headers)
Exemple #6
0
 def test_addHeader(self):
     options = cors_options.CorsOptions(vary=True)
     response = cors_handler.CorsResponse()
     filtr = filters.VaryFilter(options)
     filtr.filter(None, response)
     self.assertEquals(constants.ORIGIN, response.headers[constants.VARY])
Exemple #7
0
 def test_addHeader(self):
     options = cors_options.CorsOptions(max_age=1000)
     response = cors_handler.CorsResponse()
     f = filters.MaxAgeFilter(options)
     f.filter(None, response)
     self.assertEquals(1000, response.max_age)
Exemple #8
0
 def test_noHeader(self):
     options = cors_options.CorsOptions()
     response = cors_handler.CorsResponse()
     f = filters.MaxAgeFilter(options)
     f.filter(None, response)
     self.assertIsNone(response.max_age)
Exemple #9
0
 def test_noHeader(self):
     options = cors_options.CorsOptions()
     response = cors_handler.CorsResponse()
     f = filters.ExposeHeadersFilter(options)
     f.filter(None, response)
     self.assertEquals(0, len(response.expose_headers))