def test_consumer_should_be_able_to_encrypt_and_decrypt_content(tmpdir):
    content = "blabla"
    fake_key = crypto.get_key("fake_key.bin", str(tmpdir))
    assert content == crypto.decrypt(crypto.encrypt(content, fake_key), fake_key)

    # Generate some big data and try it out
    bigcontent = content * 2 * 1024 + content
    bigcontent = '0123456789abcdef'

    contentf = StringIO.StringIO(bigcontent)
    encryptf = crypto.Encrypt(contentf, fake_key)
    decryptf = crypto.Decrypt(encryptf, fake_key)

    decrypted = ''
    data = decryptf.read(1024)
    while data:
        decrypted += data
        data = decryptf.read(1024)

    assert bigcontent == decrypted
def test_save_new_key_should_create_iv_file_with_right_content(tmpdir):
    fake_key = crypto.get_key("fake_key.bin", str(tmpdir))
    fake_key.iv.iv = "rsrs"
    crypto.save_new_key(fake_key, str(tmpdir))

    assert 'rsrs' == tmpdir.join('fake_key.iv').read()
def test_key_generated_by_consumer_should_be_saved_on_right_path(tmpdir):
    fake_key = crypto.get_key("fake_key.bin", str(tmpdir))
    crypto.save_new_key(fake_key, str(tmpdir))

    assert tmpdir.join("fake_key.bin") in tmpdir.listdir()
    assert tmpdir.join("fake_key.iv") in tmpdir.listdir()