[swugenerator] [PATCH 3/3] Extend test cases for sign feature

7 views
Skip to first unread message

INgo...@gmx.net

unread,
Oct 22, 2025, 10:56:14 AM (7 days ago) Oct 22
to swupdate
Signed-off-by: INgo Rah <ingo...@linutronix.de>
---
tests/test_integration.py | 71 +++++++++++++++++++++++++++++++++++++++
tests/test_main.py | 12 +++++++
2 files changed, 83 insertions(+)

diff --git a/tests/test_integration.py b/tests/test_integration.py
index fc7bc9e..133ac9a 100644
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -206,3 +206,74 @@ def test_command_with_sign_flag_and_encrypt_flag_creates_signed_encrypted_swu(
]
main.parse_args(command_args)
assert validate_swu(output_directory / output_file, encrypted=True)
+
+def test_creates_and_signs_valid_swu(
+ artifactory, sw_description_template, config_file,
+ signing_key, output_directory
+):
+ output_file = "output.swu"
+ command_args = [
+ "-s",
+ str(sw_description_template),
+ "-a",
+ str(artifactory),
+ "-c",
+ str(config_file),
+ "-o",
+ str((output_directory / output_file).resolve()),
+ "create",
+ ]
+ main.parse_args(command_args)
+ signed_output_file = "signed_output.swu"
+ command_args = [
+ "-o",
+ str((output_directory / signed_output_file).resolve()),
+ "-k",
+ f"RSA,{signing_key}",
+ "sign",
+ "-i",
+ str((output_directory / output_file).resolve()),
+ ]
+ main.parse_args(command_args)
+
+ assert validate_swu(output_directory / signed_output_file)
+
+
+def test_with_encryption_flag_creates_encrypted_and_sign_swu(
+ artifactory,
+ encrypted_sw_description_template,
+ config_file,
+ encryption_key,
+ signing_key,
+ output_directory,
+):
+ output_file = "output.swu.enc"
+ command_args = [
+ "-s",
+ str(encrypted_sw_description_template),
+ "-a",
+ str(artifactory),
+ "-c",
+ str(config_file),
+ "-K",
+ str(encryption_key),
+ "-o",
+ str((output_directory / output_file).resolve()),
+ "create",
+ ]
+ main.parse_args(command_args)
+ assert validate_swu(output_directory / output_file, encrypted=True)
+
+ signed_output_file = "signed_output.swu.enc"
+ command_args = [
+ "-o",
+ str((output_directory / signed_output_file).resolve()),
+ "-k",
+ f"RSA,{signing_key}",
+ "sign",
+ "-i",
+ str((output_directory / output_file).resolve()),
+ ]
+ main.parse_args(command_args)
+
+ assert validate_swu(output_directory / signed_output_file, encrypted=True)
diff --git a/tests/test_main.py b/tests/test_main.py
index 7846a7d..ae999d8 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -212,7 +212,11 @@ def mock_main_funcs(monkeypatch):
def mock_argparse_error(*_):
raise Exception
+ def mock_sign_swu(*_):
+ return True
+
monkeypatch.setattr(main, "create_swu", mock_create_swu)
+ monkeypatch.setattr(main, "sign_swu", mock_sign_swu)
monkeypatch.setattr(main, "extract_keys", mock_extract_keys)
monkeypatch.setattr(main, "parse_signing_option", mock_parse_signing_option)
monkeypatch.setattr(main, "parse_config_file", mock_parse_config_file)
@@ -268,6 +272,7 @@ VALID_COMMANDS = [
"create",
]
),
+ (["-o", "test.swu", "sign", "-i", "in.swu"]),
]
@@ -277,6 +282,7 @@ def test_parsing_valid_args_doesnt_throw(args, mock_main_funcs):
INVALID_COMMANDS = [
+ (["create"]),
(["-s", "sw-description", "-o", "test.swu"]),
(["-s", "-o", "test.swu", "create"]),
(["-s", "sw-description", "-o", "create"]),
@@ -288,6 +294,12 @@ INVALID_COMMANDS = [
(["-c", "sw-description", "-o", "test.swu", "create"]),
(["-l", "sw-description", "-o", "test.swu", "create"]),
(["-l", "baz", "sw-description", "-o", "test.swu", "create"]),
+ (["sign"]),
+ (["-o", "test.swu", "sign"]),
+ (["-i", "-o", "test.swu", "sign"]),
+ (["-i", "in.swu", "-o", "test.swu", "sign"]),
+ (["-o", "test.swu", "create"]),
+ (["-o", "sign", "-i", "in.swu"]),
]
--
2.47.3


Reply all
Reply to author
Forward
0 new messages