2021-04-17 16:31:44 -04:00
|
|
|
#!/usr/bin/expect
|
|
|
|
|
2021-04-18 10:06:04 -04:00
|
|
|
source ./test.exp
|
2021-04-17 16:31:44 -04:00
|
|
|
|
2021-04-18 10:06:04 -04:00
|
|
|
set secret "foo\nbar"
|
|
|
|
set passphrase "asdasd"
|
|
|
|
|
|
|
|
test_label "Should fails to backup secret using secrets that do not match"
|
|
|
|
|
|
|
|
spawn qr-backup.sh
|
2021-04-17 16:31:44 -04:00
|
|
|
|
2021-04-18 10:06:04 -04:00
|
|
|
expect {
|
|
|
|
-re {Format USB flash drive \(y or n\)\?} {
|
|
|
|
test_send "n\r"
|
|
|
|
}
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
2021-04-18 10:06:04 -04:00
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {\[sudo\] password for pi:} {
|
|
|
|
test_send "$env(password)\r"
|
|
|
|
}
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
2021-04-18 10:06:04 -04:00
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {Please type secret and press enter, then ctrl\+d} {
|
|
|
|
test_send "$secret\r"
|
|
|
|
test_send "\x04"
|
|
|
|
}
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
2021-04-18 10:06:04 -04:00
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {Please type secret and press enter, then ctrl\+d \(again\)} {
|
|
|
|
test_send "foo\r"
|
|
|
|
test_send "\x04"
|
|
|
|
}
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
|
|
|
|
2021-04-18 10:06:04 -04:00
|
|
|
expect {
|
|
|
|
-re {Secrets do not match} {
|
|
|
|
test_ok
|
|
|
|
}
|
|
|
|
}
|
2021-04-17 16:31:44 -04:00
|
|
|
|
2021-04-18 10:06:04 -04:00
|
|
|
test_label "Should fails to backup secret using passphrases that do not match"
|
2021-04-17 16:31:44 -04:00
|
|
|
|
|
|
|
spawn qr-backup.sh
|
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {Format USB flash drive \(y or n\)\?} {
|
2021-04-18 10:06:04 -04:00
|
|
|
test_send "n\r"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {\[sudo\] password for pi:} {
|
2021-04-18 10:06:04 -04:00
|
|
|
test_send "$env(password)\r"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
2021-04-18 10:06:04 -04:00
|
|
|
-re {Please type secret and press enter, then ctrl\+d} {
|
|
|
|
test_send "$secret\r"
|
|
|
|
test_send "\x04"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
2021-04-18 10:06:04 -04:00
|
|
|
-re {Please type secret and press enter, then ctrl\+d \(again\)} {
|
|
|
|
test_send "$secret\r"
|
|
|
|
test_send "\x04"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
2021-04-18 10:06:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {Please type passphrase and press enter} {
|
|
|
|
test_send "$passphrase\r"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
2021-04-18 10:06:04 -04:00
|
|
|
-re {Please type passphrase and press enter \(again\)} {
|
|
|
|
test_send "foo\r"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
2021-04-18 10:06:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {Passphrases do not match} {
|
|
|
|
test_ok
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 13:43:55 -04:00
|
|
|
test_label "Should backup secret showing passphrase"
|
2021-04-18 10:06:04 -04:00
|
|
|
|
|
|
|
spawn qr-backup.sh
|
|
|
|
|
2021-04-17 16:31:44 -04:00
|
|
|
expect {
|
2021-04-18 10:06:04 -04:00
|
|
|
-re {Format USB flash drive \(y or n\)\?} {
|
2021-04-19 13:43:55 -04:00
|
|
|
test_send "n\r"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
2021-04-18 10:06:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {\[sudo\] password for pi:} {
|
|
|
|
test_send "$env(password)\r"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 10:06:04 -04:00
|
|
|
expect {
|
|
|
|
-re {Please type secret and press enter, then ctrl\+d} {
|
|
|
|
test_send "$secret\r"
|
|
|
|
test_send "\x04"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
2021-04-18 10:06:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {Please type secret and press enter, then ctrl\+d \(again\)} {
|
|
|
|
test_send "$secret\r"
|
|
|
|
test_send "\x04"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
2021-04-18 10:06:04 -04:00
|
|
|
-re {Please type passphrase and press enter} {
|
|
|
|
test_send "$passphrase\r"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
2021-04-18 10:06:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {Please type passphrase and press enter \(again\)} {
|
|
|
|
test_send "$passphrase\r"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
2021-04-18 10:06:04 -04:00
|
|
|
-re {Show passphrase \(y or n\)\?} {
|
|
|
|
test_send "y\r"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
2021-04-18 10:06:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
2021-04-17 16:31:44 -04:00
|
|
|
$passphrase
|
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
|
|
|
set short_hash $expect_out(1,string)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
2021-04-18 10:06:04 -04:00
|
|
|
test_send "n\r"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
2021-04-18 10:06:04 -04:00
|
|
|
-re {Done} {
|
|
|
|
test_ok
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 10:06:04 -04:00
|
|
|
test_label "Should restore secret"
|
2021-04-17 16:31:44 -04:00
|
|
|
|
|
|
|
spawn qr-restore.sh --images $short_hash.jpg
|
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {\[sudo\] password for pi:} {
|
2021-04-18 10:06:04 -04:00
|
|
|
test_send "$env(password)\r"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {Please type passphrase and press enter} {
|
2021-04-18 10:06:04 -04:00
|
|
|
test_send "$passphrase\r"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {Show secret \(y or n\)\?} {
|
2021-04-18 10:06:04 -04:00
|
|
|
test_send "y\r"
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect {
|
|
|
|
-re {Secret:\r\n((.|\r\n)+?)\r\nDone} {
|
|
|
|
set restored_secret $expect_out(1,string)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 13:43:55 -04:00
|
|
|
regsub -all {\033\[[0-9]*m(\017)?} $restored_secret {} restored_secret
|
2021-04-17 16:31:44 -04:00
|
|
|
regsub -all {\r} $restored_secret {} restored_secret
|
|
|
|
|
|
|
|
if { "$restored_secret" != "$secret" } {
|
2021-04-18 10:06:04 -04:00
|
|
|
test_failed
|
2021-04-17 16:31:44 -04:00
|
|
|
} else {
|
2021-04-18 10:06:04 -04:00
|
|
|
test_ok
|
2021-04-17 16:31:44 -04:00
|
|
|
}
|