44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
import json
|
|
import re
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
FRONTEND = ROOT / "frontend"
|
|
REGISTRY = FRONTEND / "private-data-registry.js"
|
|
|
|
|
|
def test_private_database_registry_covers_every_shipped_indexeddb_store():
|
|
harness = f"""
|
|
const databases = require({json.dumps(str(REGISTRY))});
|
|
process.stdout.write(JSON.stringify(databases));
|
|
"""
|
|
completed = subprocess.run(
|
|
["node", "-e", harness], text=True, capture_output=True, check=True
|
|
)
|
|
registered = set(json.loads(completed.stdout))
|
|
|
|
opened = set()
|
|
for path in FRONTEND.glob("*.js"):
|
|
source = path.read_text()
|
|
opened.update(re.findall(r"dbName\s*=\s*['\"](stackchain-[^'\"]+)['\"]", source))
|
|
opened.update(re.findall(r"createIndexedDbTransaction\([^\n]+['\"](stackchain-[^'\"]+)['\"]", source))
|
|
|
|
assert registered == opened
|
|
assert registered == {
|
|
"stackchain-background-outbox-v1",
|
|
"stackchain-offline-work-v2",
|
|
"stackchain-unfiled-captures-v1",
|
|
}
|
|
|
|
|
|
def test_every_private_data_purge_context_consumes_the_shared_registry():
|
|
for name in ("private-device-data.js", "session.js", "service-worker.js"):
|
|
source = (FRONTEND / name).read_text()
|
|
assert "stackchainPrivateDatabases" in source
|
|
assert not re.search(r"deletePrivateDatabase\(['\"]stackchain-", source)
|
|
|
|
html = (FRONTEND / "index.html").read_text()
|
|
assert html.index('static/private-data-registry.js') < html.index('static/session.js')
|