summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Kreutz <mail@skreutz.com>2022-05-26 22:26:34 +0200
committerStefan Kreutz <mail@skreutz.com>2022-05-26 22:26:34 +0200
commit9994ec96fa65f8c9f177fef5522a20d9a4b41547 (patch)
tree45f2c88ec23184459952e14e54e1e823bd7534cb
parentc3208b30771c2378ec48e2a2d10338bd3ad90137 (diff)
downloadwpa-psk-9994ec96fa65f8c9f177fef5522a20d9a4b41547.tar
Test command-line interface
-rw-r--r--Cargo.lock107
-rw-r--r--Cargo.toml3
-rw-r--r--tests/cli.rs34
3 files changed, 144 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c6e97e5..1415e60 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,20 @@
version = 3
[[package]]
+name = "assert_cmd"
+version = "2.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "93ae1ddd39efd67689deb1979d80bad3bf7f2b09c6e6117c8d1f2443b5e2f83e"
+dependencies = [
+ "bstr",
+ "doc-comment",
+ "predicates",
+ "predicates-core",
+ "predicates-tree",
+ "wait-timeout",
+]
+
+[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -35,6 +49,17 @@ dependencies = [
]
[[package]]
+name = "bstr"
+version = "0.2.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
+dependencies = [
+ "lazy_static",
+ "memchr",
+ "regex-automata",
+]
+
+[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -99,6 +124,12 @@ dependencies = [
]
[[package]]
+name = "difflib"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
+
+[[package]]
name = "digest"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -110,6 +141,18 @@ dependencies = [
]
[[package]]
+name = "doc-comment"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
+
+[[package]]
+name = "either"
+version = "1.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
+
+[[package]]
name = "generic-array"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -160,6 +203,15 @@ dependencies = [
]
[[package]]
+name = "itertools"
+version = "0.10.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
+dependencies = [
+ "either",
+]
+
+[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -172,6 +224,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
[[package]]
+name = "memchr"
+version = "2.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
+
+[[package]]
name = "os_str_bytes"
version = "6.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -187,6 +245,33 @@ dependencies = [
]
[[package]]
+name = "predicates"
+version = "2.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a5aab5be6e4732b473071984b3164dbbfb7a3674d30ea5ff44410b6bcd960c3c"
+dependencies = [
+ "difflib",
+ "itertools",
+ "predicates-core",
+]
+
+[[package]]
+name = "predicates-core"
+version = "1.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da1c2388b1513e1b605fcec39a95e0a9e8ef088f71443ef37099fa9ae6673fcb"
+
+[[package]]
+name = "predicates-tree"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4d86de6de25020a36c6d3643a86d9a6a9f552107c0559c60ea03551b5e16c032"
+dependencies = [
+ "predicates-core",
+ "termtree",
+]
+
+[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -229,6 +314,12 @@ dependencies = [
]
[[package]]
+name = "regex-automata"
+version = "0.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
+
+[[package]]
name = "sha-1"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -272,6 +363,12 @@ dependencies = [
]
[[package]]
+name = "termtree"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b"
+
+[[package]]
name = "textwrap"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -296,6 +393,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
+name = "wait-timeout"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
+dependencies = [
+ "libc",
+]
+
+[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -330,6 +436,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
name = "wpa-psk"
version = "0.1.5"
dependencies = [
+ "assert_cmd",
"clap",
"hmac",
"pbkdf2",
diff --git a/Cargo.toml b/Cargo.toml
index 6b7f39b..6480261 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,3 +18,6 @@ pbkdf2 = { version = "0.11.0", default-features = false }
hmac = { version = "0.12.1", default-features = false }
sha-1 = { version = "0.10.0", default-features = false }
clap = { version = "3.1.18", features = ["derive"] }
+
+[dev-dependencies]
+assert_cmd = "2.0.4"
diff --git a/tests/cli.rs b/tests/cli.rs
new file mode 100644
index 0000000..47fab8d
--- /dev/null
+++ b/tests/cli.rs
@@ -0,0 +1,34 @@
+use std::process::Command;
+
+use assert_cmd::prelude::*;
+
+#[test]
+fn valid() {
+ let mut cmd = Command::cargo_bin("wpa-psk").unwrap();
+ cmd.arg("home")
+ .arg("0123-4567-89")
+ .assert()
+ .success()
+ .stdout("0x150c047b6fad724512a17fa431687048ee503d14c1ea87681d4f241beb04f5ee\n");
+}
+
+#[test]
+fn passphrase_too_short() {
+ let mut cmd = Command::cargo_bin("wpa-psk").unwrap();
+ cmd.arg("bar")
+ .arg("2short")
+ .assert()
+ .failure()
+ .stderr("passphrase must have at least 8 bytes\n");
+}
+
+#[test]
+fn force() {
+ let mut cmd = Command::cargo_bin("wpa-psk").unwrap();
+ cmd.arg("--force")
+ .arg("bar")
+ .arg("2short")
+ .assert()
+ .success()
+ .stdout("0xcb5de4e4d23b2ab0bf5b9ba0fe8132c1e2af3bb52298ec801af8ad520cea3437\n");
+}
Generated by cgit. See skreutz.com for my tech blog and contact information.