From a7d9b21ad10c86aa5197893f3de21a097d1a63e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Mon, 5 Dec 2022 15:12:36 +0100 Subject: [PATCH] Add key generation test --- tests/card/mod.rs | 6 ++++++ tests/pivy.rs | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/tests/card/mod.rs b/tests/card/mod.rs index 2ef9c46..2f23146 100644 --- a/tests/card/mod.rs +++ b/tests/card/mod.rs @@ -6,7 +6,13 @@ use piv_authenticator::{vpicc::VirtualCard, Authenticator}; use std::{sync::mpsc, thread::sleep, time::Duration}; use stoppable_thread::spawn; +use std::sync::Mutex; + +static VSC_MUTEX: Mutex<()> = Mutex::new(()); + pub fn with_vsc R, R>(f: F) -> R { + let _lock = VSC_MUTEX.lock().unwrap(); + let mut vpicc = vpicc::connect().expect("failed to connect to vpcd"); let (tx, rx) = mpsc::channel(); diff --git a/tests/pivy.rs b/tests/pivy.rs index c5dc1fa..1370e57 100644 --- a/tests/pivy.rs +++ b/tests/pivy.rs @@ -22,3 +22,18 @@ fn list() { assert_eq!(p.wait().unwrap(), WaitStatus::Exited(p.pid(), 0)); }); } + +#[test] +fn generate() { + with_vsc(|| { + let mut p = spawn("pivy-tool -A 3des -K 010203040506070801020304050607080102030405060708 generate 9A -a eccp256 -P 123456").unwrap(); + p.check("Touch button confirmation may be required.") + .unwrap(); + p.check(Regex( + "^ecdsa-sha2-nistp256 (?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)? PIV_slot_9A@[A-F0-9]{20}$", + )) + .unwrap(); + p.check(Eof).unwrap(); + assert_eq!(p.wait().unwrap(), WaitStatus::Exited(p.pid(), 0)); + }); +}