1 parent
0421994fe6
commit
425ea7449b
138 files changed
+5705
-1012
No files matched your search
@@ -59,7 +59,7 @@ def test_html_contract():
|
||||
for control_id in ["message-details-menu", "message-transfer-menu", "reader-move-action", "reader-copy-action", "compose-mode"]:
|
||||
assert f'id="{control_id}"' in source
|
||||
assert "data-appearance-preset" not in source
|
||||
for value in ["rustbox", "roundcube-classic", "roundcube-larry", "roundcube-elastic", "clean", "gmail", "proton", "zoho", "outlook", "minimal", "graphite", "high-contrast", "fastmail", "apple-mail", "yahoo", "hey", "nord"]:
|
||||
for value in ["rustbox", "roundcube-classic", "roundcube-larry", "roundcube-elastic", "clean", "gmail", "proton", "zoho", "outlook", "minimal", "graphite", "high-contrast", "fastmail", "apple-mail", "yahoo", "hey", "nord", "github", "gitlab", "discord", "slack", "reddit", "notion"]:
|
||||
assert f'value="{value}"' in source
|
||||
|
||||
|
||||
@@ -116,10 +116,10 @@ def test_modular_js_contract():
|
||||
|
||||
def test_backend_skin_contract_and_version():
|
||||
db_source = (ROOT / "src/db/display_preferences.rs").read_text()
|
||||
for value in ["rustbox", "roundcube-classic", "roundcube-larry", "roundcube-elastic", "clean", "gmail", "proton", "zoho", "outlook", "minimal", "graphite", "high-contrast", "fastmail", "apple-mail", "yahoo", "hey", "nord"]:
|
||||
for value in ["rustbox", "roundcube-classic", "roundcube-larry", "roundcube-elastic", "clean", "gmail", "proton", "zoho", "outlook", "minimal", "graphite", "high-contrast", "fastmail", "apple-mail", "yahoo", "hey", "nord", "github", "gitlab", "discord", "slack", "reddit", "notion"]:
|
||||
assert f'"{value}"' in db_source
|
||||
cargo = (ROOT / "Cargo.toml").read_text()
|
||||
assert 'version = "0.0.6"' in cargo
|
||||
assert 'version = "0.1.0"' in cargo
|
||||
config = (ROOT / "src/config.rs").read_text()
|
||||
assert "pub default_theme: String" in config
|
||||
assert '"system" | "dark" | "light"' in config
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
from pathlib import Path
|
||||
import sqlite3
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_all_user_sqlite_migrations_apply_on_fresh_database(tmp_path):
|
||||
db_path = tmp_path / "user.sqlite"
|
||||
conn = sqlite3.connect(db_path)
|
||||
migrations = sorted((ROOT / "migrations/sqlite").glob("V*.sql"))
|
||||
user_migrations = [m for m in migrations if m.name != "V047__sessions.sql"]
|
||||
assert len(user_migrations) == 46
|
||||
for migration in user_migrations:
|
||||
conn.executescript(migration.read_text())
|
||||
version = int(migration.name[1:4])
|
||||
conn.execute(f"PRAGMA user_version = {version}")
|
||||
assert conn.execute("PRAGMA user_version").fetchone()[0] == 46
|
||||
tables = {row[0] for row in conn.execute("SELECT name FROM sqlite_master WHERE type='table'")}
|
||||
assert {"user_meta", "folders", "messages", "drafts", "contacts"} <= tables
|
||||
assert "sessions" not in tables
|
||||
conn.close()
|
||||
|
||||
|
||||
def test_session_sqlite_migration_is_separate_and_valid(tmp_path):
|
||||
db_path = tmp_path / "rustbox.sqlite"
|
||||
conn = sqlite3.connect(db_path)
|
||||
conn.executescript((ROOT / "migrations/sqlite/V047__sessions.sql").read_text())
|
||||
tables = {row[0] for row in conn.execute("SELECT name FROM sqlite_master WHERE type='table'")}
|
||||
indexes = {row[0] for row in conn.execute("SELECT name FROM sqlite_master WHERE type='index'")}
|
||||
assert "sessions" in tables
|
||||
assert {"idx_sessions_browser", "idx_sessions_user", "idx_sessions_expiry"} <= indexes
|
||||
conn.close()
|
||||
@@ -0,0 +1,74 @@
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
EXPECTED = (
|
||||
"uid, folder, message_id, in_reply_to, references_header, subject, "
|
||||
"from_address, from_name, to_addresses, cc_addresses, date, flags, "
|
||||
"size, has_attachments, snippet, reaction"
|
||||
)
|
||||
|
||||
|
||||
def read(rel: str) -> str:
|
||||
return (ROOT / rel).read_text()
|
||||
|
||||
|
||||
def test_cached_message_projection_is_stable_for_all_sql_dialects():
|
||||
for dialect in ("sqlite", "mysql", "pgsql"):
|
||||
text = read(f"src/queries/{dialect}/queries.rs")
|
||||
m = re.search(r'pub const MSG_SELECT_COLS: &str = "([^"]+)";', text)
|
||||
assert m, dialect
|
||||
assert m.group(1) == EXPECTED, dialect
|
||||
|
||||
|
||||
def test_cached_message_row_mapping_matches_projection():
|
||||
text = read("src/db/messages.rs")
|
||||
assert "let has_attachments_int: i32 = row.get(13)?;" in text
|
||||
assert "flags: row.get(11)?" in text
|
||||
assert "size: row.get(12)?" in text
|
||||
assert "snippet: row.get(14)?" in text
|
||||
assert "reaction: row.get(15)?" in text
|
||||
|
||||
|
||||
def test_cached_message_projection_does_not_include_body_cache_columns():
|
||||
sqlite = read("src/queries/sqlite/queries.rs")
|
||||
m = re.search(r'pub const MSG_SELECT_COLS: &str = "([^"]+)";', sqlite)
|
||||
projection = m.group(1)
|
||||
for unexpected in ("date_epoch", "body_cached", "body_html", "body_text", "attachments_json", "raw_headers", "email_theme"):
|
||||
assert unexpected not in projection
|
||||
|
||||
|
||||
def test_cached_message_projection_executes_on_fresh_sqlite_schema():
|
||||
import sqlite3
|
||||
|
||||
conn = sqlite3.connect(":memory:")
|
||||
migration_dir = ROOT / "migrations/sqlite"
|
||||
for migration in sorted(migration_dir.glob("V*.sql")):
|
||||
if migration.name.startswith("V047__sessions"):
|
||||
continue
|
||||
conn.executescript(migration.read_text())
|
||||
|
||||
conn.execute("INSERT OR IGNORE INTO folders(name) VALUES ('INBOX')")
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO messages
|
||||
(uid, folder, message_id, in_reply_to, references_header, subject,
|
||||
from_address, from_name, to_addresses, cc_addresses, date, flags,
|
||||
size, has_attachments, snippet, date_epoch, reaction)
|
||||
VALUES (1, 'INBOX', 'm1', NULL, NULL, 'Subject',
|
||||
'a@example.com', 'Alice', '[]', '[]', '2026-10-30', '\\Seen',
|
||||
123, 1, 'snippet', 1761840000, 'ok')
|
||||
"""
|
||||
)
|
||||
|
||||
row = conn.execute(
|
||||
f"SELECT {EXPECTED} FROM messages WHERE folder = ? AND uid = ?",
|
||||
("INBOX", 1),
|
||||
).fetchone()
|
||||
|
||||
assert len(row) == 16
|
||||
assert row[11] == "\\Seen"
|
||||
assert row[12] == 123
|
||||
assert row[13] == 1
|
||||
assert row[14] == "snippet"
|
||||
assert row[15] == "ok"
|
||||
@@ -0,0 +1,91 @@
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SRC = ROOT / "src"
|
||||
DIALECTS = ("sqlite", "mysql", "pgsql")
|
||||
|
||||
SQL_LITERAL = re.compile(
|
||||
r'(?:r#{0,8})?"\s*(?:SELECT\s+(?:\*|[A-Za-z_(])|INSERT\s+INTO|INSERT\s+OR\s+(?:IGNORE|REPLACE)\s+INTO|UPDATE\s+[A-Za-z_]|DELETE\s+FROM|PRAGMA\s+[A-Za-z_]|WITH\s+[A-Za-z_]|CREATE\s+(?:TABLE|INDEX)|ALTER\s+TABLE|DROP\s+(?:TABLE|INDEX))',
|
||||
re.IGNORECASE | re.MULTILINE,
|
||||
)
|
||||
CONST_NAME = re.compile(r"pub const\s+([A-Z][A-Z0-9_]*)\s*:")
|
||||
MODULE = re.compile(r"^pub mod\s+([a-zA-Z0-9_]+)\s*\{", re.MULTILINE)
|
||||
|
||||
|
||||
def read(path: str) -> str:
|
||||
return (ROOT / path).read_text()
|
||||
|
||||
|
||||
def test_central_query_tree_exists():
|
||||
for dialect in DIALECTS:
|
||||
assert (ROOT / f"src/queries/{dialect}/queries.rs").is_file()
|
||||
assert (ROOT / f"src/queries/{dialect}/mod.rs").is_file()
|
||||
assert not (ROOT / "src/session_store/queries").exists()
|
||||
|
||||
|
||||
def test_session_store_uses_central_query_tree():
|
||||
db = read("src/session_store/database.rs")
|
||||
for dialect in DIALECTS:
|
||||
assert f"queries::{dialect}::queries::sessions::" in db
|
||||
|
||||
|
||||
def test_no_executable_sql_literals_outside_query_tree():
|
||||
offenders = []
|
||||
for path in SRC.rglob("*.rs"):
|
||||
if "queries" in path.parts:
|
||||
continue
|
||||
text = path.read_text()
|
||||
if SQL_LITERAL.search(text):
|
||||
offenders.append(str(path.relative_to(ROOT)))
|
||||
assert offenders == []
|
||||
|
||||
|
||||
def test_dialect_catalogs_have_same_modules_and_query_constants():
|
||||
catalogs = {d: read(f"src/queries/{d}/queries.rs") for d in DIALECTS}
|
||||
base_modules = set(MODULE.findall(catalogs["sqlite"]))
|
||||
assert "sessions" in base_modules
|
||||
for dialect in DIALECTS[1:]:
|
||||
assert set(MODULE.findall(catalogs[dialect])) == base_modules
|
||||
|
||||
# Every dialect must expose the same named query constants/templates.
|
||||
base_consts = set(CONST_NAME.findall(catalogs["sqlite"]))
|
||||
assert len(base_consts) >= 10
|
||||
for dialect in DIALECTS[1:]:
|
||||
assert set(CONST_NAME.findall(catalogs[dialect])) == base_consts
|
||||
|
||||
|
||||
def test_backend_specific_session_placeholders_are_preserved():
|
||||
sqlite = read("src/queries/sqlite/queries.rs")
|
||||
mysql = read("src/queries/mysql/queries.rs")
|
||||
pgsql = read("src/queries/pgsql/queries.rs")
|
||||
assert 'BY_TOKEN: &str = "SELECT * FROM sessions WHERE token = ?"' in sqlite
|
||||
assert 'BY_TOKEN: &str = "SELECT * FROM sessions WHERE token = ?"' in mysql
|
||||
assert 'BY_TOKEN: &str = "SELECT * FROM sessions WHERE token = $1"' in pgsql
|
||||
|
||||
|
||||
def test_dynamic_query_macros_do_not_capture_caller_locals():
|
||||
sqlite = read("src/queries/sqlite/queries.rs")
|
||||
# macro_rules identifiers are hygienic: caller-local values must arrive as metavariables.
|
||||
forbidden = [
|
||||
'WHERE id = ?{idx}',
|
||||
'ORDER BY {order_by}',
|
||||
'{where_clause}',
|
||||
'SET {set_clause}',
|
||||
'user_version = {current}',
|
||||
'user_version = {version}',
|
||||
]
|
||||
macro_section = sqlite[sqlite.index("#[macro_export]"):]
|
||||
for fragment in forbidden:
|
||||
assert fragment not in macro_section
|
||||
|
||||
calendar = read("src/db/calendar.rs")
|
||||
messages = read("src/db/messages.rs")
|
||||
notifications = read("src/db/notification_preferences.rs")
|
||||
pool = read("src/db/pool.rs")
|
||||
assert 'rustbox_query_db_calendar_004!(sets.join(", "), idx)' in calendar
|
||||
assert 'rustbox_query_db_messages_002!(&order_by)' in messages
|
||||
assert 'rustbox_query_db_messages_005!(&where_clause, param_values.len() + 1)' in messages
|
||||
assert 'rustbox_query_db_notification_preferences_001!(&set_clause, idx)' in notifications
|
||||
assert re.search(r'db_pool::set_user_version\(\s*version,?\s*\)', pool)
|
||||
assert 'refinery_schema_history' not in pool
|
||||
@@ -6,8 +6,8 @@ def read(path):
|
||||
return (ROOT / path).read_text()
|
||||
|
||||
def test_release_version():
|
||||
assert 'version = "0.0.5"' in read("Cargo.toml")
|
||||
assert "# RustBox 0.0.5" in read("README.md")
|
||||
assert 'version = "0.1.0"' in read("Cargo.toml")
|
||||
assert "# RustBox 0.1.0" in read("README.md")
|
||||
|
||||
def test_realtime_contract():
|
||||
ws = read("src/realtime/ws.rs")
|
||||
|
||||
@@ -5,9 +5,13 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
def read(path):
|
||||
return (ROOT / path).read_text()
|
||||
|
||||
def test_release_version():
|
||||
assert 'version = "0.0.6"' in read("Cargo.toml")
|
||||
assert "# RustBox 0.0.6" in read("README.md")
|
||||
def test_release_version_is_at_least_006():
|
||||
import re
|
||||
cargo = read("Cargo.toml")
|
||||
match = re.search(r'^version = "(\d+)\.(\d+)\.(\d+)"$', cargo, re.M)
|
||||
assert match
|
||||
version = tuple(map(int, match.groups()))
|
||||
assert version >= (0, 0, 6)
|
||||
|
||||
def test_realtime_contract():
|
||||
ws = read("src/realtime/ws.rs")
|
||||
@@ -53,7 +57,7 @@ def test_mobile_reader_contract():
|
||||
|
||||
def test_message_links_can_open_new_tabs_from_sandbox():
|
||||
reader = read("src/web/js/40-messages-reader.js")
|
||||
assert 'iframe.setAttribute("sandbox", "allow-popups allow-popups-to-escape-sandbox")' in reader
|
||||
assert 'allow-popups allow-popups-to-escape-sandbox' in reader
|
||||
|
||||
|
||||
def test_extended_color_presets_contract():
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
def read(path):
|
||||
return (ROOT / path).read_text()
|
||||
|
||||
def test_release_version():
|
||||
assert 'version = "0.1.0"' in read("Cargo.toml")
|
||||
assert "# RustBox 0.1.0" in read("README.md")
|
||||
|
||||
def test_realtime_contract():
|
||||
ws = read("src/realtime/ws.rs")
|
||||
js = read("src/web/js/80-settings-realtime.js")
|
||||
assert '"type": "heartbeat"' in ws
|
||||
assert "Heartbeat timeout" in js
|
||||
assert "2 ** attempt" in js
|
||||
assert "resyncRealtimeState" in js
|
||||
assert "realtimeSeenEvents" in js
|
||||
assert "realtimePollTimer" in js
|
||||
assert "realtimeRefreshEvents" in js
|
||||
|
||||
def test_upload_progress_is_not_toast_driven():
|
||||
compose = read("src/web/js/50-compose.js")
|
||||
block = compose[compose.index("async function uploadComposeFiles"):compose.index("function previewMarkdown")]
|
||||
assert "progressToast(" not in block
|
||||
assert "setComposeUploadProgress" in block
|
||||
assert "AbortController" in block
|
||||
|
||||
def test_fullscreen_reader_contract():
|
||||
html = read("src/web/index.html")
|
||||
reader = read("src/web/js/40-messages-reader.js")
|
||||
menu = read("src/web/js/60-mail-actions-search.js")
|
||||
css = read("src/web/css/30-mail.css")
|
||||
assert 'id="reader-fullscreen"' in html
|
||||
assert "Open full screen" in menu
|
||||
assert "message-fullscreen-action" in reader
|
||||
assert "reader-fullscreen" in reader
|
||||
assert "history.pushState" in reader
|
||||
assert "reader-pane.reader-fullscreen" in css
|
||||
assert ".reader-pane.reader-fullscreen .message-body" in css
|
||||
assert "max-width: none" in css
|
||||
|
||||
def test_mobile_reader_contract():
|
||||
css = read("src/web/css/30-mail.css")
|
||||
responsive = read("src/web/css/60-responsive.css")
|
||||
bindings = read("src/web/js/95-bindings-boot.js")
|
||||
assert ".toolbar-menu-popover button" in css
|
||||
assert ".attachment-item .attachment-button" in css
|
||||
assert "min-height: 34px" in responsive
|
||||
assert 'bottom: "8px"' not in bindings
|
||||
assert 'rect.bottom + 5' in bindings
|
||||
|
||||
def test_message_links_can_open_new_tabs_from_sandbox():
|
||||
reader = read("src/web/js/40-messages-reader.js")
|
||||
assert 'iframe.setAttribute("sandbox", "allow-popups allow-popups-to-escape-sandbox allow-downloads")' in reader
|
||||
|
||||
|
||||
def test_extended_color_presets_contract():
|
||||
html = read("src/web/index.html")
|
||||
css = read("src/web/css/00-tokens.css")
|
||||
backend = read("src/db/display_preferences.rs")
|
||||
presets = ["emerald", "lime", "sky", "navy", "plum", "magenta", "copper", "sand"]
|
||||
for preset in presets:
|
||||
assert f'<option value="{preset}">' in html
|
||||
assert f'html[data-color-preset="{preset}"]' in css
|
||||
assert f'"{preset}"' in backend
|
||||
|
||||
|
||||
def test_all_predefined_interface_styles_are_visible_and_wired():
|
||||
import re
|
||||
html = read("src/web/index.html")
|
||||
js = read("src/web/js/20-preferences-auth.js")
|
||||
css = read("src/web/css/55-roundcube-skins.css") + read("src/web/css/56-interface-styles.css")
|
||||
backend = read("src/db/display_preferences.rs")
|
||||
config = read("src/config.rs")
|
||||
select = re.search(r'<select id="pref-interface-skin">(.*?)</select>', html, re.S).group(1)
|
||||
visible = set(re.findall(r'<option value="([^"]+)">', select))
|
||||
expected = {
|
||||
"default", "rustbox", "roundcube-classic", "roundcube-larry", "roundcube-elastic",
|
||||
"clean", "gmail", "proton", "zoho", "outlook", "minimal", "graphite",
|
||||
"high-contrast", "fastmail", "apple-mail", "yahoo", "hey", "nord",
|
||||
"github", "gitlab", "discord", "slack", "reddit", "notion",
|
||||
}
|
||||
assert visible == expected
|
||||
for skin in expected - {"default", "rustbox"}:
|
||||
assert f'data-interface-skin="{skin}"' in css
|
||||
assert re.search(rf'(?:\"{re.escape(skin)}\"|\b{re.escape(skin)})\s*:', js)
|
||||
assert f'"{skin}"' in backend
|
||||
for skin in expected - {"default"}:
|
||||
assert f'"{skin}"' in config
|
||||
|
||||
|
||||
def test_new_website_inspired_styles_have_light_and_dark_palettes():
|
||||
css = read("src/web/css/56-interface-styles.css")
|
||||
for skin in ["github", "gitlab", "discord", "slack", "reddit", "notion"]:
|
||||
assert f'html[data-interface-skin="{skin}"][data-theme="light"]' in css
|
||||
assert f'html[data-interface-skin="{skin}"][data-theme="dark"]' in css
|
||||
@@ -0,0 +1,123 @@
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
def read(path):
|
||||
return (ROOT / path).read_text()
|
||||
|
||||
def test_release_version():
|
||||
assert 'version = "0.1.0"' in read('Cargo.toml')
|
||||
assert '# RustBox 0.1.0' in read('README.md')
|
||||
|
||||
def test_default_session_storage_is_sqlite_in_data_dir():
|
||||
cfg = read('src/config.rs')
|
||||
db = read('src/session_store/database.rs')
|
||||
assert '"sqlite".to_string()' in cfg
|
||||
assert 'session_backend' in cfg
|
||||
assert 'join("rustbox.sqlite")' in db
|
||||
assert 'config.data_dir' in db
|
||||
|
||||
def test_supported_sql_backends_and_query_files():
|
||||
cfg = read('src/config.rs')
|
||||
assert '"sqlite" | "mysql" | "pgsql"' in cfg
|
||||
for dialect in ['sqlite', 'mysql', 'pgsql']:
|
||||
q = ROOT / f'src/queries/{dialect}/queries.rs'
|
||||
m = ROOT / f'migrations/{dialect}/V047__sessions.sql'
|
||||
assert q.is_file(), q
|
||||
assert m.is_file(), m
|
||||
assert 'pub mod sessions' in q.read_text()
|
||||
assert 'CREATE TABLE IF NOT EXISTS sessions' in m.read_text()
|
||||
|
||||
def test_legacy_user_migrations_are_scoped_to_sqlite():
|
||||
pool = read('src/db/pool.rs')
|
||||
assert '../../migrations/sqlite/V001__initial_schema.sql' in pool
|
||||
assert (ROOT / 'migrations/sqlite/V046__preset_scale_unlock.sql').is_file()
|
||||
|
||||
|
||||
def test_migrations_are_flat_by_dialect():
|
||||
for dialect in ["sqlite", "mysql", "pgsql"]:
|
||||
root = ROOT / "migrations" / dialect
|
||||
assert root.is_dir()
|
||||
assert not any(path.is_dir() for path in root.iterdir())
|
||||
assert (ROOT / "migrations/sqlite/V001__initial_schema.sql").is_file()
|
||||
assert (ROOT / "migrations/sqlite/V047__sessions.sql").is_file()
|
||||
|
||||
def test_persisted_credentials_are_encrypted():
|
||||
crypto = read('src/session_store/crypto.rs')
|
||||
session = read('src/auth/session.rs')
|
||||
assert 'Aes256Gcm' in crypto
|
||||
assert 'password_ciphertext' in session
|
||||
assert 'crypto.encrypt(&session.password)' in session
|
||||
assert 'crypto.decrypt(&record.password_ciphertext)' in session
|
||||
|
||||
def test_cluster_shared_reads_are_used_in_request_paths():
|
||||
middleware = read('src/auth/middleware.rs')
|
||||
auth = read('src/routes/auth.rs')
|
||||
ws = read('src/realtime/ws.rs')
|
||||
assert 'get_account_session_shared' in middleware
|
||||
assert 'get_browser_accounts_shared' in auth
|
||||
assert 'get_browser_accounts_shared' in ws
|
||||
|
||||
def test_redis_direct_and_sentinel_are_supported():
|
||||
redis = read('src/session_store/redis_store.rs')
|
||||
cfg = read('src/config.rs')
|
||||
assert 'get-master-addr-by-name' in redis
|
||||
assert 'redis_url' in cfg
|
||||
assert 'redis_sentinel_nodes' in cfg
|
||||
assert 'redis_sentinel_master' in cfg
|
||||
|
||||
def test_restart_regression_test_exists():
|
||||
session = read('src/auth/session.rs')
|
||||
assert 'persistent_sqlite_session_survives_store_restart' in session
|
||||
assert 'session should survive restart' in session
|
||||
|
||||
|
||||
def test_sqlite_native_link_is_owned_only_by_rusqlite():
|
||||
import tomllib
|
||||
|
||||
cargo = tomllib.loads(read('Cargo.toml'))
|
||||
sqlx = cargo['dependencies']['sqlx']
|
||||
assert sqlx['default-features'] is False
|
||||
assert 'sqlite' not in sqlx['features']
|
||||
assert {'mysql', 'postgres'} <= set(sqlx['features'])
|
||||
|
||||
db = read('src/session_store/database.rs')
|
||||
assert 'SqlitePool' not in db
|
||||
assert 'rusqlite::{Connection, params}' in db
|
||||
|
||||
|
||||
def test_user_provisioning_uses_only_sqlite_user_migrator():
|
||||
user_data = read('src/auth/user_data.rs')
|
||||
assert 'db::pool::open_user_db(data_dir, user_hash)' in user_data
|
||||
assert 'embed_migrations' not in user_data
|
||||
assert 'refinery' not in user_data
|
||||
|
||||
|
||||
def test_refinery_dependency_and_history_bridge_are_removed():
|
||||
cargo = read('Cargo.toml')
|
||||
pool = read('src/db/pool.rs')
|
||||
assert 'refinery =' not in cargo
|
||||
assert 'refinery_schema_history' not in pool
|
||||
assert 'sync user_version from refinery' not in pool
|
||||
|
||||
|
||||
def test_release_script_runs_full_locked_rust_gate():
|
||||
script = read('scripts/build-release.sh')
|
||||
assert 'cargo fmt --all -- --check' in script
|
||||
assert 'cargo test --locked' in script
|
||||
assert 'cargo clippy --locked --all-targets -- -D warnings' in script
|
||||
assert 'cargo build --release --locked' in script
|
||||
|
||||
|
||||
def test_session_store_selects_only_backend_specific_session_migration():
|
||||
db = read('src/session_store/database.rs')
|
||||
for dialect in ('sqlite', 'mysql', 'pgsql'):
|
||||
assert f'../../migrations/{dialect}/V047__sessions.sql' in db
|
||||
assert 'embed_migrations' not in db
|
||||
|
||||
|
||||
def test_refinery_is_absent_from_lockfile_too():
|
||||
lock = read('Cargo.lock')
|
||||
assert 'name = "refinery"' not in lock
|
||||
assert 'name = "refinery-core"' not in lock
|
||||
assert 'name = "refinery-macros"' not in lock
|
||||
@@ -0,0 +1,61 @@
|
||||
from pathlib import Path
|
||||
import sqlite3
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_sqlite_session_migration_executes_and_survives_reopen(tmp_path):
|
||||
db_path = tmp_path / "rustbox.sqlite"
|
||||
migration = (ROOT / "migrations/sqlite/V047__sessions.sql").read_text()
|
||||
|
||||
conn = sqlite3.connect(db_path)
|
||||
conn.executescript(migration)
|
||||
conn.execute(
|
||||
"""INSERT INTO sessions (
|
||||
token, account_id, browser_id, email, password_ciphertext, user_hash,
|
||||
imap_host, imap_port, imap_tls, imap_tls_verify,
|
||||
smtp_host, smtp_port, smtp_tls, smtp_tls_verify,
|
||||
timeout_secs, created_at_unix, last_accessed_unix, user_agent
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
(
|
||||
"token-1", "account-1", "browser-1", "user@example.com", "ciphertext", "hash-1",
|
||||
"imap.example.com", 993, 1, 1, "smtp.example.com", 587, 1, 1,
|
||||
3600, 1000, 1000, "pytest",
|
||||
),
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
reopened = sqlite3.connect(db_path)
|
||||
row = reopened.execute(
|
||||
"SELECT token, account_id, browser_id, password_ciphertext FROM sessions WHERE token = ?",
|
||||
("token-1",),
|
||||
).fetchone()
|
||||
reopened.close()
|
||||
assert row == ("token-1", "account-1", "browser-1", "ciphertext")
|
||||
|
||||
|
||||
def test_sqlite_expiry_query_removes_only_expired_sessions(tmp_path):
|
||||
db_path = tmp_path / "rustbox.sqlite"
|
||||
conn = sqlite3.connect(db_path)
|
||||
conn.executescript((ROOT / "migrations/sqlite/V047__sessions.sql").read_text())
|
||||
base = (
|
||||
"account", "browser", "user@example.com", "ciphertext", "hash",
|
||||
"imap", 993, 1, 1, "smtp", 587, 1, 1, 100, 1000, "pytest",
|
||||
)
|
||||
for token, last_accessed in [("expired", 1000), ("live", 1950)]:
|
||||
conn.execute(
|
||||
"""INSERT INTO sessions (
|
||||
token, account_id, browser_id, email, password_ciphertext, user_hash,
|
||||
imap_host, imap_port, imap_tls, imap_tls_verify,
|
||||
smtp_host, smtp_port, smtp_tls, smtp_tls_verify,
|
||||
timeout_secs, created_at_unix, last_accessed_unix, user_agent
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
(token, f"{base[0]}-{token}", *base[1:15], last_accessed, base[15]),
|
||||
)
|
||||
delete_sql = (ROOT / "src/queries/sqlite/queries.rs").read_text()
|
||||
assert "last_accessed_unix + timeout_secs < ?" in delete_sql
|
||||
conn.execute("DELETE FROM sessions WHERE last_accessed_unix + timeout_secs < ?", (2000,))
|
||||
remaining = [row[0] for row in conn.execute("SELECT token FROM sessions ORDER BY token")]
|
||||
conn.close()
|
||||
assert remaining == ["live"]
|
||||
@@ -0,0 +1,35 @@
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_query_catalog_dead_code_lint_is_scoped_to_queries_only():
|
||||
queries_mod = (ROOT / "src/queries/mod.rs").read_text()
|
||||
for dialect in ("sqlite", "mysql", "pgsql"):
|
||||
assert f"#[allow(dead_code)]\npub mod {dialect};" in queries_mod
|
||||
assert "#![allow(dead_code)]" not in queries_mod
|
||||
|
||||
rust_sources = [p for p in (ROOT / "src").rglob("*.rs") if p != ROOT / "src/queries/mod.rs"]
|
||||
for path in rust_sources:
|
||||
text = path.read_text()
|
||||
assert "#![allow(warnings)]" not in text, path
|
||||
assert "#![allow(dead_code)]" not in text, path
|
||||
|
||||
|
||||
def test_test_only_session_helpers_are_not_in_production_build():
|
||||
text = (ROOT / "src/auth/session.rs").read_text()
|
||||
signatures = [
|
||||
"pub fn new(timeout: Duration) -> Self",
|
||||
"pub fn new_with_tls_verify(timeout: Duration, tls_verify_override: Option<bool>) -> Self",
|
||||
"pub fn add_account_to_browser(",
|
||||
]
|
||||
for signature in signatures:
|
||||
pos = text.index(signature)
|
||||
prefix = text[max(0, pos - 120):pos]
|
||||
assert "#[cfg(test)]" in prefix, signature
|
||||
|
||||
|
||||
def test_test_only_rfc822_helper_is_not_in_production_build():
|
||||
text = (ROOT / "src/smtp/builder.rs").read_text()
|
||||
pos = text.index("pub fn build_rfc822(")
|
||||
assert "#[cfg(test)]" in text[max(0, pos - 80):pos]
|
||||
@@ -0,0 +1,32 @@
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def read(path: str) -> str:
|
||||
return (ROOT / path).read_text()
|
||||
|
||||
|
||||
def test_dialect_query_catalogs_are_intentionally_warning_silent():
|
||||
mod = read("src/queries/mod.rs")
|
||||
for dialect in ("sqlite", "mysql", "pgsql"):
|
||||
assert f"#[allow(dead_code)]\npub mod {dialect};" in mod
|
||||
|
||||
|
||||
def test_test_only_session_helpers_do_not_enter_production_build():
|
||||
session = read("src/auth/session.rs")
|
||||
signatures = [
|
||||
"pub fn new(timeout: Duration) -> Self",
|
||||
"pub fn new_with_tls_verify(timeout: Duration, tls_verify_override: Option<bool>) -> Self",
|
||||
"pub fn add_account_to_browser(",
|
||||
]
|
||||
for signature in signatures:
|
||||
pos = session.index(signature)
|
||||
prefix = session[max(0, pos - 120):pos]
|
||||
assert "#[cfg(test)]" in prefix
|
||||
|
||||
|
||||
def test_test_only_rfc822_helper_does_not_enter_production_build():
|
||||
builder = read("src/smtp/builder.rs")
|
||||
pos = builder.index("pub fn build_rfc822")
|
||||
assert "#[cfg(test)]" in builder[max(0, pos - 80):pos]
|
||||
Reference in new issue
Block a user