Ejemplo n.º 1
0
    def test_set_cors(self, resource_group, location, storage_account,
                      storage_account_key):
        # Arrange
        qsc = QueueServiceClient(self.account_url(storage_account, "queue"),
                                 storage_account_key)
        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=max_age_in_seconds,
                              exposed_headers=exposed_headers,
                              allowed_headers=allowed_headers)

        cors = [cors_rule1, cors_rule2]

        # Act
        qsc.set_service_properties(cors=cors)

        # Assert
        received_props = qsc.get_service_properties()
        self._assert_cors_equal(received_props['cors'], cors)
Ejemplo n.º 2
0
    async def test_queue_service_properties(self, resource_group, location,
                                            storage_account,
                                            storage_account_key):
        # Instantiate the QueueServiceClient from a connection string
        from azure.storage.queue.aio import QueueServiceClient
        queue_service = QueueServiceClient.from_connection_string(
            self.connection_string(storage_account, storage_account_key))

        # [START async_set_queue_service_properties]
        # Create service properties
        from azure.storage.queue import QueueAnalyticsLogging, Metrics, CorsRule, RetentionPolicy

        # Create logging settings
        logging = QueueAnalyticsLogging(read=True,
                                        write=True,
                                        delete=True,
                                        retention_policy=RetentionPolicy(
                                            enabled=True, days=5))

        # Create metrics for requests statistics
        hour_metrics = Metrics(enabled=True,
                               include_apis=True,
                               retention_policy=RetentionPolicy(enabled=True,
                                                                days=5))
        minute_metrics = Metrics(enabled=True,
                                 include_apis=True,
                                 retention_policy=RetentionPolicy(enabled=True,
                                                                  days=5))

        # Create CORS rules
        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=max_age_in_seconds,
                              exposed_headers=exposed_headers,
                              allowed_headers=allowed_headers)

        cors = [cors_rule1, cors_rule2]

        # Set the service properties
        await queue_service.set_service_properties(logging, hour_metrics,
                                                   minute_metrics, cors)
        # [END async_set_queue_service_properties]

        # [START async_get_queue_service_properties]
        properties = await queue_service.get_service_properties()
    def set_cors_rules(self, queue_service):

        cors_rule = CorsRule(allowed_origins=['*'],
                             allowed_methods=['POST', 'GET'],
                             allowed_headers=['*'],
                             exposed_headers=['*'],
                             max_age_in_seconds=3600)

        try:
            print('1. Get Cors Rules')
            original_cors_rules = queue_service.get_service_properties(
            )['cors']

            print('2. Overwrite Cors Rules')
            queue_service.set_service_properties(cors=[cors_rule])

        except Exception as e:
            print(e)

        finally:
            print('3. Revert Cors Rules back the original ones')
            #reverting cors rules back to the original ones
            queue_service.set_service_properties(cors=original_cors_rules)

        print("CORS sample completed")
Ejemplo n.º 4
0
    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(HttpResponseError,
                          self.qsc.set_service_properties, None, None, None, cors)
Ejemplo n.º 5
0
    def test_too_many_cors_rules(self, storage_account_name, storage_account_key):
        # Arrange
        qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key)
        cors = []
        for i in range(0, 6):
            cors.append(CorsRule(['www.xyz.com'], ['GET']))

        # Assert
        self.assertRaises(HttpResponseError,
                          qsc.set_service_properties, None, None, None, cors)
Ejemplo n.º 6
0
    async def test_too_many_cors_rules(self, storage_account_name, storage_account_key):
        # Arrange
        qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key, transport=AiohttpTestTransport())
        cors = []
        for _ in range(0, 6):
            cors.append(CorsRule(['www.xyz.com'], ['GET']))

        # Assert
        with self.assertRaises(HttpResponseError):
            await qsc.set_service_properties()
Ejemplo n.º 7
0
    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=max_age_in_seconds,
            exposed_headers=exposed_headers,
            allowed_headers=allowed_headers)

        cors = [cors_rule1, cors_rule2]

        # Act
        self.qsc.set_service_properties(cors=cors)

        # Assert
        received_props = self.qsc.get_service_properties()
        self._assert_cors_equal(received_props.cors, cors)