From ecb044bb3df60190b05e2190fb10bd2df2d51856 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 19 Mar 2021 17:37:32 +0900 Subject: [PATCH] Fix tests for Gnuk emulation (skip test with no KDF setup). Signed-off-by: NIIBE Yutaka --- tests/openpgp_card.py | 1 + tests/skip_if_emulation.py | 6 ++++++ tests/skip_if_gnuk.py | 6 ++++++ tests/test_001_personalize_card.py | 1 + tests/test_002_personalize_reset.py | 1 + tests/test_003_remove_keys.py | 1 + tests/test_004_reset_pw3.py | 1 + tests/test_005_personalize_admin_less.py | 1 + tests/test_006_pso.py | 5 +++-- tests/test_009_keygen.py | 1 + tests/test_021_personalize_admin_less.py | 6 +++++- 11 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tests/skip_if_emulation.py create mode 100644 tests/skip_if_gnuk.py diff --git a/tests/openpgp_card.py b/tests/openpgp_card.py index 5db9244..b51c26f 100644 --- a/tests/openpgp_card.py +++ b/tests/openpgp_card.py @@ -60,6 +60,7 @@ class OpenPGP_Card(object): self.__kdf_salt_reset = None self.__kdf_salt_admin = None self.is_gnuk = (reader.get_string(2) == "Gnuk Token") + self.is_emulated_gnuk = (reader.get_string(3)[-8:] == "EMULATED") def configure_with_kdf(self): kdf_data = self.cmd_get_data(0x00, 0xf9) diff --git a/tests/skip_if_emulation.py b/tests/skip_if_emulation.py new file mode 100644 index 0000000..a77d968 --- /dev/null +++ b/tests/skip_if_emulation.py @@ -0,0 +1,6 @@ +import pytest + +@pytest.fixture(scope="module",autouse=True) +def check_emulation(card): + if card.is_emulated_gnuk: + pytest.skip("Emulation requires KDF setup", allow_module_level=True) diff --git a/tests/skip_if_gnuk.py b/tests/skip_if_gnuk.py new file mode 100644 index 0000000..fbc0d45 --- /dev/null +++ b/tests/skip_if_gnuk.py @@ -0,0 +1,6 @@ +import pytest + +@pytest.fixture(scope="module",autouse=True) +def check_gnuk(card): + if card.is_gnuk: + pytest.skip("Gnuk has no support for those features", allow_module_level=True) diff --git a/tests/test_001_personalize_card.py b/tests/test_001_personalize_card.py index 4053172..1e1f78e 100644 --- a/tests/test_001_personalize_card.py +++ b/tests/test_001_personalize_card.py @@ -1 +1,2 @@ +from skip_if_emulation import * from card_test_personalize_card import * diff --git a/tests/test_002_personalize_reset.py b/tests/test_002_personalize_reset.py index dfacdeb..55b71b9 100644 --- a/tests/test_002_personalize_reset.py +++ b/tests/test_002_personalize_reset.py @@ -1 +1,2 @@ +from skip_if_emulation import * from card_test_personalize_reset import * diff --git a/tests/test_003_remove_keys.py b/tests/test_003_remove_keys.py index bcd8313..c625168 100644 --- a/tests/test_003_remove_keys.py +++ b/tests/test_003_remove_keys.py @@ -1 +1,2 @@ +from skip_if_emulation import * from card_test_remove_keys import * diff --git a/tests/test_004_reset_pw3.py b/tests/test_004_reset_pw3.py index dc43309..eb69132 100644 --- a/tests/test_004_reset_pw3.py +++ b/tests/test_004_reset_pw3.py @@ -1 +1,2 @@ +from skip_if_emulation import * from card_test_reset_pw3 import * diff --git a/tests/test_005_personalize_admin_less.py b/tests/test_005_personalize_admin_less.py index 3f86af6..d249207 100644 --- a/tests/test_005_personalize_admin_less.py +++ b/tests/test_005_personalize_admin_less.py @@ -20,6 +20,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ +from skip_if_emulation import * from skip_gnuk_only_tests import * from card_test_personalize_admin_less import * diff --git a/tests/test_006_pso.py b/tests/test_006_pso.py index b8bc24b..6ee2ab5 100644 --- a/tests/test_006_pso.py +++ b/tests/test_006_pso.py @@ -1,8 +1,9 @@ +from skip_if_gnuk import * +from card_test_ed25519 import * +from card_test_x25519 import * from card_test_ansix9p256r1 import * from card_test_ansix9p384r1 import * from card_test_ansix9p512r1 import * from card_test_brainpoolp256r1 import * from card_test_brainpoolp384r1 import * from card_test_brainpoolp512r1 import * -from card_test_ed25519 import * -from card_test_x25519 import * diff --git a/tests/test_009_keygen.py b/tests/test_009_keygen.py index 36fb39f..a9c5281 100644 --- a/tests/test_009_keygen.py +++ b/tests/test_009_keygen.py @@ -20,5 +20,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ +from skip_if_emulation import * from card_test_keygen import * from card_test_remove_keys import * diff --git a/tests/test_021_personalize_admin_less.py b/tests/test_021_personalize_admin_less.py index 317b572..a796c6c 100644 --- a/tests/test_021_personalize_admin_less.py +++ b/tests/test_021_personalize_admin_less.py @@ -1 +1,5 @@ -from test_005_personalize_admin_less import * +from skip_gnuk_only_tests import * +from card_test_personalize_admin_less import * +from card_test_personalize_reset import * +from card_test_remove_keys import * +from card_test_reset_pw3 import *