コード例 #1
0
 def test_decode_as_text(self):
     self.assertEqual(u'text',
                      base64.decode_as_text(b'dGV4dA=='))
     self.assertEqual(u'text',
                      base64.decode_as_text(u'dGV4dA=='))
     self.assertEqual(u'e:\xe9',
                      base64.decode_as_text(u'ZTrDqQ=='))
     self.assertEqual(u'e:\xe9',
                      base64.decode_as_text(u'ZTrp', encoding='latin1'))
コード例 #2
0
 def test_decode_as_text(self):
     self.assertEqual(u'text',
                      base64.decode_as_text(b'dGV4dA=='))
     self.assertEqual(u'text',
                      base64.decode_as_text(u'dGV4dA=='))
     self.assertEqual(u'e:\xe9',
                      base64.decode_as_text(u'ZTrDqQ=='))
     self.assertEqual(u'e:\xe9',
                      base64.decode_as_text(u'ZTrp', encoding='latin1'))
コード例 #3
0
 def test_can_create_server_with_max_number_personality_files(self):
     # Server should be created successfully if maximum allowed number of
     # files is injected into the server during creation.
     file_contents = 'This is a test file.'
     limits = self.user_client.show_limits()['limits']
     max_file_limit = limits['absolute']['maxPersonality']
     if max_file_limit == -1:
         raise self.skipException("No limit for personality files")
     person = []
     for i in range(0, int(max_file_limit)):
         # NOTE(andreaf) The cirros disk image is blank before boot
         # so we can only inject safely to /
         path = '/test' + str(i) + '.txt'
         person.append({
             'path': path,
             'contents': base64.encode_as_text(file_contents + str(i)),
         })
     password = data_utils.rand_password()
     created_server = self.create_test_server(personality=person,
                                              adminPass=password,
                                              wait_until='ACTIVE',
                                              validatable=True)
     server = self.client.show_server(created_server['id'])['server']
     if CONF.validation.run_validation:
         linux_client = remote_client.RemoteClient(
             self.get_server_ip(server),
             self.ssh_user, password,
             self.validation_resources['keypair']['private_key'],
             server=server,
             servers_client=self.client)
         for i in person:
             self.assertEqual(base64.decode_as_text(i['contents']),
                              linux_client.exec_command(
                                  'sudo cat %s' % i['path']))
コード例 #4
0
 def test_can_create_server_with_max_number_personality_files(self):
     # Server should be created successfully if maximum allowed number of
     # files is injected into the server during creation.
     file_contents = 'This is a test file.'
     limits = self.user_client.show_limits()['limits']
     max_file_limit = limits['absolute']['maxPersonality']
     if max_file_limit == -1:
         raise self.skipException("No limit for personality files")
     person = []
     for i in range(0, int(max_file_limit)):
         path = '/etc/test' + str(i) + '.txt'
         person.append({
             'path': path,
             'contents': base64.encode_as_text(file_contents),
         })
     password = data_utils.rand_password()
     created_server = self.create_test_server(personality=person,
                                              adminPass=password,
                                              wait_until='ACTIVE',
                                              validatable=True)
     server = self.client.show_server(created_server['id'])['server']
     if CONF.validation.run_validation:
         linux_client = remote_client.RemoteClient(
             self.get_server_ip(server),
             self.ssh_user, password,
             self.validation_resources['keypair']['private_key'],
             server=server,
             servers_client=self.client)
         for i in person:
             self.assertEqual(base64.decode_as_text(i['contents']),
                              linux_client.exec_command(
                                  'sudo cat %s' % i['path']))
コード例 #5
0
ファイル: driver.py プロジェクト: daaser/deckhand
 def _base64_decode_payload(self, payload):
     # If the secret_type is 'opaque' then this implies the
     # payload was encoded to base64 previously. Reverse the
     # operation.
     try:
         return ast.literal_eval(base64.decode_as_text(payload))
     except Exception:
         with excutils.save_and_reraise_exception():
             message = ('Failed to unencode the original payload that '
                        'presumably was encoded to base64 with '
                        'secret_type: opaque.')
             LOG.error(message)
コード例 #6
0
ファイル: backup.py プロジェクト: lubidl0/cinder-1
    def decode_record(backup_url):
        """Deserialize backup metadata from string into a dictionary.

        :raises InvalidInput:
        """
        try:
            return jsonutils.loads(base64.decode_as_text(backup_url))
        except TypeError:
            msg = _("Can't decode backup record.")
        except ValueError:
            msg = _("Can't parse backup record.")
        raise exception.InvalidInput(reason=msg)
