diff --git a/Plans/02 Verify/S008-verify-stores.md b/Plans/02 Verify/S008-verify-stores.md index 76fb715..e563ed3 100644 --- a/Plans/02 Verify/S008-verify-stores.md +++ b/Plans/02 Verify/S008-verify-stores.md @@ -12,8 +12,8 @@ Verify passwords/vault and autofill, permissions prompts, history/bookmarks/down ## Steps - [x] Script: open every nacre:// page and take a shot; check none panics or renders empty -- [ ] Vault: create, lock/unlock, save a login from a local form page, autofill it, export/import; check the vault file is encrypted -- [ ] Permissions: a local page asking for notifications/geolocation/camera; allow/deny/remember; check `permissions` store +- [x] Vault: create, lock/unlock, save a login from a local form page, autofill it, export/import; check the vault file is encrypted +- [x] Permissions: a local page asking for notifications/geolocation/camera; allow/deny/remember; check `permissions` store - [ ] History, bookmarks (add, folder, bookmarks bar, import/export HTML), downloads page lists entries - [ ] User scripts/styles apply on matching pages; install a site as an app and launch it - [ ] Importer: build a fake old-Nacre profile from `~/Documents/Apps/Nacre` config format in a temp dir (never the user's real profile) and import it diff --git a/src/selftest.rs b/src/selftest.rs index d714731..4d48cac 100644 --- a/src/selftest.rs +++ b/src/selftest.rs @@ -12,6 +12,7 @@ //! set change a setting, e.g. `set /privacy/https_only true` //! perm allow|block|default store a site's answer for a permission (kinds: store::permissions::Kind keys) //! prompt allow|deny [remember] answer the active tab's first permission prompt +//! vault master | lock | unlock | remove_master | export | import the password vault //! flyout main, downloads, shield, vpn, media, siteinfo, profiles, apps, qr, tabmenu, back, //! bookmark (edit the current page's bookmark), none //! type put text in the address bar with its suggestions open @@ -288,6 +289,32 @@ impl App { } self.refresh_hub_config(); }, + "vault" => { + let (what, arg) = rest.split_once(char::is_whitespace).map(|(w, a)| (w, a.trim())).unwrap_or((rest, "")); + let result = { + let mut vault = self.shared.vault.borrow_mut(); + match what { + "master" => vault.set_master(arg).map(|_| String::new()), + "lock" => { + vault.lock(); + Ok(String::new()) + }, + "unlock" => vault.unlock(arg).map(|_| String::new()), + "remove_master" => vault.remove_master().map(|_| String::new()), + "export" => vault.export_csv().and_then(|csv| std::fs::write(arg, csv).map_err(|e| crate::store::vault::VaultError::Io(e.to_string()))).map(|_| String::new()), + "import" => match std::fs::read_to_string(arg) { + Ok(text) => vault.import_csv(&text).map(|(added, skipped)| format!("imported {added}, skipped {skipped}")), + Err(error) => Err(crate::store::vault::VaultError::Io(error.to_string())), + }, + _ => Ok(format!("unknown vault command {what}")), + } + }; + match result { + Ok(note) if !note.is_empty() => self.selftest_log(¬e), + Ok(_) => {}, + Err(error) => self.selftest_log(&format!("vault {what}: {error}")), + } + }, "prompt" => { let remember = rest.contains("remember"); let answer = if rest.starts_with("allow") { crate::actions::PromptAnswer::Allow { remember } } else { crate::actions::PromptAnswer::Deny { remember } }; @@ -708,6 +735,7 @@ impl App { "bookmarks": self.shared.bookmarks.borrow().all().len(), "logins": self.shared.vault.borrow().contents.logins.len(), "vault_locked": self.shared.vault.borrow().locked(), + "vault_mode": format!("{:?}", self.shared.vault.borrow().mode()), "apps": self.shared.apps.borrow().items.len(), "dlm": format!("{:?}", self.shared.dlm_status.borrow()), "discord": self.shared.presence_status.borrow().clone(), diff --git a/tests/smoke/pages/login.html b/tests/smoke/pages/login.html new file mode 100644 index 0000000..aeecabc --- /dev/null +++ b/tests/smoke/pages/login.html @@ -0,0 +1,9 @@ + + +Login probe + +
+

+

+

