From 6388c78e4f6c47b3da92b793a754083a81e6ba2d Mon Sep 17 00:00:00 2001 From: Rustam Ismayilov Date: Fri, 21 Jun 2024 10:59:01 +0200 Subject: [PATCH] imgtool: Fix test paths Move tests from imgtool/keys to test/keys Move pre-generated files to test/assets folder Fix paths for tests to run from root directory Replace hardcoded paths with constants in tests Signed-off-by: Rustam Ismayilov Change-Id: I100e65609f31cefa1c17f20143bceb165862fa14 --- scripts/tests/{ => assets}/images/one.bin | 0 .../tests/{ => assets}/images/one_offset.hex | 0 .../images/signed/basic/ecdsa-p256.bin | Bin .../images/signed/basic/ecdsa-p384.bin | Bin .../images/signed/basic/ed25519.bin | Bin .../images/signed/basic/rsa-2048.bin | Bin .../images/signed/basic/rsa-3072.bin | Bin .../images/signed/basic/rsa-3072_invHash.bin | Bin .../images/signed/basic/rsa-3072_invMagic.bin | Bin .../signed/basic/rsa-3072_invTLVMagic.bin | Bin .../images/signed/customTLV/ecdsa-p256.bin | Bin .../images/signed/customTLV/ecdsa-p384.bin | Bin .../images/signed/customTLV/ed25519.bin | Bin .../images/signed/customTLV/rsa-2048.bin | Bin .../images/signed/customTLV/rsa-3072.bin | Bin .../signed/encryptedClear/ecdsa-p256.enc | Bin .../signed/encryptedClear/ecdsa-p384.enc | Bin .../images/signed/encryptedClear/ed25519.enc | Bin .../images/signed/encryptedClear/rsa-2048.enc | Bin .../images/signed/encryptedClear/rsa-3072.enc | Bin .../images/signed/hex/zero_hex-addr_0.hex | 0 .../images/signed/hex/zero_hex-addr_16.hex | 0 .../images/signed/hex/zero_hex-addr_35.hex | 0 .../images/signed/noKey/noKey256.bin | Bin .../images/signed/no_pad_sig_enc_16.bin | Bin .../images/signed/no_pad_sig_enc_16_inv.bin | Bin .../images/signed/pad/padNoEnc.bin | Bin .../images/signed/pad_2.3K_sig_enc_16_inv.bin | Bin .../images/signed/pad_sig_enc_16.bin | Bin .../images/signed/pad_sig_enc_16_inv.bin | Bin .../images/signed/pad_sig_enc_32.bin | Bin .../images/signed/pubKeyOnly/ecdsa-p256.bin | Bin .../images/signed/pubKeyOnly/ecdsa-p384.bin | Bin .../images/signed/pubKeyOnly/rsa-2048.bin | Bin .../images/signed/pubKeyOnly/rsa-3072.bin | Bin scripts/tests/{ => assets}/images/zero.bin | Bin scripts/tests/{ => assets}/images/zero.hex | 0 .../tests/{ => assets}/keys/ecdsa-p256.key | 0 .../{ => assets}/keys/ecdsa-p256_passwd.key | 0 .../tests/{ => assets}/keys/ecdsa-p384.key | 0 .../{ => assets}/keys/ecdsa-p384_passwd.key | 0 scripts/tests/{ => assets}/keys/ed25519.key | 0 .../{ => assets}/keys/ed25519_passwd.key | 0 .../keys/public/ecdsa-p256-pem.pub | 0 .../keys/public/ecdsa-p384-pem.pub | 0 .../{ => assets}/keys/public/rsa-2048-pem.pub | 0 .../{ => assets}/keys/public/rsa-3072-pem.pub | 0 .../{ => assets}/keys/public/x25519-pem.pub | 0 scripts/tests/{ => assets}/keys/rsa-2048.key | 0 .../{ => assets}/keys/rsa-2048_passwd.key | 0 scripts/tests/{ => assets}/keys/rsa-3072.key | 0 .../{ => assets}/keys/rsa-3072_passwd.key | 0 scripts/tests/{ => assets}/keys/x25519.key | 0 .../tests/{ => assets}/keys/x25519_passwd.key | 0 scripts/tests/constants.py | 4 +- scripts/{imgtool => tests}/keys/ecdsa_test.py | 0 .../{imgtool => tests}/keys/ed25519_test.py | 0 scripts/{imgtool => tests}/keys/rsa_test.py | 0 scripts/tests/test_dumpinfo.py | 4 +- scripts/tests/test_keys.py | 36 +++++++++--------- scripts/tests/test_sign.py | 32 ++++++++-------- scripts/tests/test_verify.py | 18 ++++----- 62 files changed, 46 insertions(+), 48 deletions(-) rename scripts/tests/{ => assets}/images/one.bin (100%) rename scripts/tests/{ => assets}/images/one_offset.hex (100%) rename scripts/tests/{ => assets}/images/signed/basic/ecdsa-p256.bin (100%) rename scripts/tests/{ => assets}/images/signed/basic/ecdsa-p384.bin (100%) rename scripts/tests/{ => assets}/images/signed/basic/ed25519.bin (100%) rename scripts/tests/{ => assets}/images/signed/basic/rsa-2048.bin (100%) rename scripts/tests/{ => assets}/images/signed/basic/rsa-3072.bin (100%) rename scripts/tests/{ => assets}/images/signed/basic/rsa-3072_invHash.bin (100%) rename scripts/tests/{ => assets}/images/signed/basic/rsa-3072_invMagic.bin (100%) rename scripts/tests/{ => assets}/images/signed/basic/rsa-3072_invTLVMagic.bin (100%) rename scripts/tests/{ => assets}/images/signed/customTLV/ecdsa-p256.bin (100%) rename scripts/tests/{ => assets}/images/signed/customTLV/ecdsa-p384.bin (100%) rename scripts/tests/{ => assets}/images/signed/customTLV/ed25519.bin (100%) rename scripts/tests/{ => assets}/images/signed/customTLV/rsa-2048.bin (100%) rename scripts/tests/{ => assets}/images/signed/customTLV/rsa-3072.bin (100%) rename scripts/tests/{ => assets}/images/signed/encryptedClear/ecdsa-p256.enc (100%) rename scripts/tests/{ => assets}/images/signed/encryptedClear/ecdsa-p384.enc (100%) rename scripts/tests/{ => assets}/images/signed/encryptedClear/ed25519.enc (100%) rename scripts/tests/{ => assets}/images/signed/encryptedClear/rsa-2048.enc (100%) rename scripts/tests/{ => assets}/images/signed/encryptedClear/rsa-3072.enc (100%) rename scripts/tests/{ => assets}/images/signed/hex/zero_hex-addr_0.hex (100%) rename scripts/tests/{ => assets}/images/signed/hex/zero_hex-addr_16.hex (100%) rename scripts/tests/{ => assets}/images/signed/hex/zero_hex-addr_35.hex (100%) rename scripts/tests/{ => assets}/images/signed/noKey/noKey256.bin (100%) rename scripts/tests/{ => assets}/images/signed/no_pad_sig_enc_16.bin (100%) rename scripts/tests/{ => assets}/images/signed/no_pad_sig_enc_16_inv.bin (100%) rename scripts/tests/{ => assets}/images/signed/pad/padNoEnc.bin (100%) rename scripts/tests/{ => assets}/images/signed/pad_2.3K_sig_enc_16_inv.bin (100%) rename scripts/tests/{ => assets}/images/signed/pad_sig_enc_16.bin (100%) rename scripts/tests/{ => assets}/images/signed/pad_sig_enc_16_inv.bin (100%) rename scripts/tests/{ => assets}/images/signed/pad_sig_enc_32.bin (100%) rename scripts/tests/{ => assets}/images/signed/pubKeyOnly/ecdsa-p256.bin (100%) rename scripts/tests/{ => assets}/images/signed/pubKeyOnly/ecdsa-p384.bin (100%) rename scripts/tests/{ => assets}/images/signed/pubKeyOnly/rsa-2048.bin (100%) rename scripts/tests/{ => assets}/images/signed/pubKeyOnly/rsa-3072.bin (100%) rename scripts/tests/{ => assets}/images/zero.bin (100%) rename scripts/tests/{ => assets}/images/zero.hex (100%) rename scripts/tests/{ => assets}/keys/ecdsa-p256.key (100%) rename scripts/tests/{ => assets}/keys/ecdsa-p256_passwd.key (100%) rename scripts/tests/{ => assets}/keys/ecdsa-p384.key (100%) rename scripts/tests/{ => assets}/keys/ecdsa-p384_passwd.key (100%) rename scripts/tests/{ => assets}/keys/ed25519.key (100%) rename scripts/tests/{ => assets}/keys/ed25519_passwd.key (100%) rename scripts/tests/{ => assets}/keys/public/ecdsa-p256-pem.pub (100%) rename scripts/tests/{ => assets}/keys/public/ecdsa-p384-pem.pub (100%) rename scripts/tests/{ => assets}/keys/public/rsa-2048-pem.pub (100%) rename scripts/tests/{ => assets}/keys/public/rsa-3072-pem.pub (100%) rename scripts/tests/{ => assets}/keys/public/x25519-pem.pub (100%) rename scripts/tests/{ => assets}/keys/rsa-2048.key (100%) rename scripts/tests/{ => assets}/keys/rsa-2048_passwd.key (100%) rename scripts/tests/{ => assets}/keys/rsa-3072.key (100%) rename scripts/tests/{ => assets}/keys/rsa-3072_passwd.key (100%) rename scripts/tests/{ => assets}/keys/x25519.key (100%) rename scripts/tests/{ => assets}/keys/x25519_passwd.key (100%) rename scripts/{imgtool => tests}/keys/ecdsa_test.py (100%) rename scripts/{imgtool => tests}/keys/ed25519_test.py (100%) rename scripts/{imgtool => tests}/keys/rsa_test.py (100%) diff --git a/scripts/tests/images/one.bin b/scripts/tests/assets/images/one.bin similarity index 100% rename from scripts/tests/images/one.bin rename to scripts/tests/assets/images/one.bin diff --git a/scripts/tests/images/one_offset.hex b/scripts/tests/assets/images/one_offset.hex similarity index 100% rename from scripts/tests/images/one_offset.hex rename to scripts/tests/assets/images/one_offset.hex diff --git a/scripts/tests/images/signed/basic/ecdsa-p256.bin b/scripts/tests/assets/images/signed/basic/ecdsa-p256.bin similarity index 100% rename from scripts/tests/images/signed/basic/ecdsa-p256.bin rename to scripts/tests/assets/images/signed/basic/ecdsa-p256.bin diff --git a/scripts/tests/images/signed/basic/ecdsa-p384.bin b/scripts/tests/assets/images/signed/basic/ecdsa-p384.bin similarity index 100% rename from scripts/tests/images/signed/basic/ecdsa-p384.bin rename to scripts/tests/assets/images/signed/basic/ecdsa-p384.bin diff --git a/scripts/tests/images/signed/basic/ed25519.bin b/scripts/tests/assets/images/signed/basic/ed25519.bin similarity index 100% rename from scripts/tests/images/signed/basic/ed25519.bin rename to scripts/tests/assets/images/signed/basic/ed25519.bin diff --git a/scripts/tests/images/signed/basic/rsa-2048.bin b/scripts/tests/assets/images/signed/basic/rsa-2048.bin similarity index 100% rename from scripts/tests/images/signed/basic/rsa-2048.bin rename to scripts/tests/assets/images/signed/basic/rsa-2048.bin diff --git a/scripts/tests/images/signed/basic/rsa-3072.bin b/scripts/tests/assets/images/signed/basic/rsa-3072.bin similarity index 100% rename from scripts/tests/images/signed/basic/rsa-3072.bin rename to scripts/tests/assets/images/signed/basic/rsa-3072.bin diff --git a/scripts/tests/images/signed/basic/rsa-3072_invHash.bin b/scripts/tests/assets/images/signed/basic/rsa-3072_invHash.bin similarity index 100% rename from scripts/tests/images/signed/basic/rsa-3072_invHash.bin rename to scripts/tests/assets/images/signed/basic/rsa-3072_invHash.bin diff --git a/scripts/tests/images/signed/basic/rsa-3072_invMagic.bin b/scripts/tests/assets/images/signed/basic/rsa-3072_invMagic.bin similarity index 100% rename from scripts/tests/images/signed/basic/rsa-3072_invMagic.bin rename to scripts/tests/assets/images/signed/basic/rsa-3072_invMagic.bin diff --git a/scripts/tests/images/signed/basic/rsa-3072_invTLVMagic.bin b/scripts/tests/assets/images/signed/basic/rsa-3072_invTLVMagic.bin similarity index 100% rename from scripts/tests/images/signed/basic/rsa-3072_invTLVMagic.bin rename to scripts/tests/assets/images/signed/basic/rsa-3072_invTLVMagic.bin diff --git a/scripts/tests/images/signed/customTLV/ecdsa-p256.bin b/scripts/tests/assets/images/signed/customTLV/ecdsa-p256.bin similarity index 100% rename from scripts/tests/images/signed/customTLV/ecdsa-p256.bin rename to scripts/tests/assets/images/signed/customTLV/ecdsa-p256.bin diff --git a/scripts/tests/images/signed/customTLV/ecdsa-p384.bin b/scripts/tests/assets/images/signed/customTLV/ecdsa-p384.bin similarity index 100% rename from scripts/tests/images/signed/customTLV/ecdsa-p384.bin rename to scripts/tests/assets/images/signed/customTLV/ecdsa-p384.bin diff --git a/scripts/tests/images/signed/customTLV/ed25519.bin b/scripts/tests/assets/images/signed/customTLV/ed25519.bin similarity index 100% rename from scripts/tests/images/signed/customTLV/ed25519.bin rename to scripts/tests/assets/images/signed/customTLV/ed25519.bin diff --git a/scripts/tests/images/signed/customTLV/rsa-2048.bin b/scripts/tests/assets/images/signed/customTLV/rsa-2048.bin similarity index 100% rename from scripts/tests/images/signed/customTLV/rsa-2048.bin rename to scripts/tests/assets/images/signed/customTLV/rsa-2048.bin diff --git a/scripts/tests/images/signed/customTLV/rsa-3072.bin b/scripts/tests/assets/images/signed/customTLV/rsa-3072.bin similarity index 100% rename from scripts/tests/images/signed/customTLV/rsa-3072.bin rename to scripts/tests/assets/images/signed/customTLV/rsa-3072.bin diff --git a/scripts/tests/images/signed/encryptedClear/ecdsa-p256.enc b/scripts/tests/assets/images/signed/encryptedClear/ecdsa-p256.enc similarity index 100% rename from scripts/tests/images/signed/encryptedClear/ecdsa-p256.enc rename to scripts/tests/assets/images/signed/encryptedClear/ecdsa-p256.enc diff --git a/scripts/tests/images/signed/encryptedClear/ecdsa-p384.enc b/scripts/tests/assets/images/signed/encryptedClear/ecdsa-p384.enc similarity index 100% rename from scripts/tests/images/signed/encryptedClear/ecdsa-p384.enc rename to scripts/tests/assets/images/signed/encryptedClear/ecdsa-p384.enc diff --git a/scripts/tests/images/signed/encryptedClear/ed25519.enc b/scripts/tests/assets/images/signed/encryptedClear/ed25519.enc similarity index 100% rename from scripts/tests/images/signed/encryptedClear/ed25519.enc rename to scripts/tests/assets/images/signed/encryptedClear/ed25519.enc diff --git a/scripts/tests/images/signed/encryptedClear/rsa-2048.enc b/scripts/tests/assets/images/signed/encryptedClear/rsa-2048.enc similarity index 100% rename from scripts/tests/images/signed/encryptedClear/rsa-2048.enc rename to scripts/tests/assets/images/signed/encryptedClear/rsa-2048.enc diff --git a/scripts/tests/images/signed/encryptedClear/rsa-3072.enc b/scripts/tests/assets/images/signed/encryptedClear/rsa-3072.enc similarity index 100% rename from scripts/tests/images/signed/encryptedClear/rsa-3072.enc rename to scripts/tests/assets/images/signed/encryptedClear/rsa-3072.enc diff --git a/scripts/tests/images/signed/hex/zero_hex-addr_0.hex b/scripts/tests/assets/images/signed/hex/zero_hex-addr_0.hex similarity index 100% rename from scripts/tests/images/signed/hex/zero_hex-addr_0.hex rename to scripts/tests/assets/images/signed/hex/zero_hex-addr_0.hex diff --git a/scripts/tests/images/signed/hex/zero_hex-addr_16.hex b/scripts/tests/assets/images/signed/hex/zero_hex-addr_16.hex similarity index 100% rename from scripts/tests/images/signed/hex/zero_hex-addr_16.hex rename to scripts/tests/assets/images/signed/hex/zero_hex-addr_16.hex diff --git a/scripts/tests/images/signed/hex/zero_hex-addr_35.hex b/scripts/tests/assets/images/signed/hex/zero_hex-addr_35.hex similarity index 100% rename from scripts/tests/images/signed/hex/zero_hex-addr_35.hex rename to scripts/tests/assets/images/signed/hex/zero_hex-addr_35.hex diff --git a/scripts/tests/images/signed/noKey/noKey256.bin b/scripts/tests/assets/images/signed/noKey/noKey256.bin similarity index 100% rename from scripts/tests/images/signed/noKey/noKey256.bin rename to scripts/tests/assets/images/signed/noKey/noKey256.bin diff --git a/scripts/tests/images/signed/no_pad_sig_enc_16.bin b/scripts/tests/assets/images/signed/no_pad_sig_enc_16.bin similarity index 100% rename from scripts/tests/images/signed/no_pad_sig_enc_16.bin rename to scripts/tests/assets/images/signed/no_pad_sig_enc_16.bin diff --git a/scripts/tests/images/signed/no_pad_sig_enc_16_inv.bin b/scripts/tests/assets/images/signed/no_pad_sig_enc_16_inv.bin similarity index 100% rename from scripts/tests/images/signed/no_pad_sig_enc_16_inv.bin rename to scripts/tests/assets/images/signed/no_pad_sig_enc_16_inv.bin diff --git a/scripts/tests/images/signed/pad/padNoEnc.bin b/scripts/tests/assets/images/signed/pad/padNoEnc.bin similarity index 100% rename from scripts/tests/images/signed/pad/padNoEnc.bin rename to scripts/tests/assets/images/signed/pad/padNoEnc.bin diff --git a/scripts/tests/images/signed/pad_2.3K_sig_enc_16_inv.bin b/scripts/tests/assets/images/signed/pad_2.3K_sig_enc_16_inv.bin similarity index 100% rename from scripts/tests/images/signed/pad_2.3K_sig_enc_16_inv.bin rename to scripts/tests/assets/images/signed/pad_2.3K_sig_enc_16_inv.bin diff --git a/scripts/tests/images/signed/pad_sig_enc_16.bin b/scripts/tests/assets/images/signed/pad_sig_enc_16.bin similarity index 100% rename from scripts/tests/images/signed/pad_sig_enc_16.bin rename to scripts/tests/assets/images/signed/pad_sig_enc_16.bin diff --git a/scripts/tests/images/signed/pad_sig_enc_16_inv.bin b/scripts/tests/assets/images/signed/pad_sig_enc_16_inv.bin similarity index 100% rename from scripts/tests/images/signed/pad_sig_enc_16_inv.bin rename to scripts/tests/assets/images/signed/pad_sig_enc_16_inv.bin diff --git a/scripts/tests/images/signed/pad_sig_enc_32.bin b/scripts/tests/assets/images/signed/pad_sig_enc_32.bin similarity index 100% rename from scripts/tests/images/signed/pad_sig_enc_32.bin rename to scripts/tests/assets/images/signed/pad_sig_enc_32.bin diff --git a/scripts/tests/images/signed/pubKeyOnly/ecdsa-p256.bin b/scripts/tests/assets/images/signed/pubKeyOnly/ecdsa-p256.bin similarity index 100% rename from scripts/tests/images/signed/pubKeyOnly/ecdsa-p256.bin rename to scripts/tests/assets/images/signed/pubKeyOnly/ecdsa-p256.bin diff --git a/scripts/tests/images/signed/pubKeyOnly/ecdsa-p384.bin b/scripts/tests/assets/images/signed/pubKeyOnly/ecdsa-p384.bin similarity index 100% rename from scripts/tests/images/signed/pubKeyOnly/ecdsa-p384.bin rename to scripts/tests/assets/images/signed/pubKeyOnly/ecdsa-p384.bin diff --git a/scripts/tests/images/signed/pubKeyOnly/rsa-2048.bin b/scripts/tests/assets/images/signed/pubKeyOnly/rsa-2048.bin similarity index 100% rename from scripts/tests/images/signed/pubKeyOnly/rsa-2048.bin rename to scripts/tests/assets/images/signed/pubKeyOnly/rsa-2048.bin diff --git a/scripts/tests/images/signed/pubKeyOnly/rsa-3072.bin b/scripts/tests/assets/images/signed/pubKeyOnly/rsa-3072.bin similarity index 100% rename from scripts/tests/images/signed/pubKeyOnly/rsa-3072.bin rename to scripts/tests/assets/images/signed/pubKeyOnly/rsa-3072.bin diff --git a/scripts/tests/images/zero.bin b/scripts/tests/assets/images/zero.bin similarity index 100% rename from scripts/tests/images/zero.bin rename to scripts/tests/assets/images/zero.bin diff --git a/scripts/tests/images/zero.hex b/scripts/tests/assets/images/zero.hex similarity index 100% rename from scripts/tests/images/zero.hex rename to scripts/tests/assets/images/zero.hex diff --git a/scripts/tests/keys/ecdsa-p256.key b/scripts/tests/assets/keys/ecdsa-p256.key similarity index 100% rename from scripts/tests/keys/ecdsa-p256.key rename to scripts/tests/assets/keys/ecdsa-p256.key diff --git a/scripts/tests/keys/ecdsa-p256_passwd.key b/scripts/tests/assets/keys/ecdsa-p256_passwd.key similarity index 100% rename from scripts/tests/keys/ecdsa-p256_passwd.key rename to scripts/tests/assets/keys/ecdsa-p256_passwd.key diff --git a/scripts/tests/keys/ecdsa-p384.key b/scripts/tests/assets/keys/ecdsa-p384.key similarity index 100% rename from scripts/tests/keys/ecdsa-p384.key rename to scripts/tests/assets/keys/ecdsa-p384.key diff --git a/scripts/tests/keys/ecdsa-p384_passwd.key b/scripts/tests/assets/keys/ecdsa-p384_passwd.key similarity index 100% rename from scripts/tests/keys/ecdsa-p384_passwd.key rename to scripts/tests/assets/keys/ecdsa-p384_passwd.key diff --git a/scripts/tests/keys/ed25519.key b/scripts/tests/assets/keys/ed25519.key similarity index 100% rename from scripts/tests/keys/ed25519.key rename to scripts/tests/assets/keys/ed25519.key diff --git a/scripts/tests/keys/ed25519_passwd.key b/scripts/tests/assets/keys/ed25519_passwd.key similarity index 100% rename from scripts/tests/keys/ed25519_passwd.key rename to scripts/tests/assets/keys/ed25519_passwd.key diff --git a/scripts/tests/keys/public/ecdsa-p256-pem.pub b/scripts/tests/assets/keys/public/ecdsa-p256-pem.pub similarity index 100% rename from scripts/tests/keys/public/ecdsa-p256-pem.pub rename to scripts/tests/assets/keys/public/ecdsa-p256-pem.pub diff --git a/scripts/tests/keys/public/ecdsa-p384-pem.pub b/scripts/tests/assets/keys/public/ecdsa-p384-pem.pub similarity index 100% rename from scripts/tests/keys/public/ecdsa-p384-pem.pub rename to scripts/tests/assets/keys/public/ecdsa-p384-pem.pub diff --git a/scripts/tests/keys/public/rsa-2048-pem.pub b/scripts/tests/assets/keys/public/rsa-2048-pem.pub similarity index 100% rename from scripts/tests/keys/public/rsa-2048-pem.pub rename to scripts/tests/assets/keys/public/rsa-2048-pem.pub diff --git a/scripts/tests/keys/public/rsa-3072-pem.pub b/scripts/tests/assets/keys/public/rsa-3072-pem.pub similarity index 100% rename from scripts/tests/keys/public/rsa-3072-pem.pub rename to scripts/tests/assets/keys/public/rsa-3072-pem.pub diff --git a/scripts/tests/keys/public/x25519-pem.pub b/scripts/tests/assets/keys/public/x25519-pem.pub similarity index 100% rename from scripts/tests/keys/public/x25519-pem.pub rename to scripts/tests/assets/keys/public/x25519-pem.pub diff --git a/scripts/tests/keys/rsa-2048.key b/scripts/tests/assets/keys/rsa-2048.key similarity index 100% rename from scripts/tests/keys/rsa-2048.key rename to scripts/tests/assets/keys/rsa-2048.key diff --git a/scripts/tests/keys/rsa-2048_passwd.key b/scripts/tests/assets/keys/rsa-2048_passwd.key similarity index 100% rename from scripts/tests/keys/rsa-2048_passwd.key rename to scripts/tests/assets/keys/rsa-2048_passwd.key diff --git a/scripts/tests/keys/rsa-3072.key b/scripts/tests/assets/keys/rsa-3072.key similarity index 100% rename from scripts/tests/keys/rsa-3072.key rename to scripts/tests/assets/keys/rsa-3072.key diff --git a/scripts/tests/keys/rsa-3072_passwd.key b/scripts/tests/assets/keys/rsa-3072_passwd.key similarity index 100% rename from scripts/tests/keys/rsa-3072_passwd.key rename to scripts/tests/assets/keys/rsa-3072_passwd.key diff --git a/scripts/tests/keys/x25519.key b/scripts/tests/assets/keys/x25519.key similarity index 100% rename from scripts/tests/keys/x25519.key rename to scripts/tests/assets/keys/x25519.key diff --git a/scripts/tests/keys/x25519_passwd.key b/scripts/tests/assets/keys/x25519_passwd.key similarity index 100% rename from scripts/tests/keys/x25519_passwd.key rename to scripts/tests/assets/keys/x25519_passwd.key diff --git a/scripts/tests/constants.py b/scripts/tests/constants.py index 2616b9a77..6dc383ed1 100644 --- a/scripts/tests/constants.py +++ b/scripts/tests/constants.py @@ -35,9 +35,9 @@ PUB_KEY_EXT = ".pub" PUB_KEY_HASH_EXT = ".pubhash" -images_dir = "./images" +images_dir = "./tests/assets/images" signed_images_dir = images_dir + "/signed" - +keys_dir = "./tests/assets/keys/" def tmp_name(tmp_path, key_type, suffix=""): return tmp_path / (key_type + suffix) diff --git a/scripts/imgtool/keys/ecdsa_test.py b/scripts/tests/keys/ecdsa_test.py similarity index 100% rename from scripts/imgtool/keys/ecdsa_test.py rename to scripts/tests/keys/ecdsa_test.py diff --git a/scripts/imgtool/keys/ed25519_test.py b/scripts/tests/keys/ed25519_test.py similarity index 100% rename from scripts/imgtool/keys/ed25519_test.py rename to scripts/tests/keys/ed25519_test.py diff --git a/scripts/imgtool/keys/rsa_test.py b/scripts/tests/keys/rsa_test.py similarity index 100% rename from scripts/imgtool/keys/rsa_test.py rename to scripts/tests/keys/rsa_test.py diff --git a/scripts/tests/test_dumpinfo.py b/scripts/tests/test_dumpinfo.py index 8bc817b53..1b8c4cda5 100644 --- a/scripts/tests/test_dumpinfo.py +++ b/scripts/tests/test_dumpinfo.py @@ -21,7 +21,7 @@ from click.testing import CliRunner from imgtool.main import imgtool -from tests.constants import tmp_name, KEY_TYPES, signed_images_dir +from tests.constants import tmp_name, KEY_TYPES, signed_images_dir, images_dir DUMPINFO_SUCCESS_LITERAL = "dumpinfo has run successfully" @@ -63,7 +63,7 @@ def setup(self, tmp_path_persistent, key_type="rsa-2048"): imgtool, ["keygen", "--key", str(self.key), "--type", key_type] ) - self.image = "./images/zero.bin" + self.image = images_dir + "/zero.bin" self.image_signed = tmp_name(tmp_path_persistent, "image", ".signed") @pytest.mark.parametrize("key_type", ("rsa-2048",)) diff --git a/scripts/tests/test_keys.py b/scripts/tests/test_keys.py index cc40d1d31..3f5472010 100644 --- a/scripts/tests/test_keys.py +++ b/scripts/tests/test_keys.py @@ -24,7 +24,7 @@ from imgtool.main import imgtool from tests.constants import KEY_TYPES, GEN_KEY_EXT, tmp_name, OPENSSL_KEY_TYPES, KEY_ENCODINGS, PUB_KEY_EXT, \ - PVT_KEY_FORMATS, KEY_LANGS, PUB_HASH_ENCODINGS, PUB_KEY_HASH_EXT + PVT_KEY_FORMATS, KEY_LANGS, PUB_HASH_ENCODINGS, PUB_KEY_HASH_EXT, keys_dir UNSUPPORTED_TYPES = [("openssl", "ed25519"), ("openssl", "x25519"), @@ -168,7 +168,7 @@ class TestGetPriv(TestKeys): def test_getpriv(self, key_type, key_format, tmp_path_persistent): """Get private key""" - gen_key = "./keys/" + key_type + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + GEN_KEY_EXT result = self.runner.invoke( imgtool, @@ -187,7 +187,7 @@ def test_getpriv(self, key_type, key_format, tmp_path_persistent): def test_getpriv_with_password(self, key_type, key_format, tmp_path_persistent): """Get private key with password""" - gen_key = "./keys/" + key_type + "_passwd" + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + "_passwd" + GEN_KEY_EXT result = self.runner.invoke( imgtool, @@ -207,7 +207,7 @@ def test_getpriv_with_password(self, key_type, key_format, tmp_path_persistent): def test_getpriv_unsupported(self, key_format, key_type, tmp_path_persistent): """Get private key for unsupported combinations should print error message""" - gen_key = "./keys/" + key_type + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + GEN_KEY_EXT result = self.runner.invoke( imgtool, @@ -228,7 +228,7 @@ def test_getpriv_unsupported(self, key_format, key_type, tmp_path_persistent): def test_getpriv_with_invalid_pass(self, key_type, key_format, tmp_path_persistent): """Get private key with invalid password should print 'Invalid passphrase' in stdout""" - gen_key = "./keys/" + key_type + "_passwd" + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + "_passwd" + GEN_KEY_EXT result = self.runner.invoke( imgtool, @@ -252,7 +252,7 @@ class TestGetPub(TestKeys): def test_getpub(self, key_type, tmp_path_persistent): """Get public key - Default lang is c """ - gen_key = "./keys/" + key_type + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + GEN_KEY_EXT pub_key = tmp_name(tmp_path_persistent, key_type, "." + "default" + PUB_KEY_EXT) assert not pub_key.exists() @@ -276,7 +276,7 @@ def test_getpub(self, key_type, tmp_path_persistent): def test_getpub_with_encoding(self, key_type, encoding, tmp_path_persistent): """Get public key with encoding""" - gen_key = "./keys/" + key_type + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + GEN_KEY_EXT pub_key = tmp_name(tmp_path_persistent, key_type, "." + encoding + PUB_KEY_EXT) assert not pub_key.exists() @@ -302,7 +302,7 @@ def test_getpub_with_encoding(self, key_type, encoding, tmp_path_persistent): def test_getpub_with_lang(self, key_type, lang, tmp_path_persistent): """Get public key with specified lang""" - gen_key = "./keys/" + key_type + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + GEN_KEY_EXT pub_key = tmp_name(tmp_path_persistent, key_type, PUB_KEY_EXT + "." + lang) assert not pub_key.exists() @@ -328,7 +328,7 @@ def test_getpub_with_lang(self, key_type, lang, tmp_path_persistent): def test_getpub_no_outfile(self, key_type, encoding, tmp_path_persistent): """Get public key without output file should dump only to stdout""" - gen_key = "./keys/" + key_type + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + GEN_KEY_EXT pub_key = tmp_name(tmp_path_persistent, key_type, "." + encoding + "-null" + PUB_KEY_EXT) assert not pub_key.exists() @@ -350,7 +350,7 @@ def test_getpub_no_outfile(self, key_type, encoding, tmp_path_persistent): def test_getpub_invalid_encoding(self, key_type, tmp_path_persistent): """Get public key with invalid encoding should error message in stdout""" - gen_key = "./keys/" + key_type + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + GEN_KEY_EXT pub_key = tmp_name(tmp_path_persistent, key_type, "." + PUB_KEY_EXT) assert not pub_key.exists() @@ -373,7 +373,7 @@ def test_getpub_invalid_encoding(self, key_type, tmp_path_persistent): def test_getpub_invalid_lang(self, key_type, tmp_path_persistent): """Get public key with invalid lang should print error message in stdout""" - gen_key = "./keys/" + key_type + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + GEN_KEY_EXT pub_key = tmp_name(tmp_path_persistent, key_type, "." + PUB_KEY_EXT) assert not pub_key.exists() @@ -398,7 +398,7 @@ def test_getpub_invalid_lang(self, key_type, tmp_path_persistent): def test_getpub_with_encoding_and_lang(self, key_type, encoding, lang, tmp_path_persistent): """Get public key with both encoding and lang should print error message""" - gen_key = "./keys/" + key_type + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + GEN_KEY_EXT pub_key = tmp_name(tmp_path_persistent, key_type, "." + lang + encoding + PUB_KEY_EXT) assert not pub_key.exists() @@ -425,7 +425,7 @@ def test_getpub_with_encoding_and_lang(self, key_type, encoding, lang, tmp_path_ def test_getpub_invalid_pass(self, key_type, encoding, tmp_path_persistent): """Get public key with invalid password should print 'Invalid passphrase' in stdout""" - gen_key = "./keys/" + key_type + "_passwd" + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + "_passwd" + GEN_KEY_EXT pub_key = tmp_name(tmp_path_persistent, key_type, "." + encoding + PUB_KEY_EXT) result = self.runner.invoke( @@ -451,7 +451,7 @@ class TestGetPubHash(TestKeys): def test_getpubhash(self, key_type, tmp_path_persistent): """Get the hash of the public key - Default encoding is lang-c""" - gen_key = "./keys/" + key_type + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + GEN_KEY_EXT pub_key_hash = tmp_name( tmp_path_persistent, key_type, "." + "default" + PUB_KEY_HASH_EXT ) @@ -476,7 +476,7 @@ def test_getpubhash(self, key_type, tmp_path_persistent): def test_getpubhash_with_encoding(self, key_type, encoding, tmp_path_persistent): """Get the hash of the public key with encoding""" - gen_key = "./keys/" + key_type + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + GEN_KEY_EXT pub_key_hash = tmp_name( tmp_path_persistent, key_type, "." + encoding + PUB_KEY_HASH_EXT ) @@ -503,7 +503,7 @@ def test_getpubhash_with_encoding(self, key_type, encoding, tmp_path_persistent) def test_getpubhash_with_no_output(self, key_type, encoding, tmp_path_persistent): """Get the hash of the public key without outfile should dump only to stdout""" - gen_key = "./keys/" + key_type + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + GEN_KEY_EXT pub_key_hash = tmp_name( tmp_path_persistent, key_type, "." + encoding + "-null" + PUB_KEY_HASH_EXT ) @@ -527,7 +527,7 @@ def test_getpubhash_with_no_output(self, key_type, encoding, tmp_path_persistent def test_getpubhash_with_invalid_encoding(self, key_type, tmp_path_persistent): """Get the hash of the public key with encoding""" - gen_key = "./keys/" + key_type + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + GEN_KEY_EXT pub_key_hash = tmp_name( tmp_path_persistent, key_type, "." + "invalid" + PUB_KEY_HASH_EXT ) @@ -555,7 +555,7 @@ def test_getpubhash_with_invalid_encoding(self, key_type, tmp_path_persistent): def test_getpubhash_with_invalid_pass(self, key_type, encoding, tmp_path_persistent): """Get the hash of the public key with invalid password should print 'Invalid passphrase' in stdout""" - gen_key = "./keys/" + key_type + "_passwd" + GEN_KEY_EXT + gen_key = keys_dir + "/" + key_type + "_passwd" + GEN_KEY_EXT pub_key_hash = tmp_name( tmp_path_persistent, key_type, "." + encoding + "-null" + PUB_KEY_HASH_EXT ) diff --git a/scripts/tests/test_sign.py b/scripts/tests/test_sign.py index 8b93525b1..e3a5437a8 100644 --- a/scripts/tests/test_sign.py +++ b/scripts/tests/test_sign.py @@ -24,15 +24,13 @@ from imgtool.dumpinfo import dump_imginfo from imgtool.main import imgtool -from tests.constants import KEY_TYPES, GEN_KEY_EXT, PUB_KEY_EXT, tmp_name +from tests.constants import KEY_TYPES, GEN_KEY_EXT, PUB_KEY_EXT, tmp_name, images_dir, keys_dir try: KEY_TYPES.remove("x25519") # x25519 is not used for signing, so directory does not contain any such image except ValueError: pass -KEY_DIR = "./keys/" - def assert_image_signed(result, image_signed, verify=True): assert result.exit_code == 0 @@ -63,7 +61,7 @@ def tmp_path_persistent(self, tmp_path_factory): def setup(self, tmp_path_persistent): """Generate keys and images for testing""" - self.image = Path("./images/zero.bin") + self.image = Path(images_dir + "/zero.bin") self.image_signed = tmp_name(tmp_path_persistent, "image", ".signed") @pytest.fixture(autouse=True) @@ -252,7 +250,7 @@ def test_sign_dependencies(self, tmp_path_persistent, dependencies, expected): def test_sign_header_not_padded(self, tmp_path_persistent): """Test with un-padded header with non-zero start should fail""" - self.image = Path("./images/one.bin") + self.image = Path(images_dir + "/one.bin") result = self.runner.invoke( imgtool, @@ -545,7 +543,7 @@ def test_sign_missing_args(self, key_type, tmp_path_persistent): def test_sign_pub_key_format(self, key_type, tmp_path_persistent, key_format): """Test with pub key format""" - loaded_key = KEY_DIR + key_type + ".key" + loaded_key = keys_dir + key_type + ".key" result = self.runner.invoke( imgtool, @@ -683,7 +681,7 @@ def test_sign_sig_out(self, tmp_path_persistent, key_type): def test_sign_load_addr(self, key_type, tmp_path_persistent): """Test sign with load addr""" - loaded_key = KEY_DIR + key_type + ".key" + loaded_key = keys_dir + key_type + ".key" result = self.runner.invoke( imgtool, @@ -712,7 +710,7 @@ def test_sign_load_addr(self, key_type, tmp_path_persistent): def test_sign_load_addr_rom_fixed(self, key_type, tmp_path_persistent): """Test sign with both load addr and rom fixed should fail""" - loaded_key = KEY_DIR + key_type + ".key" + loaded_key = keys_dir + key_type + ".key" result = self.runner.invoke( imgtool, @@ -1207,8 +1205,8 @@ class TestSignHex(TestSign): def test_sign_basic_hex(self, key_type, tmp_path_persistent): """Test basic sign and verify hex file""" - loaded_key = KEY_DIR + key_type + ".key" - self.image = "./images/zero.hex" + loaded_key = keys_dir + key_type + ".key" + self.image = images_dir + "/zero.hex" self.image_signed = tmp_name(tmp_path_persistent, "image", ".hex") result = self.runner.invoke( @@ -1238,7 +1236,7 @@ def test_sign_basic_hex(self, key_type, tmp_path_persistent): def test_sign_hex_file_not_exists(self, key_type, tmp_path_persistent): """Test sign hex file with non-existent file""" - loaded_key = KEY_DIR + key_type + ".key" + loaded_key = keys_dir + key_type + ".key" self.image = "./images/invalid/path/file.hex" self.image_signed = tmp_name(tmp_path_persistent, "image", ".hex") @@ -1270,8 +1268,8 @@ def test_sign_hex_file_not_exists(self, key_type, tmp_path_persistent): def test_sign_hex_padded(self, key_type, tmp_path_persistent): """Test hex file with pad""" - loaded_key = KEY_DIR + key_type + ".key" - self.image = "./images/one_offset.hex" + loaded_key = keys_dir + key_type + ".key" + self.image = images_dir + "/one_offset.hex" # image above generated as below: # ih = IntelHex() # ih.puts(10, '1' * 1024) @@ -1307,8 +1305,8 @@ def test_sign_hex_padded(self, key_type, tmp_path_persistent): def test_sign_hex_confirm(self, key_type, tmp_path_persistent): """Test hex file with confirm""" - loaded_key = KEY_DIR + key_type + ".key" - self.image = "./images/zero.hex" + loaded_key = keys_dir + key_type + ".key" + self.image = images_dir + "/zero.hex" self.image_signed = tmp_name(tmp_path_persistent, "image", ".hex") result = self.runner.invoke( @@ -1339,8 +1337,8 @@ def test_sign_hex_confirm(self, key_type, tmp_path_persistent): def test_sign_basic_hex_bad_image_size(self, key_type, tmp_path_persistent): """Test basic sign hex file with insufficient size should fail""" - loaded_key = KEY_DIR + key_type + ".key" - self.image = "./images/zero.hex" + loaded_key = keys_dir + key_type + ".key" + self.image = images_dir + "/zero.hex" self.image_signed = tmp_name(tmp_path_persistent, "image", ".hex") result = self.runner.invoke( diff --git a/scripts/tests/test_verify.py b/scripts/tests/test_verify.py index 9aacfaa8a..833693685 100644 --- a/scripts/tests/test_verify.py +++ b/scripts/tests/test_verify.py @@ -18,7 +18,7 @@ from click.testing import CliRunner from imgtool.main import imgtool -from tests.constants import KEY_TYPES, GEN_KEY_EXT, tmp_name, signed_images_dir +from tests.constants import KEY_TYPES, GEN_KEY_EXT, tmp_name, signed_images_dir, keys_dir KEY_TYPE_MISMATCH_TLV = "Key type does not match TLV record" NO_SIG_FOR_KEY = "No signature found for the given key" @@ -51,7 +51,7 @@ class TestVerifyBasic(TestVerify): @pytest.fixture(autouse=True) def setup(self, request, tmp_path_persistent, key_type): - self.key = "./keys/" + key_type + ".key" + self.key = keys_dir + key_type + ".key" self.gen_key = tmp_name(tmp_path_persistent, key_type, GEN_KEY_EXT) self.runner.invoke( imgtool, ["keygen", "--key", str(self.gen_key), "--type", key_type] @@ -191,7 +191,7 @@ class TestVerifyEncryptedClear(TestVerify): @pytest.fixture(autouse=True) def setup(self, request, tmp_path_persistent, key_type): - self.key = "./keys/" + key_type + ".key" + self.key = keys_dir + key_type + ".key" self.gen_key = tmp_name(tmp_path_persistent, key_type, GEN_KEY_EXT) self.runner.invoke( imgtool, ["keygen", "--key", str(self.gen_key), "--type", key_type] @@ -240,7 +240,7 @@ class TestVerifyCustomTLV(TestVerify): @pytest.fixture(autouse=True) def setup(self, request, tmp_path_persistent, key_type): - self.key = "./keys/" + key_type + ".key" + self.key = keys_dir + key_type + ".key" self.gen_key = tmp_name(tmp_path_persistent, key_type, GEN_KEY_EXT) self.runner.invoke( imgtool, ["keygen", "--key", str(self.gen_key), "--type", key_type] @@ -301,7 +301,7 @@ def test_verify_no_key(self): def test_verify_no_key_image_with_key(self): """Test verify image signed without key, attempt to verify with a key should fail on signature check""" - self.key = "./keys/" + "rsa-2048" + ".key" + self.key = keys_dir + "rsa-2048" + ".key" self.image_signed = self.test_signed_images_dir + "noKey256" + ".bin" result = self.runner.invoke( @@ -319,7 +319,7 @@ def test_verify_no_key_image_with_key(self): def test_verify_no_key_image_with_wrong_key(self): """Test verify image signed without key, attempt to verify with wrong key should fail on hash check""" - self.key = "./keys/" + "ecdsa-p384" + ".key" + self.key = keys_dir + "ecdsa-p384" + ".key" self.image_signed = self.test_signed_images_dir + "noKey256" + ".bin" result = self.runner.invoke( @@ -343,7 +343,7 @@ class TestVerifyPubKey(TestVerify): @pytest.fixture(autouse=True) def setup(self, request, tmp_path_persistent, key_type): - self.key = "./keys/" + key_type + ".key" + self.key = keys_dir + key_type + ".key" self.gen_key = tmp_name(tmp_path_persistent, key_type, GEN_KEY_EXT) self.runner.invoke( imgtool, ["keygen", "--key", str(self.gen_key), "--type", key_type] @@ -383,7 +383,7 @@ def test_verify_384_key(self, key_type): def test_verify_key_not_matching(self, key_type, tmp_path_persistent): """Test verify image with mismatching key """ - self.key = "./keys/" + "ecdsa-p384" + ".key" + self.key = keys_dir + "ecdsa-p384" + ".key" self.image_signed = self.test_signed_images_dir + key_type + ".bin" result = self.runner.invoke( @@ -423,7 +423,7 @@ class TestVerifyHex(TestVerify): @pytest.fixture(autouse=True) def setup(self, request, tmp_path_persistent, key_type="rsa-2048"): - self.key = "./keys/" + key_type + ".key" + self.key = keys_dir + key_type + ".key" @pytest.mark.parametrize("hex_addr", ("0", "16", "35")) def test_verify_basic(self, hex_addr, tmp_path_persistent):