def test_cors_configurtaions(self):
    client = self._get_test_client()
    bucket = 'test-cors'
    object_key = 'index.html'
    url = '{}/{}/{}'.format(config.get_edge_url(), bucket, object_key)
    BUCKET_CORS_CONFIG = {'CORSRules': [{'AllowedOrigins': [config.get_edge_url()], 'AllowedMethods': ['GET', 'PUT'], 'MaxAgeSeconds': 3000, 'AllowedHeaders': ['x-amz-tagging']}]}
    client.create_bucket(Bucket=bucket)
    client.put_bucket_cors(Bucket=bucket, CORSConfiguration=BUCKET_CORS_CONFIG)
    client.put_object(Bucket=bucket, Key=object_key, Body='<h1>Index</html>')
    response = requests.get(url, headers={'Origin': config.get_edge_url(), 'Content-Type': 'text/html'})
    self.assertEqual(response.status_code, 200)
    self.assertIn('Access-Control-Allow-Origin'.lower(), response.headers)
    self.assertEqual(response.headers['Access-Control-Allow-Origin'], config.get_edge_url())
    self.assertIn('Access-Control-Allow-Methods'.lower(), response.headers)
    self.assertIn('GET', response.headers['Access-Control-Allow-Methods'])
    self.assertIn('Access-Control-Allow-Headers', response.headers)
    self.assertEqual(response.headers['Access-Control-Allow-Headers'], 'x-amz-tagging')
    self.assertIn('Access-Control-Max-Age'.lower(), response.headers)
    self.assertEqual(response.headers['Access-Control-Max-Age'], '3000')
    self.assertIn('Access-Control-Allow-Credentials'.lower(), response.headers)
    self.assertEqual(response.headers['Access-Control-Allow-Credentials'].lower(), 'true')
    BUCKET_CORS_CONFIG = {'CORSRules': [{'AllowedOrigins': ['https://anydomain.com'], 'AllowedMethods': ['GET', 'PUT'], 'MaxAgeSeconds': 3000, 'AllowedHeaders': ['x-amz-tagging']}]}
    client.put_bucket_cors(Bucket=bucket, CORSConfiguration=BUCKET_CORS_CONFIG)
    response = requests.get(url, headers={'Origin': config.get_edge_url(), 'Content-Type': 'text/html'})
    self.assertEqual(response.status_code, 200)
    self.assertNotIn('Access-Control-Allow-Origin'.lower(), response.headers)
    self.assertNotIn('Access-Control-Allow-Methods'.lower(), response.headers)
    self.assertNotIn('Access-Control-Allow-Headers', response.headers)
    self.assertNotIn('Access-Control-MaxAge', response.headers)
    client.delete_object(Bucket=bucket, Key=object_key)
    client.delete_bucket(Bucket=bucket)
def test_cors_configurtaions(self):
    client = self._get_test_client()
    bucket = 'test-cors'
    object_key = 'index.html'
    url = '{}/{}/{}'.format(config.get_edge_url(), bucket, object_key)
    BUCKET_CORS_CONFIG = {'CORSRules': [{'AllowedOrigins': [config.get_edge_url()], 'AllowedMethods': ['GET', 'PUT'], 'MaxAgeSeconds': 3000, 'AllowedHeaders': ['x-amz-tagging']}]}
    client.create_bucket(Bucket=bucket)
    client.put_bucket_cors(Bucket=bucket, CORSConfiguration=BUCKET_CORS_CONFIG)
    client.put_object(Bucket=bucket, Key=object_key, Body='<h1>Index</html>')
    response = requests.get(url, headers={'Origin': config.get_edge_url(), 'Content-Type': 'text/html'})
    self.assertEqual(response.status_code, 200)
    self.assertIn('Access-Control-Allow-Origin'.lower(), response.headers)
    self.assertEqual(response.headers['Access-Control-Allow-Origin'], config.get_edge_url())
    self.assertIn('Access-Control-Allow-Methods'.lower(), response.headers)
    self.assertIn('GET', response.headers['Access-Control-Allow-Methods'])
    self.assertIn('Access-Control-Allow-Headers', response.headers)
    self.assertEqual(response.headers['Access-Control-Allow-Headers'], 'x-amz-tagging')
    self.assertIn('Access-Control-Max-Age'.lower(), response.headers)
    self.assertEqual(response.headers['Access-Control-Max-Age'], '3000')
    self.assertIn('Access-Control-Allow-Credentials'.lower(), response.headers)
    self.assertEqual(response.headers['Access-Control-Allow-Credentials'].lower(), 'true')
    BUCKET_CORS_CONFIG = {'CORSRules': [{'AllowedOrigins': ['https://anydomain.com'], 'AllowedMethods': ['GET', 'PUT'], 'MaxAgeSeconds': 3000, 'AllowedHeaders': ['x-amz-tagging']}]}
    client.put_bucket_cors(Bucket=bucket, CORSConfiguration=BUCKET_CORS_CONFIG)
    response = requests.get(url, headers={'Origin': config.get_edge_url(), 'Content-Type': 'text/html'})
    self.assertEqual(response.status_code, 200)
    self.assertNotIn('Access-Control-Allow-Origin'.lower(), response.headers)
    self.assertNotIn('Access-Control-Allow-Methods'.lower(), response.headers)
    self.assertNotIn('Access-Control-Allow-Headers', response.headers)
    self.assertNotIn('Access-Control-MaxAge', response.headers)
    client.delete_object(Bucket=bucket, Key=object_key)
    client.delete_bucket(Bucket=bucket)