+
diff --git a/tests/smoke/pages/vault-import.csv b/tests/smoke/pages/vault-import.csv new file mode 100644 index 0000000..3f1298c --- /dev/null +++ b/tests/smoke/pages/vault-import.csv @@ -0,0 +1,4 @@ +name,url,username,password,note +shop,https://shop.example/login,bob,Tr0ub4dor&3,first +mail,https://mail.example/,carol,correct horse battery, +bad,not a url,dave,x, diff --git a/tests/smoke/site-memory-restart.txt b/tests/smoke/site-memory-restart.txt index 02c8f9c..4594039 100644 --- a/tests/smoke/site-memory-restart.txt +++ b/tests/smoke/site-memory-restart.txt @@ -25,6 +25,38 @@ js pop() wait 2 status checked expect /tab_count 2 +expect /active/prompts 1 +# That one prompt is the 'pop-up blocked' notice; dismiss it. +prompt deny +# Prompt answers: allow + remember is stored; deny without remember is not (it asks again after a reload). +perm 127.0.0.1 notifications default +cmd reload +waitload +waitfor 20 window.res && window.res.img !== undefined +js notif() +wait 3 +status ask-again +expect /active/prompts 1 +prompt allow remember +waitfor 10 res.notif === 'granted' +status allowed +expect /permissions/127.0.0.1/notifications allow +perm 127.0.0.1 notifications default +cmd reload +waitload +waitfor 20 window.res && window.res.img !== undefined +js notif() +wait 3 +prompt deny +waitfor 10 res.notif === 'denied' +cmd reload +waitload +waitfor 20 window.res && window.res.img !== undefined +js notif() +wait 3 +status asked-third +expect /active/prompts 1 +prompt deny remember # Reset the images answer: the picture loads again, and the change is stored. perm 127.0.0.1 images default cmd reload diff --git a/tests/smoke/stores-vault-check.sh b/tests/smoke/stores-vault-check.sh new file mode 100755 index 0000000..49cc838 --- /dev/null +++ b/tests/smoke/stores-vault-check.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# After tests/smoke/stores-vault.txt: the vault file holds no plain text and the device key is gone (master mode); the +# CSV export has the login. Usage: tests/smoke/stores-vault-check.sh +set -eu +out=${1:?outdir} +data=$out/home/.local/share/nacre-servo/Default +fail=0 +for secret in s3cret-Pa55 alice 127.0.0.1 'Tr0ub4dor' carol; do + if grep -q -- "$secret" "$data/vault.json"; then echo "FAIL: vault.json contains '$secret'"; fail=1; fi +done +if [ -e "$data/vault.key" ]; then echo "FAIL: vault.key still exists in master mode"; fail=1; fi +grep -q 's3cret-Pa55' "$out/home/export.csv" || { echo "FAIL: export.csv lacks the login"; fail=1; } +[ "$(stat -c %a "$data/vault.json")" = 600 ] || { echo "FAIL: vault.json mode is not 600"; fail=1; } +[ $fail = 0 ] && echo "vault files ok" +exit $fail diff --git a/tests/smoke/stores-vault.txt b/tests/smoke/stores-vault.txt new file mode 100644 index 0000000..ed09d60 --- /dev/null +++ b/tests/smoke/stores-vault.txt @@ -0,0 +1,64 @@ +# Stores pass (S008): the password vault. Save a login from a local form, autofill it, master password lock/unlock, +# CSV export and import. Offline. Start the page server first, then run hidden and check the files afterwards: +# python3 -m http.server 8768 --bind 127.0.0.1 --directory tests/smoke/pages & +# tools/smoke.sh tests/smoke/stores-vault.txt then tests/smoke/stores-vault-check.sh +wait 3 +open http://127.0.0.1:8768/login.html +waitload +waitfor 10 document.getElementById('pass') !== null +locate #user +wait 1 +click @ +pagetype alice +locate #pass +wait 1 +click @ +pagetype s3cret-Pa55 +locate #go +wait 1 +click @ +wait 2 +status save-prompt +expect /active/prompts 1 +prompt allow +status saved +expect /logins 1 +# Autofill: with one saved login the form fills itself. +open http://127.0.0.1:8768/login.html +waitload +waitfor 10 document.getElementById('pass').value === 's3cret-Pa55' +assert document.getElementById('user').value === 'alice' +shot autofilled +# Export, master password, lock. +vault export @HOME@/export.csv +vault master hunter2 +status master +expect /vault_mode "Master" +vault lock +status locked +expect /vault_locked true +expect /logins 0 +open http://127.0.0.1:8768/login.html +waitload +wait 2 +assert document.getElementById('pass').value === '' +vault unlock wrong-password +status wrong +expect /vault_locked true +vault unlock hunter2 +status unlocked +expect /vault_locked false +expect /logins 1 +open http://127.0.0.1:8768/login.html +waitload +waitfor 10 document.getElementById('pass').value === 's3cret-Pa55' +# Import: the same file again adds nothing; a Chrome-format file adds two and skips the bad row. +vault import @HOME@/export.csv +vault import @PAGESDIR@/vault-import.csv +status imported +expect /logins 3 +page nacre://passwords +wait 1 +shot passwords-page +status done +quit