mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-28 20:33:45 +03:00
add test checking for #1324
This commit is contained in:
parent
a4876c1ac5
commit
acd14d7bf3
37
tests/telethon/crypto/test_rsa.py
Normal file
37
tests/telethon/crypto/test_rsa.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
"""
|
||||||
|
tests for telethon.crypto.rsa
|
||||||
|
"""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from telethon.crypto import rsa
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def server_key_fp():
|
||||||
|
"""factory to return a key, old if so chosen"""
|
||||||
|
def _server_key_fp(old: bool):
|
||||||
|
for fp, data in rsa._server_keys.items():
|
||||||
|
_, old_key = data
|
||||||
|
if old_key == old:
|
||||||
|
return fp
|
||||||
|
|
||||||
|
return _server_key_fp
|
||||||
|
|
||||||
|
def test_encryption_inv_key():
|
||||||
|
"""test for #1324"""
|
||||||
|
assert rsa.encrypt("invalid", b"testdata") is None
|
||||||
|
|
||||||
|
def test_encryption_old_key(server_key_fp):
|
||||||
|
"""test for #1324"""
|
||||||
|
assert rsa.encrypt(server_key_fp(old=True), b"testdata") is None
|
||||||
|
|
||||||
|
def test_encryption_allowed_old_key(server_key_fp):
|
||||||
|
data = rsa.encrypt(server_key_fp(old=True), b"testdata", use_old=True)
|
||||||
|
# we can't verify the data is actually valid because we don't have
|
||||||
|
# the decryption keys
|
||||||
|
assert data is not None and len(data) == 256
|
||||||
|
|
||||||
|
def test_encryption_current_key(server_key_fp):
|
||||||
|
data = rsa.encrypt(server_key_fp(old=False), b"testdata")
|
||||||
|
# we can't verify the data is actually valid because we don't have
|
||||||
|
# the decryption keys
|
||||||
|
assert data is not None and len(data) == 256
|
Loading…
Reference in New Issue
Block a user