def test_encrypted_swift_storage(monkeypatch):
    swift = MagicMock()
    monkeypatch.setattr(swiftclient.client, "Connection",
                        lambda **kwargs: swift)
    rsa_obj = RSA.generate(1024)
    private_key = rsa_obj.exportKey()
    public_key = rsa_obj.publickey().exportKey()

    data = "Wow a wild data appeared."
    filename = "Just a filename"
    container = "ooh_container"
    key_name = "key-" + filename
    data_name = "data-" + filename

    cypher = EncryptedSharedStorage()
    encrypted_key, encrypted_data = cypher.asym_encryption(data, public_key)

    monkeypatch.setattr(swift, 'get_object', lambda container, key_name: (None, encrypted_key))
    monkeypatch.setattr(swift, 'get_object', lambda container, data_name: (None, encrypted_data))

    storage = EncryptedSwiftStorage('ooh_container')
    storage.save(filename, data, public_key)
    loaded_data = storage.load(filename, private_key)

    assert loaded_data == data
Example #2
0
def test_encrypted_swift_storage(monkeypatch):
    swift = MagicMock()
    monkeypatch.setattr(swiftclient.client, "Connection",
                        lambda **kwargs: swift)
    rsa_obj = RSA.generate(1024)
    private_key = rsa_obj.exportKey()
    public_key = rsa_obj.publickey().exportKey()

    data = "Wow a wild data appeared."
    filename = "Just a filename"
    container = "ooh_container"
    key_name = "key-" + filename
    data_name = "data-" + filename

    cypher = EncryptedSharedStorage()
    encrypted_key, encrypted_data = cypher.asym_encryption(data, public_key)

    monkeypatch.setattr(swift, 'get_object', lambda container, key_name:
                        (None, encrypted_key))
    monkeypatch.setattr(swift, 'get_object', lambda container, data_name:
                        (None, encrypted_data))

    storage = EncryptedSwiftStorage('ooh_container')
    storage.save(filename, data, public_key)
    loaded_data = storage.load(filename, private_key)

    assert loaded_data == data
def test_encrypted_shared_storage():
    rsa_obj = RSA.generate(1024)
    private_key = rsa_obj.exportKey()
    public_key = rsa_obj.publickey().exportKey()

    data = "Wow a wild data appeared."

    cypher = EncryptedSharedStorage()
    encrypted_key, encrypted_data = cypher.asym_encryption(data, public_key)
    decrypted_data = cypher.asym_decryption(encrypted_key, encrypted_data,
                                            private_key)
    assert decrypted_data == data
Example #4
0
def test_encrypted_shared_storage():
    rsa_obj = RSA.generate(1024)
    private_key = rsa_obj.exportKey()
    public_key = rsa_obj.publickey().exportKey()

    data = "Wow a wild data appeared."

    cypher = EncryptedSharedStorage()
    encrypted_key, encrypted_data = cypher.asym_encryption(data, public_key)
    decrypted_data = cypher.asym_decryption(encrypted_key, encrypted_data,
                                            private_key)
    assert decrypted_data == data