From ca45fd413e7c8af212a693d94dba0038d055bff8 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sat, 26 Jan 2019 20:05:47 +0000 Subject: 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. --- nitrocli/src/tests/pws.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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 @@ -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); -- cgit v1.2.3