From d3a103bc25e5f37a42a19515ad25e5a8e5995b36 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 16 Jan 2019 19:35:50 +0000 Subject: Make device::factory_reset test more robust MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The device::factory_reset test used to first change the PINs and then access the PWS and the OTP data. If for example the PWS access failed due to an problem with the AES key, the PINs were not reset. Now we perform the PWS and OTP access with the old PINs – which is okay as we do not want to test the PIN change but the factory reset. If these preparations fail, the tests is cancelled before the PINs are changed. --- tests/device.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/device.rs b/tests/device.rs index 9e2bba2..7dea000 100644 --- a/tests/device.rs +++ b/tests/device.rs @@ -260,6 +260,15 @@ fn unlock_user_pin(device: DeviceWrapper) { #[test_device] fn factory_reset(device: DeviceWrapper) { + let admin = device.authenticate_admin(ADMIN_PASSWORD).unwrap(); + let otp_data = OtpSlotData::new(1, "test", "0123468790", OtpMode::SixDigits); + assert_eq!(Ok(()), admin.write_totp_slot(otp_data, 30)); + + let device = admin.device(); + let pws = device.get_password_safe(USER_PASSWORD).unwrap(); + assert_eq!(Ok(()), pws.write_slot(0, "test", "testlogin", "testpw")); + drop(pws); + assert_eq!( Ok(()), device.change_user_pin(USER_PASSWORD, USER_NEW_PASSWORD) @@ -269,15 +278,6 @@ fn factory_reset(device: DeviceWrapper) { device.change_admin_pin(ADMIN_PASSWORD, ADMIN_NEW_PASSWORD) ); - let admin = device.authenticate_admin(ADMIN_NEW_PASSWORD).unwrap(); - let otp_data = OtpSlotData::new(1, "test", "0123468790", OtpMode::SixDigits); - assert_eq!(Ok(()), admin.write_totp_slot(otp_data, 30)); - - let device = admin.device(); - let pws = device.get_password_safe(USER_NEW_PASSWORD).unwrap(); - assert_eq!(Ok(()), pws.write_slot(0, "test", "testlogin", "testpw")); - drop(pws); - assert_eq!( Err(CommandError::WrongPassword), device.factory_reset(USER_NEW_PASSWORD) -- cgit v1.2.1