S008: vault smoke (save, autofill, master lock, csv), permission prompt answers

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-12 11:31:19 -06:00
commit b54d1a828e
7 changed files with 154 additions and 2 deletions

View file

@ -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

View file

@ -12,6 +12,7 @@
//! set <json pointer> <json> change a setting, e.g. `set /privacy/https_only true`
//! perm <host> <kind> 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 <pw> | lock | unlock <pw> | remove_master | export <file> | import <file> the password vault
//! flyout <name> main, downloads, shield, vpn, media, siteinfo, profiles, apps, qr, tabmenu, back,
//! bookmark (edit the current page's bookmark), none
//! type <text> 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(&note),
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(),

View file

@ -0,0 +1,9 @@
<!doctype html>
<meta charset="utf-8">
<title>Login probe</title>
<!-- tests/smoke/stores-vault.txt: a plain login form; submitting only reloads the page with ?sent. -->
<form id="f" onsubmit="setTimeout(() => { location = 'login.html?sent'; }, 50); return false;" style="font: 20px sans-serif; margin: 40px">
<p><input id="user" name="username" autocomplete="username" size="24"></p>
<p><input id="pass" name="password" type="password" autocomplete="current-password" size="24"></p>
<p><button id="go" type="submit">Sign in</button></p>
</form>

View file

@ -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,
1 name url username password note
2 shop https://shop.example/login bob Tr0ub4dor&3 first
3 mail https://mail.example/ carol correct horse battery
4 bad not a url dave x

View file

@ -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

View file

@ -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 <outdir>
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

View file

@ -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 <outdir> then tests/smoke/stores-vault-check.sh <outdir>
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