From e6d89a69521db96e27d65d8284acfa81f0ff4b2d Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Mon, 27 May 2019 09:30:46 -0700 Subject: Rename storage command to encrypted This change is the last step in the process of restructuring the storage command. In particular, now that functionality pertaining hidden volumes has been moved out into a dedicated top-level command, it renames said command to encrypted, because dealing with the encrypted volume is the only functionality it provides. --- nitrocli/src/tests/encrypted.rs | 90 +++++++++++++++++++++++++++++++++++++++++ nitrocli/src/tests/lock.rs | 2 +- nitrocli/src/tests/mod.rs | 2 +- nitrocli/src/tests/storage.rs | 90 ----------------------------------------- 4 files changed, 92 insertions(+), 92 deletions(-) create mode 100644 nitrocli/src/tests/encrypted.rs delete mode 100644 nitrocli/src/tests/storage.rs (limited to 'nitrocli/src/tests') diff --git a/nitrocli/src/tests/encrypted.rs b/nitrocli/src/tests/encrypted.rs new file mode 100644 index 0000000..8aef864 --- /dev/null +++ b/nitrocli/src/tests/encrypted.rs @@ -0,0 +1,90 @@ +// encrypted.rs + +// ************************************************************************* +// * Copyright (C) 2019 Daniel Mueller (deso@posteo.net) * +// * * +// * This program is free software: you can redistribute it and/or modify * +// * it under the terms of the GNU General Public License as published by * +// * the Free Software Foundation, either version 3 of the License, or * +// * (at your option) any later version. * +// * * +// * This program is distributed in the hope that it will be useful, * +// * but WITHOUT ANY WARRANTY; without even the implied warranty of * +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +// * GNU General Public License for more details. * +// * * +// * You should have received a copy of the GNU General Public License * +// * along with this program. If not, see . * +// ************************************************************************* + +use super::*; + +#[test_device] +fn status_open_close(device: nitrokey::Storage) -> crate::Result<()> { + fn make_re(open: Option) -> regex::Regex { + let encrypted = match open { + Some(open) => { + if open { + "active" + } else { + "(read-only|inactive)" + } + } + None => "(read-only|active|inactive)", + }; + let re = format!( + r#" + volumes: + unencrypted: (read-only|active|inactive) + encrypted: {} + hidden: (read-only|active|inactive) +$"#, + encrypted + ); + regex::Regex::new(&re).unwrap() + } + + let mut ncli = Nitrocli::with_dev(device); + let out = ncli.handle(&["status"])?; + assert!(make_re(None).is_match(&out), out); + + let _ = ncli.handle(&["encrypted", "open"])?; + let out = ncli.handle(&["status"])?; + assert!(make_re(Some(true)).is_match(&out), out); + + let _ = ncli.handle(&["encrypted", "close"])?; + let out = ncli.handle(&["status"])?; + assert!(make_re(Some(false)).is_match(&out), out); + + Ok(()) +} + +#[test_device] +fn encrypted_open_on_pro(device: nitrokey::Pro) { + let res = Nitrocli::with_dev(device).handle(&["encrypted", "open"]); + assert_eq!( + res.unwrap_str_err(), + "This command is only available on the Nitrokey Storage", + ); +} + +#[test_device] +fn encrypted_open_close(device: nitrokey::Storage) -> crate::Result<()> { + let mut ncli = Nitrocli::with_dev(device); + let out = ncli.handle(&["encrypted", "open"])?; + assert!(out.is_empty()); + + let device = nitrokey::Storage::connect()?; + assert!(device.get_status()?.encrypted_volume.active); + assert!(!device.get_status()?.hidden_volume.active); + drop(device); + + let out = ncli.handle(&["encrypted", "close"])?; + assert!(out.is_empty()); + + let device = nitrokey::Storage::connect()?; + assert!(!device.get_status()?.encrypted_volume.active); + assert!(!device.get_status()?.hidden_volume.active); + + Ok(()) +} diff --git a/nitrocli/src/tests/lock.rs b/nitrocli/src/tests/lock.rs index 1993350..d23d2ae 100644 --- a/nitrocli/src/tests/lock.rs +++ b/nitrocli/src/tests/lock.rs @@ -31,7 +31,7 @@ fn lock_pro(device: nitrokey::Pro) -> crate::Result<()> { #[test_device] fn lock_storage(device: nitrokey::Storage) -> crate::Result<()> { let mut ncli = Nitrocli::with_dev(device); - let _ = ncli.handle(&["storage", "open"])?; + let _ = ncli.handle(&["encrypted", "open"])?; let out = ncli.handle(&["lock"])?; assert!(out.is_empty()); diff --git a/nitrocli/src/tests/mod.rs b/nitrocli/src/tests/mod.rs index 2d6f93c..70a3d20 100644 --- a/nitrocli/src/tests/mod.rs +++ b/nitrocli/src/tests/mod.rs @@ -37,6 +37,7 @@ const NITROKEY_DEFAULT_USER_PIN: &str = "123456"; fn dummy() {} mod config; +mod encrypted; mod hidden; mod lock; mod otp; @@ -45,7 +46,6 @@ mod pws; mod reset; mod run; mod status; -mod storage; /// A trait simplifying checking for expected errors. pub trait UnwrapError { diff --git a/nitrocli/src/tests/storage.rs b/nitrocli/src/tests/storage.rs deleted file mode 100644 index a1c6ecf..0000000 --- a/nitrocli/src/tests/storage.rs +++ /dev/null @@ -1,90 +0,0 @@ -// storage.rs - -// ************************************************************************* -// * Copyright (C) 2019 Daniel Mueller (deso@posteo.net) * -// * * -// * This program is free software: you can redistribute it and/or modify * -// * it under the terms of the GNU General Public License as published by * -// * the Free Software Foundation, either version 3 of the License, or * -// * (at your option) any later version. * -// * * -// * This program is distributed in the hope that it will be useful, * -// * but WITHOUT ANY WARRANTY; without even the implied warranty of * -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -// * GNU General Public License for more details. * -// * * -// * You should have received a copy of the GNU General Public License * -// * along with this program. If not, see . * -// ************************************************************************* - -use super::*; - -#[test_device] -fn status_open_close(device: nitrokey::Storage) -> crate::Result<()> { - fn make_re(open: Option) -> regex::Regex { - let encrypted = match open { - Some(open) => { - if open { - "active" - } else { - "(read-only|inactive)" - } - } - None => "(read-only|active|inactive)", - }; - let re = format!( - r#" - volumes: - unencrypted: (read-only|active|inactive) - encrypted: {} - hidden: (read-only|active|inactive) -$"#, - encrypted - ); - regex::Regex::new(&re).unwrap() - } - - let mut ncli = Nitrocli::with_dev(device); - let out = ncli.handle(&["status"])?; - assert!(make_re(None).is_match(&out), out); - - let _ = ncli.handle(&["storage", "open"])?; - let out = ncli.handle(&["status"])?; - assert!(make_re(Some(true)).is_match(&out), out); - - let _ = ncli.handle(&["storage", "close"])?; - let out = ncli.handle(&["status"])?; - assert!(make_re(Some(false)).is_match(&out), out); - - Ok(()) -} - -#[test_device] -fn encrypted_open_on_pro(device: nitrokey::Pro) { - let res = Nitrocli::with_dev(device).handle(&["storage", "open"]); - assert_eq!( - res.unwrap_str_err(), - "This command is only available on the Nitrokey Storage", - ); -} - -#[test_device] -fn encrypted_open_close(device: nitrokey::Storage) -> crate::Result<()> { - let mut ncli = Nitrocli::with_dev(device); - let out = ncli.handle(&["storage", "open"])?; - assert!(out.is_empty()); - - let device = nitrokey::Storage::connect()?; - assert!(device.get_status()?.encrypted_volume.active); - assert!(!device.get_status()?.hidden_volume.active); - drop(device); - - let out = ncli.handle(&["storage", "close"])?; - assert!(out.is_empty()); - - let device = nitrokey::Storage::connect()?; - assert!(!device.get_status()?.encrypted_volume.active); - assert!(!device.get_status()?.hidden_volume.active); - - Ok(()) -} -- cgit v1.2.1