| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- """Tests for loginInfo RSA encryption (login_cipher.py).
- Verifies the output format matches the live capture: base64url-ish
- (+ -> -, / -> _), and decryption with the known public key structure
- round-trips (we can't decrypt without the private key, but we can
- verify format + length for a 1024-bit RSA = 128 bytes -> 172 base64 chars).
- """
- import base64
- import json
- from cq2_sdk.login.login_cipher import encrypt_login_info, _load_public_key
- def test_output_is_base64url_charset():
- out = encrypt_login_info("longwu988", "Longwu1988")
- assert "+" not in out
- assert "/" not in out
- # reverse substitutions to validate it's proper base64
- b64 = out.replace("-", "+").replace("_", "/")
- raw = base64.b64decode(b64)
- # 1024-bit RSA output = 128 bytes
- assert len(raw) == 128
- def test_output_nondeterministic_pkcs1_padding():
- """PKCS1v15 uses random padding -> two encryptions differ."""
- a = encrypt_login_info("user", "pass")
- b = encrypt_login_info("user", "pass")
- assert a != b
- def test_public_key_loads():
- key = _load_public_key()
- assert key.key_size == 1024
- def test_payload_is_json_username_password():
- """The plaintext being encrypted is JSON{username,password} (documented).
- We can't decrypt, but we verify the documented contract exists in the
- function signature and it doesn't crash on unicode."""
- out = encrypt_login_info("玩家测试", "密码123")
- assert len(out) > 100 # sane base64 length
|