def test_set_cors(self): # Arrange cors_rule1 = CorsRule(['www.xyz.com'], ['GET']) allowed_origins = ['www.xyz.com', "www.ab.com", "www.bc.com"] allowed_methods = ['GET', 'PUT'] max_age_in_seconds = 500 exposed_headers = [ "x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd" ] allowed_headers = [ "x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo" ] cors_rule2 = CorsRule(allowed_origins, allowed_methods, max_age_in_seconds, exposed_headers, allowed_headers) cors = [cors_rule1, cors_rule2] # Act self.bs.set_blob_service_properties(cors=cors) # Assert received_props = self.bs.get_blob_service_properties() self._assert_cors_equal(received_props.cors, cors)
def test_set_static_website_properties_does_not_impact_other_properties(self): # Arrange to set cors cors_rule1 = CorsRule(['www.xyz.com'], ['GET']) allowed_origins = ['www.xyz.com', "www.ab.com", "www.bc.com"] allowed_methods = ['GET', 'PUT'] max_age_in_seconds = 500 exposed_headers = ["x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd"] allowed_headers = ["x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo"] cors_rule2 = CorsRule(allowed_origins, allowed_methods, max_age_in_seconds, exposed_headers, allowed_headers) cors = [cors_rule1, cors_rule2] # Act to set cors self.bs.set_blob_service_properties(cors=cors) # Assert cors is updated received_props = self.bs.get_blob_service_properties() self._assert_cors_equal(received_props.cors, cors) # Arrange to set static website properties static_website = StaticWebsite(enabled=True, index_document="index.html", error_document_404_path="errors/error/404error.html") # Act to set static website self.bs.set_blob_service_properties(static_website=static_website) # Assert static website was updated was cors was unchanged received_props = self.bs.get_blob_service_properties() self._assert_static_website_equal(received_props.static_website, static_website) self._assert_cors_equal(received_props.cors, cors)
def test_too_many_cors_rules(self): # Arrange cors = [] for i in range(0, 6): cors.append(CorsRule(['www.xyz.com'], ['GET'])) # Assert self.assertRaises(AzureHttpError, self.bs.set_blob_service_properties, None, None, None, cors)
def service_properties(self): # Basic self.service.set_file_service_properties(hour_metrics=Metrics(enabled=True, include_apis=True), minute_metrics=Metrics(enabled=True, include_apis=False), cors=[CorsRule(allowed_origins=['*'], allowed_methods=['GET'])]) # Wait 30 seconds for settings to propagate time.sleep(30) props = self.service.get_file_service_properties() # props = ServiceProperties() w/ all properties specified above # Omitted properties will not overwrite what's already on the self.service # Empty properties will clear self.service.set_file_service_properties(cors=[]) # Wait 30 seconds for settings to propagate time.sleep(30) props = self.service.get_file_service_properties() # props = ServiceProperties() w/ CORS rules cleared
def set_cors_rules(self, file_service): print('1. Get Cors Rules') original_cors_rules = file_service.get_file_service_properties().cors print('2. Overwrite Cors Rules') cors_rule = CorsRule(allowed_origins=['*'], allowed_methods=['POST', 'GET'], allowed_headers=['*'], exposed_headers=['*'], max_age_in_seconds=3600) try: file_service.set_file_service_properties(cors=[cors_rule]) finally: #reverting cors rules back to the original ones print('3. Revert Cors Rules back the original ones') file_service.set_file_service_properties(cors=original_cors_rules) print("CORS sample completed")