コード例 #7
0
    def decode_record(backup_url):
        """Deserialize backup metadata from string into a dictionary.

        :raises: InvalidInput
        """
        try:
            return jsonutils.loads(base64.decode_as_text(backup_url))
        except TypeError:
            msg = _("Can't decode backup record.")
        except ValueError:
            msg = _("Can't parse backup record.")
        raise exception.InvalidInput(reason=msg)
コード例 #8
0
    def test_can_create_server_with_max_number_personality_files(self):
        """Test creating server with maximum allowed number of injected files

        Server should be created successfully if maximum allowed number of
        files is injected into the server during creation.
        """
        file_contents = 'This is a test file.'
        limits = self.limits_client.show_limits()['limits']
        max_file_limit = limits['absolute']['maxPersonality']
        if max_file_limit == -1:
            raise self.skipException("No limit for personality files")
        person = []
        for i in range(0, max_file_limit):
            # NOTE(andreaf) The cirros disk image is blank before boot
            # so we can only inject safely to /
            path = '/test' + str(i) + '.txt'
            person.append({
                'path':
                path,
                'contents':
                base64.encode_as_text(file_contents + str(i)),
            })
        password = data_utils.rand_password()
        validation_resources = self.get_test_validation_resources(
            self.os_primary)
        created_server = self.create_test_server(
            personality=person,
            adminPass=password,
            wait_until='ACTIVE',
            validatable=True,
            validation_resources=validation_resources)
        self.addCleanup(waiters.wait_for_server_termination,
                        self.servers_client, created_server['id'])
        self.addCleanup(test_utils.call_and_ignore_notfound_exc,
                        self.servers_client.delete_server,
                        created_server['id'])
        server = self.client.show_server(created_server['id'])['server']
        if CONF.validation.run_validation:
            linux_client = remote_client.RemoteClient(
                self.get_server_ip(server, validation_resources),
                self.ssh_user,
                password,
                validation_resources['keypair']['private_key'],
                server=server,
                servers_client=self.client)
            for i in person:
                self.assertEqual(
                    base64.decode_as_text(i['contents']),
                    linux_client.exec_command('sudo cat %s' % i['path']))
コード例 #9
0
def denormalize_after_decryption(unencrypted, content_type):
    """Translate the decrypted data into the desired content type.

    This is called when the raw keys are requested by the user. The secret
    returned from the SecretStore is the unencrypted parameter. This
    'denormalizes' the data back to its binary format.
    """

    # Process plain-text type.
    if content_type in mime_types.PLAIN_TEXT:
        # normalize text to binary string
        try:
            unencrypted = base64.decode_as_text(unencrypted)
        except UnicodeDecodeError:
            raise s.SecretAcceptNotSupportedException(content_type)

    # Process binary type.
    elif content_type in mime_types.BINARY:
        unencrypted = base64.decode_as_bytes(unencrypted)
    else:
        raise s.SecretContentTypeNotSupportedException(content_type)

    return unencrypted
コード例 #10
0
ファイル: translations.py プロジェクト: abattye/barbican
def denormalize_after_decryption(unencrypted, content_type):
    """Translate the decrypted data into the desired content type.

    This is called when the raw keys are requested by the user. The secret
    returned from the SecretStore is the unencrypted parameter. This
    'denormalizes' the data back to its binary format.
    """

    # Process plain-text type.
    if content_type in mime_types.PLAIN_TEXT:
        # normalize text to binary string
        try:
            unencrypted = base64.decode_as_text(unencrypted)
        except UnicodeDecodeError:
            raise s.SecretAcceptNotSupportedException(content_type)

    # Process binary type.
    elif content_type in mime_types.BINARY:
        unencrypted = base64.decode_as_bytes(unencrypted)
    else:
        raise s.SecretContentTypeNotSupportedException(content_type)

    return unencrypted
コード例 #11
0
 def _decode_url(self, backup_url):
     return json.loads(base64.decode_as_text(backup_url))
コード例 #12
0
def base64decode(value):
    return base64.decode_as_text(value)
コード例 #13
0
 def _decode_url(self, backup_url):
     return json.loads(base64.decode_as_text(backup_url))
コード例 #14
0
ファイル: yaql_functions.py プロジェクト: HarborOS/murano
def base64decode(value):
    return base64.decode_as_text(value)