|
| 1 | +import pytest |
| 2 | +from src.phase import Phase |
| 3 | +import src |
| 4 | + |
| 5 | +APP_ID = "phApp:v1:e0e50cb9a1953c610126b4092093b1beca51d08d91fc3d9f8d90482a32853215" |
| 6 | +APP_SECRET = "pss:v1:d261abecb6708c18bebdb8b2748ee574e2b0bdeaf19b081a5f10006cc83d48d0:d146c8c6d326a7842ff9b2da0da455b3f7f568a70808e2eb0cfc5143d4fe170f:59e413612e06d75d251e3416361d0743345a9c9eda1cbcf2b1ef16e3077c011c" |
| 7 | +APP_SECRET_INVALID = "pss:v1:d251abecb6708c18bebdb8b2748ee574e2b0bdeaf19b081a5f10006cc83d48d0:d146c8c6d326a7842ff9b2da0da455b3f7f568a70808e2eb0cfc5143d4fe170d:59e413612e06d75d251e3416361d0743345a9c9eda1cbcf2b1ef16e3077c012d" |
| 8 | + |
| 9 | + |
| 10 | +@pytest.fixture(scope="module") |
| 11 | +def phase_instance(): |
| 12 | + return Phase(APP_ID, APP_SECRET) |
| 13 | + |
| 14 | + |
| 15 | +def mock_fetch_app_key(appToken, wrapKey, appId, dataSize): |
| 16 | + return "e35ae9560207c90fa3dd68a8715e13a1ef988bffa284db73f04328df17f37cfe" |
| 17 | + |
| 18 | + |
| 19 | +def test_phase_decrypt_returns_correct_plaintext(phase_instance, monkeypatch): |
| 20 | + data = "Signal" |
| 21 | + |
| 22 | + monkeypatch.setattr(src.phase, "fetch_app_key", mock_fetch_app_key) |
| 23 | + |
| 24 | + ciphertext = phase_instance.encrypt(data) |
| 25 | + |
| 26 | + plaintext = phase_instance.decrypt(ciphertext) |
| 27 | + |
| 28 | + assert plaintext is not None |
| 29 | + assert plaintext == data |
| 30 | + |
| 31 | + |
| 32 | +def test_phase_decrypt_rejects_promise_with_incorrect_app_secret(monkeypatch): |
| 33 | + phase = Phase(APP_ID, APP_SECRET_INVALID) |
| 34 | + |
| 35 | + monkeypatch.setattr(src.phase, "fetch_app_key", mock_fetch_app_key) |
| 36 | + |
| 37 | + data = "Signal" |
| 38 | + ciphertext = phase.encrypt(data) |
| 39 | + |
| 40 | + with pytest.raises(ValueError, match="Something went wrong"): |
| 41 | + phase.decrypt(ciphertext) |
0 commit comments