124 lines
4.5 KiB
Python
124 lines
4.5 KiB
Python
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
|