aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-common/tests
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-common/tests')
-rw-r--r--packages/meshbay-common/tests/test_keyderive.py57
-rw-r--r--packages/meshbay-common/tests/test_paths.py7
-rw-r--r--packages/meshbay-common/tests/test_portable_name_parity.py1
3 files changed, 8 insertions, 57 deletions
diff --git a/packages/meshbay-common/tests/test_keyderive.py b/packages/meshbay-common/tests/test_keyderive.py
deleted file mode 100644
index 40b3c71..0000000
--- a/packages/meshbay-common/tests/test_keyderive.py
+++ /dev/null
@@ -1,57 +0,0 @@
-"""Tests for password-based key derivation."""
-
-import pytest
-from meshbay_common.crypto import pk_to_b64
-from meshbay_common.keyderive import (
- decrypt_keypair_bundle,
- derive_keys_from_password,
- encrypt_keypair_bundle,
-)
-
-
-def test_deterministic():
- """Same credentials → same keys."""
- sk_ed1, sk_x1 = derive_keys_from_password("alice", "correct-horse")
- sk_ed2, sk_x2 = derive_keys_from_password("alice", "correct-horse")
- assert pk_to_b64(sk_ed1.public_key()) == pk_to_b64(sk_ed2.public_key())
- assert pk_to_b64(sk_x1.public_key()) == pk_to_b64(sk_x2.public_key())
-
-
-def test_different_users_different_keys():
- sk_ed_a, _ = derive_keys_from_password("alice", "samepassword")
- sk_ed_b, _ = derive_keys_from_password("bob", "samepassword")
- assert pk_to_b64(sk_ed_a.public_key()) != pk_to_b64(sk_ed_b.public_key())
-
-
-def test_different_passwords_different_keys():
- sk_ed1, _ = derive_keys_from_password("alice", "password1")
- sk_ed2, _ = derive_keys_from_password("alice", "password2")
- assert pk_to_b64(sk_ed1.public_key()) != pk_to_b64(sk_ed2.public_key())
-
-
-def test_ed_and_x_keys_independent():
- sk_ed, sk_x = derive_keys_from_password("user", "pass12345")
- from meshbay_common.crypto import sk_to_raw
- assert sk_to_raw(sk_ed) != sk_to_raw(sk_x)
-
-
-def test_bundle_encrypt_decrypt():
- sk_ed, sk_x = derive_keys_from_password("alice", "strongpass!")
- bundle = encrypt_keypair_bundle(sk_ed, sk_x, "password123", "alice")
- sk_ed2, sk_x2 = decrypt_keypair_bundle(bundle, "password123", "alice")
- assert pk_to_b64(sk_ed.public_key()) == pk_to_b64(sk_ed2.public_key())
- assert pk_to_b64(sk_x.public_key()) == pk_to_b64(sk_x2.public_key())
-
-
-def test_bundle_wrong_password_rejected():
- sk_ed, sk_x = derive_keys_from_password("alice", "correctpass")
- bundle = encrypt_keypair_bundle(sk_ed, sk_x, "correctpass", "alice")
- with pytest.raises(Exception):
- decrypt_keypair_bundle(bundle, "wrongpass", "alice")
-
-
-def test_bundle_wrong_username_rejected():
- sk_ed, sk_x = derive_keys_from_password("alice", "pass12345")
- bundle = encrypt_keypair_bundle(sk_ed, sk_x, "pass12345", "alice")
- with pytest.raises(Exception):
- decrypt_keypair_bundle(bundle, "pass12345", "bob") # wrong username salt
diff --git a/packages/meshbay-common/tests/test_paths.py b/packages/meshbay-common/tests/test_paths.py
index 223a2a6..012a32e 100644
--- a/packages/meshbay-common/tests/test_paths.py
+++ b/packages/meshbay-common/tests/test_paths.py
@@ -119,3 +119,10 @@ def test_sanitizing_produces_something_writable():
def test_sanitizing_never_returns_nothing():
assert sanitize_for_download("...") not in ("", None)
assert sanitize_for_download("???") not in ("", None)
+
+
+def test_a_bidi_override_cannot_hide_an_extension():
+ from meshbay_common.paths import portable_name_problem, sanitize_for_download
+ disguised = "invoice‮fdp.exe" # displays as "invoiceexe.pdf"
+ assert sanitize_for_download(disguised) == "invoice_fdp.exe"
+ assert portable_name_problem(disguised)
diff --git a/packages/meshbay-common/tests/test_portable_name_parity.py b/packages/meshbay-common/tests/test_portable_name_parity.py
index 3a491a7..d7df710 100644
--- a/packages/meshbay-common/tests/test_portable_name_parity.py
+++ b/packages/meshbay-common/tests/test_portable_name_parity.py
@@ -26,6 +26,7 @@ pytestmark = pytest.mark.skipif(
)
NAMES = [
+ "invoice\u202efdp.exe", "a\u2066b\u2069.txt", "mark\u200f.txt",
"plain.txt", "Réunion 12:30.pdf", 'a<b>c:d"e/f\\g|h?i*j.txt', "tab\tnew\nline",
"ends with dot.", "ends with space ", "trailing . . ", "CON", "con.txt", "aux.tar.gz",
"COM1", "com10.txt", "LPT9.log", "nul.", ".", "..", "", " ", ".bashrc", "...",