aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/tests/pws.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-26 20:05:47 +0000
committerDaniel Mueller <deso@posteo.net>2019-01-26 23:35:10 -0800
commitca45fd413e7c8af212a693d94dba0038d055bff8 (patch)
treebfe90d1c1581df96ed393e13648f6fc6452affcd /nitrocli/src/tests/pws.rs
parent2809a90f3a790e3fc0a81ddac58f6de56e783cf2 (diff)
downloadnitrocli-ca45fd413e7c8af212a693d94dba0038d055bff8.tar.gz
nitrocli-ca45fd413e7c8af212a693d94dba0038d055bff8.tar.bz2
Add test for pws get after factory reset
The factory reset only clears the slot status. The slot content is overwritten with random data. Therefore accessing a PWS slot after a factory reset returns garbage data. We fixed this by always querying the status before accessing the PWS. This patch adds a corresponding test case.
Diffstat (limited to 'nitrocli/src/tests/pws.rs')
-rw-r--r--nitrocli/src/tests/pws.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/nitrocli/src/tests/pws.rs b/nitrocli/src/tests/pws.rs
index 2a9a8ef..5d0f245 100644
--- a/nitrocli/src/tests/pws.rs
+++ b/nitrocli/src/tests/pws.rs
@@ -83,6 +83,29 @@ fn set_get(device: nitrokey::DeviceWrapper) -> crate::Result<()> {
}
#[test_device]
+fn set_reset_get(device: nitrokey::DeviceWrapper) -> crate::Result<()> {
+ const NAME: &str = "some/svc";
+ const LOGIN: &str = "a\\user";
+ const PASSWORD: &str = "!@&-)*(&+%^@";
+
+ let mut ncli = Nitrocli::with_dev(device);
+ let _ = ncli.handle(&["pws", "set", "2", &NAME, &LOGIN, &PASSWORD])?;
+
+ let out = ncli.handle(&["reset"])?;
+ assert_eq!(out, "");
+
+ let res = ncli.handle(&["pws", "get", "2"]);
+ assert_eq!(
+ res.unwrap_cmd_err(),
+ (
+ Some("Could not access PWS slot"),
+ nitrokey::CommandError::SlotNotProgrammed
+ )
+ );
+ Ok(())
+}
+
+#[test_device]
fn clear(device: nitrokey::DeviceWrapper) -> crate::Result<()> {
let mut ncli = Nitrocli::with_dev(device);
let _ = ncli.handle(&["pws", "set", "10", "clear-test", "some-login", "abcdef"])?;