From 499e128b4e4301bdb5b203803eba394bd96412e4 Mon Sep 17 00:00:00 2001 From: Heiko Schaefer Date: Wed, 14 Jul 2021 00:06:30 +0200 Subject: [PATCH] Minimize the output data: assert data that is always expected - only return Status bytes that diverge between cards. Added a test that sets and checks name, lang, sex, url data. --- card-functionality/src/main.rs | 86 +++++++++++++++++++++++++--------- 1 file changed, 65 insertions(+), 21 deletions(-) diff --git a/card-functionality/src/main.rs b/card-functionality/src/main.rs index ec702e0..26f1de4 100644 --- a/card-functionality/src/main.rs +++ b/card-functionality/src/main.rs @@ -1,13 +1,12 @@ // SPDX-FileCopyrightText: 2021 Heiko Schaefer // SPDX-License-Identifier: MIT OR Apache-2.0 -use anyhow::{anyhow, Result}; -use std::env; +use anyhow::Result; +use std::collections::HashMap; use openpgp_card::apdu::PcscClient; use openpgp_card::card_app::CardApp; -use openpgp_card::CardClientBox; -use std::collections::HashMap; +use openpgp_card::{CardClientBox, Sex}; #[derive(Debug)] enum TestResult { @@ -17,43 +16,91 @@ enum TestResult { type TestOutput = Vec; -/// outputs: -/// - verify pw3 + pin -> Status +/// Sets name, lang, sex, url; then reads the fields from the card and +/// compares the values with the expected values. +/// +/// Returns an empty TestOutput, throws errors for unexpected Status codes +/// and for unequal field values. +fn test_set_user_data(ca: &mut CardApp) -> Result { + let res = ca.verify_pw3("12345678")?; + res.check_ok()?; + + // name + let res = ca.set_name("Bar< Status -/// - set name -> Status -/// - get name -> Text(name) -/// - verify pw1 + pin -> Status /// - verify pw1 (check) -> Status -/// - set name -> Status -/// - get name -> Text(name) fn test_verify(ca: &mut CardApp) -> Result { + // Steps: + // + // - try to set name without verify, assert result is not ok + // - verify pw3 + pin -> Status + // - verify pw3 (check) -> Status + // - set name -> Status + // - get name -> Text(name) + // - verify pw1 + pin -> Status + // - verify pw1 (check) -> Status + // - set name -> Status + // - get name -> Text(name) + let mut out = vec![]; + // try to set name without verify, assert result is not ok! + let res = ca.set_name("Notverified< Result<()> { - // Ident of the OpenPGP Card that will be used for tests. - let test_card_ident = - env::var("TEST_CARD_IDENT").expect("TEST_CARD_IDENT is not set"); - // list of card idents to runs the tests on let cards = vec![ "0006:16019180", // Yubikey 5 @@ -100,6 +143,7 @@ fn main() -> Result<()> { ]; let _verify_res = run_test(&cards, test_verify)?; + let _userdata_res = run_test(&cards, test_set_user_data)?; Ok(()) }