# 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
