aboutsummaryrefslogtreecommitdiff
path: root/src/tests/pws.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2020-04-04 15:32:14 -0700
committerDaniel Mueller <deso@posteo.net>2020-04-04 15:32:14 -0700
commit681cc8882f7995407c33eb48730daaa901074460 (patch)
treec865f6c4a34e11af685889a09d95f3225e54a16c /src/tests/pws.rs
parentd0d9683df8398696147e7ee1fcffb2e4e957008c (diff)
downloadnitrocli-681cc8882f7995407c33eb48730daaa901074460.tar.gz
nitrocli-681cc8882f7995407c33eb48730daaa901074460.tar.bz2
Move nitrocli source code into repository root
Now that all vendored dependencies have been removed, this change moves the program's source code from the nitrocli/ directory into the root of the repository.
Diffstat (limited to 'src/tests/pws.rs')
-rw-r--r--src/tests/pws.rs123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/tests/pws.rs b/src/tests/pws.rs
new file mode 100644
index 0000000..651b2d5
--- /dev/null
+++ b/src/tests/pws.rs
@@ -0,0 +1,123 @@
+// pws.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 <http://www.gnu.org/licenses/>. *
+// *************************************************************************
+
+use super::*;
+
+#[test_device]
+fn set_invalid_slot(model: nitrokey::Model) {
+ let res = Nitrocli::with_model(model).handle(&["pws", "set", "100", "name", "login", "1234"]);
+
+ assert_eq!(
+ res.unwrap_lib_err(),
+ (
+ Some("Could not write PWS slot"),
+ nitrokey::LibraryError::InvalidSlot
+ )
+ );
+}
+
+#[test_device]
+fn status(model: nitrokey::Model) -> crate::Result<()> {
+ let re = regex::Regex::new(
+ r#"^slot\tname
+(\d+\t.+\n)+$"#,
+ )
+ .unwrap();
+
+ let mut ncli = Nitrocli::with_model(model);
+ // Make sure that we have at least something to display by ensuring
+ // that there are there is one slot programmed.
+ let _ = ncli.handle(&["pws", "set", "0", "the-name", "the-login", "123456"])?;
+
+ let out = ncli.handle(&["pws", "status"])?;
+ assert!(re.is_match(&out), out);
+ Ok(())
+}
+
+#[test_device]
+fn set_get(model: nitrokey::Model) -> crate::Result<()> {
+ const NAME: &str = "dropbox";
+ const LOGIN: &str = "d-e-s-o";
+ const PASSWORD: &str = "my-secret-password";
+
+ let mut ncli = Nitrocli::with_model(model);
+ let _ = ncli.handle(&["pws", "set", "1", &NAME, &LOGIN, &PASSWORD])?;
+
+ let out = ncli.handle(&["pws", "get", "1", "--quiet", "--name"])?;
+ assert_eq!(out, format!("{}\n", NAME));
+
+ let out = ncli.handle(&["pws", "get", "1", "--quiet", "--login"])?;
+ assert_eq!(out, format!("{}\n", LOGIN));
+
+ let out = ncli.handle(&["pws", "get", "1", "--quiet", "--password"])?;
+ assert_eq!(out, format!("{}\n", PASSWORD));
+
+ let out = ncli.handle(&["pws", "get", "1", "--quiet"])?;
+ assert_eq!(out, format!("{}\n{}\n{}\n", NAME, LOGIN, PASSWORD));
+
+ let out = ncli.handle(&["pws", "get", "1"])?;
+ assert_eq!(
+ out,
+ format!(
+ "name: {}\nlogin: {}\npassword: {}\n",
+ NAME, LOGIN, PASSWORD
+ ),
+ );
+ Ok(())
+}
+
+#[test_device]
+fn set_reset_get(model: nitrokey::Model) -> crate::Result<()> {
+ const NAME: &str = "some/svc";
+ const LOGIN: &str = "a\\user";
+ const PASSWORD: &str = "!@&-)*(&+%^@";
+
+ let mut ncli = Nitrocli::with_model(model);
+ 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(model: nitrokey::Model) -> crate::Result<()> {
+ let mut ncli = Nitrocli::with_model(model);
+ let _ = ncli.handle(&["pws", "set", "10", "clear-test", "some-login", "abcdef"])?;
+ let _ = ncli.handle(&["pws", "clear", "10"])?;
+ let res = ncli.handle(&["pws", "get", "10"]);
+
+ assert_eq!(
+ res.unwrap_cmd_err(),
+ (
+ Some("Could not access PWS slot"),
+ nitrokey::CommandError::SlotNotProgrammed
+ )
+ );
+ Ok(())
+}