Skip to content

Commit

Permalink
Add test for pws get after factory reset
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
robinkrahl authored and d-e-s-o committed Jan 27, 2019
1 parent 2809a90 commit ca45fd4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions nitrocli/src/tests/pws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ fn set_get(device: nitrokey::DeviceWrapper) -> crate::Result<()> {
Ok(())
}

#[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);
Expand Down

0 comments on commit ca45fd4

Please sign in to comment.