Ejemplo n.º 1
0
    def test_sas_signature_is_scrubbed_off(self):
        # SAS URL is calculated from storage key, so this test runs live only
        if TestMode.need_recording_file(self.test_mode):
            return

        # Arrange
        token = self.bs.generate_container_shared_access_signature(
            self.container_name,
            permission=ContainerPermissions.READ,
            expiry=datetime.utcnow() + timedelta(hours=1),
        )
        # parse out the signed signature
        token_components = parse_qs(token)
        signed_signature = token_components[
            _QueryStringConstants.SIGNED_SIGNATURE][0]

        bs_with_sas = BlockBlobService(
            account_name=self.settings.STORAGE_ACCOUNT_NAME,
            sas_token=token,
            protocol=self.settings.PROTOCOL)

        # Act
        with LogCaptured(self) as log_captured:
            bs_with_sas.get_blob_account_information(self.container_name)
            log_as_str = log_captured.getvalue()

            # Assert
            # make sure the query parameter 'sig' is logged, but its value is not
            self.assertTrue(
                _QueryStringConstants.SIGNED_SIGNATURE in log_as_str)
            self.assertFalse(signed_signature in log_as_str)
Ejemplo n.º 2
0
    def test_copy_source_sas_is_scrubbed_off(self):
        # SAS URL is calculated from storage key, so this test runs live only
        if TestMode.need_recording_file(self.test_mode):
            return

        # Arrange
        dest_blob_name = self.get_resource_name('destblob')

        # parse out the signed signature
        token_components = parse_qs(self.source_blob_url)
        signed_signature = token_components[
            _QueryStringConstants.SIGNED_SIGNATURE][0]

        # Act
        with LogCaptured(self) as log_captured:
            self.bs.copy_blob(self.container_name,
                              dest_blob_name,
                              self.source_blob_url,
                              requires_sync=True)
            log_as_str = log_captured.getvalue()

            # Assert
            # make sure the query parameter 'sig' is logged, but its value is not
            self.assertTrue(
                _QueryStringConstants.SIGNED_SIGNATURE in log_as_str)
            self.assertFalse(signed_signature in log_as_str)

            # make sure authorization header is logged, but its value is not
            # the keyword SharedKey is present in the authorization header's value
            self.assertTrue(_AUTHORIZATION_HEADER_NAME in log_as_str)
            self.assertFalse('SharedKey' in log_as_str)
    def test_delete_directory_with_non_existing_directory_fail_not_exist(self):
        # Arrange

        # Act
        with LogCaptured(self) as log_captured:
            with self.assertRaises(AzureMissingResourceHttpError):
                self.fs.delete_directory(self.share_name, 'dir1', True)

            log_as_str = log_captured.getvalue()
            self.assertTrue('ERROR' in log_as_str)
Ejemplo n.º 4
0
    def test_delete_non_existing_queue_fail_not_exist(self):
        # Action
        queue_name = self._get_queue_reference()

        with LogCaptured(self) as log_captured:
            with self.assertRaises(AzureMissingResourceHttpError):
                self.qs.delete_queue(queue_name, True)

            log_as_str = log_captured.getvalue()
            self.assertTrue('ERROR' in log_as_str)
Ejemplo n.º 5
0
    def test_delete_share_with_non_existing_share_fail_not_exist(self):
        # Arrange
        share_name = self._get_share_reference()

        # Act
        with LogCaptured(self) as log_captured:
            with self.assertRaises(AzureMissingResourceHttpError):
                self.fs.delete_share(share_name, True)

            log_as_str = log_captured.getvalue()
            self.assertTrue('ERROR' in log_as_str)
Ejemplo n.º 6
0
    def test_authorization_is_scrubbed_off(self):
        # Act
        with LogCaptured(self) as log_captured:
            self.bs.exists(self.container_name)
            log_as_str = log_captured.getvalue()

            # Assert
            # make sure authorization header is logged, but its value is not
            # the keyword SharedKey is present in the authorization header's value
            self.assertTrue(_AUTHORIZATION_HEADER_NAME in log_as_str)
            self.assertFalse('SharedKey' in log_as_str)
    def test_delete_directory_with_non_existing_directory(self):
        # Arrange

        # Act
        with LogCaptured(self) as log_captured:
            deleted = self.fs.delete_directory(self.share_name, 'dir1', False)

            log_as_str = log_captured.getvalue()
            self.assertTrue('ERROR' not in log_as_str)

        # Assert
        self.assertFalse(deleted)
    def test_directory_not_exists(self):
        # Arrange

        # Act
        with LogCaptured(self) as log_captured:
            exists = self.fs.exists(self.share_name, 'missing')

            log_as_str = log_captured.getvalue()
            self.assertTrue('ERROR' not in log_as_str)

        # Assert
        self.assertFalse(exists)
Ejemplo n.º 9
0
    def test_queue_not_exists(self):
        # Arrange

        # Act
        with LogCaptured(self) as log_captured:
            exists = self.qs.exists(self.get_resource_name('missing'))

            log_as_str = log_captured.getvalue()
            self.assertTrue('ERROR' not in log_as_str)

        # Assert
        self.assertFalse(exists)
Ejemplo n.º 10
0
    def test_delete_non_existing_queue(self):
        # Action
        queue_name = self._get_queue_reference()

        with LogCaptured(self) as log_captured:
            deleted = self.qs.delete_queue(queue_name)

            log_as_str = log_captured.getvalue()
            self.assertTrue('ERROR' not in log_as_str)

        # Asserts
        self.assertFalse(deleted)
Ejemplo n.º 11
0
    def test_delete_share_with_non_existing_share(self):
        # Arrange
        share_name = self._get_share_reference()

        # Act
        with LogCaptured(self) as log_captured:
            deleted = self.fs.delete_share(share_name)

            log_as_str = log_captured.getvalue()
            self.assertTrue('ERROR' not in log_as_str)

        # Assert
        self.assertFalse(deleted)
Ejemplo n.º 12
0
    def test_share_not_exists(self):
        # Arrange
        share_name = self._get_share_reference()

        # Act
        with LogCaptured(self) as log_captured:
            exists = self.fs.exists(share_name)

            log_as_str = log_captured.getvalue()
            self.assertTrue('ERROR' not in log_as_str)

        # Assert
        self.assertFalse(exists)
    def test_delete_container_with_non_existing_container(self):
        # Arrange
        container_name = self._get_container_reference()

        # Act
        with LogCaptured(self) as log_captured:
            deleted = self.bs.delete_container(container_name)

            log_as_str = log_captured.getvalue()
            self.assertTrue('ERROR' not in log_as_str)

        # Assert
        self.assertFalse(deleted)
Ejemplo n.º 14
0
    def test_share_snapshot_not_exists(self):
        # Arrange
        share_name = self._create_share()
        made_up_snapshot = '2017-07-19T06:53:46.0000000Z'

        # Act
        with LogCaptured(self) as log_captured:
            exists = self.fs.exists(share_name, snapshot=made_up_snapshot)

            log_as_str = log_captured.getvalue()
            self.assertTrue('ERROR' not in log_as_str)

        # Assert
        self.assertFalse(exists)