Example #1
0
    def test_encrypt_file(self, tempdir):
        data = b"data"
        passphrase = "A secret"
        file = path.join(tempdir, "keys_file")

        encrypt_and_save(data, file, passphrase, count=10)

        plaintext = decrypt_and_read(file, passphrase)
        assert plaintext == data
Example #2
0
    def test_invalid_json(self, tempdir):
        device_id = "DEVICEID"
        file = path.join(tempdir, "keys_file")

        encrypt_and_save(b"{sessions: [{}]}", file, "pass", count=10)

        alice_store = DefaultStore("alice", device_id, tempdir, "")
        alice = Olm("alice", device_id, alice_store)

        with pytest.raises(EncryptionError):
            alice.import_keys(file, "pass")
Example #3
0
    def test_invalid_json_schema(self, tempdir):
        device_id = "DEVICEID"
        file = path.join(tempdir, "keys_file")

        payload = {"sessions": [{"algorithm": "test"}]}

        encrypt_and_save(json.dumps(payload).encode(), file, "pass", count=10)

        alice_store = DefaultStore("alice", device_id, tempdir, "")
        alice = Olm("alice", device_id, alice_store)

        with pytest.raises(EncryptionError):
            alice.import_keys(file, "pass")