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(()) }