File: test_aes.py

package info (click to toggle)
python-aioairq 0.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 152 kB
  • sloc: python: 594; makefile: 5
file content (27 lines) | stat: -rw-r--r-- 613 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import pytest

from aioairq.encrypt import AESCipher
from aioairq.exceptions import InvalidAuth

PASSWORD = "my-$ecur€-pa33w0rD"
DATA = (
    "any string, does not matter... "
    "encrypting it and decrypting it should result "
    "in the very string we started with ;-)"
)


def test_encrypted_decrypt():
    aes = AESCipher(PASSWORD)

    encrypted = aes.encode(DATA)
    decrypted = aes.decode(encrypted)

    assert decrypted == DATA


def test_decrypt_failure():
    encrypted = AESCipher(PASSWORD).encode(DATA)

    with pytest.raises(InvalidAuth):
        AESCipher("wrong-password").decode(encrypted)