From 8b987e9b27a5e092029df9c0f7790b96c2a91ff6 Mon Sep 17 00:00:00 2001 From: "Sirlapu, Tejaswini" Date: Thu, 11 Jan 2024 10:47:54 -0800 Subject: [PATCH 01/16] Added verification of GPG key URIs against a list of trusted repositories for enhanced security RTC 537769 check if sourceApplication Gpg key URL is in trusted repo --- inbc-program/README.md | 7 ++++- inbm/Changelog.md | 2 ++ .../source/ubuntu_source_manager.py | 17 +++++++++--- .../unit/source/test_ubuntu_source_cmd.py | 26 +++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/inbc-program/README.md b/inbc-program/README.md index 4d36ab54d..5427161da 100644 --- a/inbc-program/README.md +++ b/inbc-program/README.md @@ -417,6 +417,12 @@ inbc query --option sw Optionally Downloads and encrypts GPG key and stores it on the system under /usr/share/keyrings. Creates a file under /etc/apt/sources.list.d to store the update source information. This list file is used during 'sudo apt update' to update the application. Deb882 format may be used instead of downloading a GPG key. +**NOTE:** Make sure to add gpgKeyUri to trustedrepositories using INBC Config Append command before using Inbc source application add command + Step 1: Refer to Inbc Config Append command to set gpgKeyUri to trustedRepositories in intel-manageability.conf file + Step 2: Use Inbc source appplication add command +``` + + ### Usage ``` inbc source application add @@ -442,7 +448,6 @@ inbc source application add - Each blank line has a period in it. -> " ." - Each line after the Signed-By: starts with a space -> " gibberish" - ``` inbc source application add --sources diff --git a/inbm/Changelog.md b/inbm/Changelog.md index 8047b01b4..77ddc86a7 100644 --- a/inbm/Changelog.md +++ b/inbm/Changelog.md @@ -10,7 +10,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Added - RTC 536601 - Added 'source' command to INBM. This command manages `/etc/apt/sources.list` and `/etc/apt/sources.list.d/*` and associated gpg keys on Ubuntu. +- RTC 537769 - Added verification of GPG key URIs against a list of trusted repositories for enhanced security +check if sourceApplication Gpg key URL is in trusted repo ### Fixed - RTC 534426 - Could not write to /var/log/inbm-update-status.log on Yocto due to /var/log being a symlink to /var/volatile/log. - RTC 523677 - Improve INBC error logging - invalid child tag not printed diff --git a/inbm/dispatcher-agent/dispatcher/source/ubuntu_source_manager.py b/inbm/dispatcher-agent/dispatcher/source/ubuntu_source_manager.py index 8838ff58a..9efbf167a 100644 --- a/inbm/dispatcher-agent/dispatcher/source/ubuntu_source_manager.py +++ b/inbm/dispatcher-agent/dispatcher/source/ubuntu_source_manager.py @@ -7,6 +7,9 @@ import logging import os +from dispatcher.packagemanager.package_manager import verify_source +from dispatcher.dispatcher_broker import DispatcherBroker +from dispatcher.dispatcher_exception import DispatcherException from dispatcher.source.source_exception import SourceError from dispatcher.source.constants import ( UBUNTU_APT_SOURCES_LIST, @@ -94,15 +97,23 @@ def update(self, parameters: SourceParameters) -> None: class UbuntuApplicationSourceManager(ApplicationSourceManager): def __init__(self) -> None: - pass + self.dispatcher_broker= DispatcherBroker() def add(self, parameters: ApplicationAddSourceParameters) -> None: """Adds a source file and optional GPG key to be used during Ubuntu application updates.""" - # Step 1: Add key (Optional) + # Step 1: Verify gpg key uri from trusted repo list if parameters.gpg_key_name and parameters.gpg_key_uri: + try: + url = parameters.gpg_key_uri + #URL slicing to remove the last segment (filename) from the URL + source = url[:-(len(url.split('/')[-1]) + 1)] + verify_source(source=source, dispatcher_broker=self.dispatcher_broker) + except (DispatcherException, IndexError) as err: + raise SourceError(f"Source Gpg key URI verification check failed: {err}") + # Step 2: Add key (Optional) add_gpg_key(parameters.gpg_key_uri, parameters.gpg_key_name) - # Step 2: Add the source + # Step 3: Add the source try: create_file_with_contents( os.path.join(UBUNTU_APT_SOURCES_LIST_D, parameters.file_name), parameters.sources diff --git a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py index 933e37379..09dafa9c8 100644 --- a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py +++ b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py @@ -279,6 +279,32 @@ def test_successfully_remove_gpg_key_and_source_list( except SourceError: self.fail("Remove GPG key raised DispatcherException unexpectedly!") + @patch("dispatcher.packagemanager.package_manager.verify_source", side_effect=DispatcherException('error')) + def test_failed_add_gpg_key_method(self, mock_verify_source): + parameters = ApplicationAddSourceParameters( + gpg_key_uri="https://dl-ssl.google.com/linux/linux_signing_key.pub", + gpg_key_name="name" + ) + command = UbuntuApplicationSourceManager() + try: + command.add(parameters) + except SourceError: + self.fail("Source Gpg key URI verification check failed: error") + + + @patch("dispatcher.packagemanager.package_manager.verify_source") + def test_success_add_gpg_key_method(self, mock_verify_source): + mock_verify_source.return_value = True + parameters = ApplicationAddSourceParameters( + gpg_key_uri="https://dl-ssl.google.com/linux/linux_signing_key.pub", + gpg_key_name="name" + ) + command = UbuntuApplicationSourceManager() + try: + command.add(parameters) + except SourceError: + assert False, f"'UbuntuApplicationSourceManager.add' raised an exception {err}" + @patch("dispatcher.source.ubuntu_source_manager.remove_gpg_key_if_exists") def test_raises_when_space_check_fails(self, mock_remove_gpg_key): parameters = ApplicationRemoveSourceParameters( From 640a59abc6c758919859448770525038151bd956 Mon Sep 17 00:00:00 2001 From: "Sirlapu, Tejaswini" Date: Thu, 11 Jan 2024 10:47:54 -0800 Subject: [PATCH 02/16] Added verification of GPG key URIs against a list of trusted repositories for enhanced security RTC 537769 check if sourceApplication Gpg key URL is in trusted repo --- inbc-program/README.md | 7 ++++- inbm/Changelog.md | 2 ++ .../source/ubuntu_source_manager.py | 17 +++++++++--- .../unit/source/test_ubuntu_source_cmd.py | 27 +++++++++++++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/inbc-program/README.md b/inbc-program/README.md index 4d36ab54d..5427161da 100644 --- a/inbc-program/README.md +++ b/inbc-program/README.md @@ -417,6 +417,12 @@ inbc query --option sw Optionally Downloads and encrypts GPG key and stores it on the system under /usr/share/keyrings. Creates a file under /etc/apt/sources.list.d to store the update source information. This list file is used during 'sudo apt update' to update the application. Deb882 format may be used instead of downloading a GPG key. +**NOTE:** Make sure to add gpgKeyUri to trustedrepositories using INBC Config Append command before using Inbc source application add command + Step 1: Refer to Inbc Config Append command to set gpgKeyUri to trustedRepositories in intel-manageability.conf file + Step 2: Use Inbc source appplication add command +``` + + ### Usage ``` inbc source application add @@ -442,7 +448,6 @@ inbc source application add - Each blank line has a period in it. -> " ." - Each line after the Signed-By: starts with a space -> " gibberish" - ``` inbc source application add --sources diff --git a/inbm/Changelog.md b/inbm/Changelog.md index 8047b01b4..77ddc86a7 100644 --- a/inbm/Changelog.md +++ b/inbm/Changelog.md @@ -10,7 +10,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Added - RTC 536601 - Added 'source' command to INBM. This command manages `/etc/apt/sources.list` and `/etc/apt/sources.list.d/*` and associated gpg keys on Ubuntu. +- RTC 537769 - Added verification of GPG key URIs against a list of trusted repositories for enhanced security +check if sourceApplication Gpg key URL is in trusted repo ### Fixed - RTC 534426 - Could not write to /var/log/inbm-update-status.log on Yocto due to /var/log being a symlink to /var/volatile/log. - RTC 523677 - Improve INBC error logging - invalid child tag not printed diff --git a/inbm/dispatcher-agent/dispatcher/source/ubuntu_source_manager.py b/inbm/dispatcher-agent/dispatcher/source/ubuntu_source_manager.py index 8838ff58a..9efbf167a 100644 --- a/inbm/dispatcher-agent/dispatcher/source/ubuntu_source_manager.py +++ b/inbm/dispatcher-agent/dispatcher/source/ubuntu_source_manager.py @@ -7,6 +7,9 @@ import logging import os +from dispatcher.packagemanager.package_manager import verify_source +from dispatcher.dispatcher_broker import DispatcherBroker +from dispatcher.dispatcher_exception import DispatcherException from dispatcher.source.source_exception import SourceError from dispatcher.source.constants import ( UBUNTU_APT_SOURCES_LIST, @@ -94,15 +97,23 @@ def update(self, parameters: SourceParameters) -> None: class UbuntuApplicationSourceManager(ApplicationSourceManager): def __init__(self) -> None: - pass + self.dispatcher_broker= DispatcherBroker() def add(self, parameters: ApplicationAddSourceParameters) -> None: """Adds a source file and optional GPG key to be used during Ubuntu application updates.""" - # Step 1: Add key (Optional) + # Step 1: Verify gpg key uri from trusted repo list if parameters.gpg_key_name and parameters.gpg_key_uri: + try: + url = parameters.gpg_key_uri + #URL slicing to remove the last segment (filename) from the URL + source = url[:-(len(url.split('/')[-1]) + 1)] + verify_source(source=source, dispatcher_broker=self.dispatcher_broker) + except (DispatcherException, IndexError) as err: + raise SourceError(f"Source Gpg key URI verification check failed: {err}") + # Step 2: Add key (Optional) add_gpg_key(parameters.gpg_key_uri, parameters.gpg_key_name) - # Step 2: Add the source + # Step 3: Add the source try: create_file_with_contents( os.path.join(UBUNTU_APT_SOURCES_LIST_D, parameters.file_name), parameters.sources diff --git a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py index 933e37379..bf547a166 100644 --- a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py +++ b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py @@ -279,6 +279,33 @@ def test_successfully_remove_gpg_key_and_source_list( except SourceError: self.fail("Remove GPG key raised DispatcherException unexpectedly!") + + @patch("dispatcher.packagemanager.package_manager.verify_source", side_effect=DispatcherException('error')) + def test_failed_add_gpg_key_method(self, mock_verify_source): + parameters = ApplicationAddSourceParameters( + gpg_key_uri="https://dl-ssl.google.com/linux/linux_signing_key.pub", + gpg_key_name="name" + ) + command = UbuntuApplicationSourceManager() + try: + command.add(parameters) + except SourceError: + self.fail("Source Gpg key URI verification check failed: error") + + + @patch("dispatcher.packagemanager.package_manager.verify_source") + def test_success_add_gpg_key_method(self, mock_verify_source): + mock_verify_source.return_value = True + parameters = ApplicationAddSourceParameters( + gpg_key_uri="https://dl-ssl.google.com/linux/linux_signing_key.pub", + gpg_key_name="name" + ) + command = UbuntuApplicationSourceManager() + try: + command.add(parameters) + except SourceError: + assert False, f"'UbuntuApplicationSourceManager.add' raised an exception {err}" + @patch("dispatcher.source.ubuntu_source_manager.remove_gpg_key_if_exists") def test_raises_when_space_check_fails(self, mock_remove_gpg_key): parameters = ApplicationRemoveSourceParameters( From 93c65b0256b9571696e3839474b516e237ee3ca5 Mon Sep 17 00:00:00 2001 From: "Sirlapu, Tejaswini" Date: Thu, 18 Jan 2024 10:37:53 -0800 Subject: [PATCH 03/16] unit tests fix --- .../dispatcher/dispatcher_class.py | 3 +- .../dispatcher/source/source_command.py | 10 +++-- .../source/source_manager_factory.py | 5 ++- .../source/ubuntu_source_manager.py | 6 +-- .../unit/source/test_source_cmd_factory.py | 7 +-- .../unit/source/test_ubuntu_source_cmd.py | 44 ++++++++++++------- 6 files changed, 47 insertions(+), 28 deletions(-) diff --git a/inbm/dispatcher-agent/dispatcher/dispatcher_class.py b/inbm/dispatcher-agent/dispatcher/dispatcher_class.py index a88cc1009..955d10103 100644 --- a/inbm/dispatcher-agent/dispatcher/dispatcher_class.py +++ b/inbm/dispatcher-agent/dispatcher/dispatcher_class.py @@ -16,6 +16,7 @@ from threading import Thread, active_count from time import sleep from typing import Tuple +from typing import Optional, Any from dispatcher.config.config_operation import ConfigOperation from dispatcher.source.source_command import do_source_command @@ -293,7 +294,7 @@ def do_install(self, xml: str, schema_location: Optional[str] = None) -> Result: elif type_of_manifest == 'source': logger.debug('Running source command') # FIXME: actually detect OS - result = do_source_command(parsed_head, source.constants.OsType.Ubuntu) + result = do_source_command(parsed_head, source.constants.OsType.Ubuntu, self._dispatcher_broker) elif type_of_manifest == 'ota': # Parse manifest header = parsed_head.get_children('ota/header') diff --git a/inbm/dispatcher-agent/dispatcher/source/source_command.py b/inbm/dispatcher-agent/dispatcher/source/source_command.py index 4b30b5cc8..af7be5ee2 100644 --- a/inbm/dispatcher-agent/dispatcher/source/source_command.py +++ b/inbm/dispatcher-agent/dispatcher/source/source_command.py @@ -7,6 +7,7 @@ import logging import json from dispatcher.common.result_constants import Result +from typing import Optional, Any from dispatcher.source.constants import ( ApplicationAddSourceParameters, ApplicationRemoveSourceParameters, @@ -22,7 +23,7 @@ logger = logging.getLogger(__name__) -def do_source_command(parsed_head: XmlHandler, os_type: OsType) -> Result: +def do_source_command(parsed_head: XmlHandler, os_type: OsType, dispatcher_broker: Optional[Any] = None) -> Result: """ Run a source command. @@ -42,7 +43,7 @@ def do_source_command(parsed_head: XmlHandler, os_type: OsType) -> Result: try: app_action = parsed_head.get_children("applicationSource") if app_action: - return _handle_app_source_command(parsed_head, os_type, app_action) + return _handle_app_source_command(parsed_head, os_type, app_action, dispatcher_broker) except XmlException as e: return Result(status=400, message=f"unable to handle source command XML: {e}") @@ -94,16 +95,17 @@ def _handle_os_source_command(parsed_head: XmlHandler, os_type: OsType, os_actio def _handle_app_source_command( - parsed_head: XmlHandler, os_type: OsType, app_action: dict) -> Result: + parsed_head: XmlHandler, os_type: OsType, app_action: dict, dispatcher_broker: Optional[Any] = None) -> Result: """ Handle the application source commands. @param parsed_head: XmlHandler with command information @param os_type: os type @param app_action: The action to be performed + @param dispatcher_broker: MQTT @return Result """ - application_source_manager = create_application_source_manager(os_type) + application_source_manager = create_application_source_manager(os_type, dispatcher_broker) if "list" in app_action: serialized_list = json.dumps( diff --git a/inbm/dispatcher-agent/dispatcher/source/source_manager_factory.py b/inbm/dispatcher-agent/dispatcher/source/source_manager_factory.py index 0f11c4b55..737aadd7b 100644 --- a/inbm/dispatcher-agent/dispatcher/source/source_manager_factory.py +++ b/inbm/dispatcher-agent/dispatcher/source/source_manager_factory.py @@ -8,6 +8,7 @@ from dispatcher.source.constants import OsType from dispatcher.source.source_manager import ApplicationSourceManager, OsSourceManager +from typing import Optional, Any from dispatcher.source.ubuntu_source_manager import ( UbuntuApplicationSourceManager, UbuntuOsSourceManager, @@ -23,8 +24,8 @@ def create_os_source_manager(os_type: OsType) -> OsSourceManager: raise ValueError(f"Unsupported OS type: {os_type}.") -def create_application_source_manager(os_type: OsType) -> ApplicationSourceManager: +def create_application_source_manager(os_type: OsType, dispatcher_broker: Optional[Any] = None) -> ApplicationSourceManager: """Return correct OS application manager based on OS type""" if os_type is OsType.Ubuntu: - return UbuntuApplicationSourceManager() + return UbuntuApplicationSourceManager(dispatcher_broker) raise ValueError(f"Unsupported OS type: {os_type}.") diff --git a/inbm/dispatcher-agent/dispatcher/source/ubuntu_source_manager.py b/inbm/dispatcher-agent/dispatcher/source/ubuntu_source_manager.py index 9efbf167a..1ff831c00 100644 --- a/inbm/dispatcher-agent/dispatcher/source/ubuntu_source_manager.py +++ b/inbm/dispatcher-agent/dispatcher/source/ubuntu_source_manager.py @@ -96,8 +96,8 @@ def update(self, parameters: SourceParameters) -> None: class UbuntuApplicationSourceManager(ApplicationSourceManager): - def __init__(self) -> None: - self.dispatcher_broker= DispatcherBroker() + def __init__(self, broker: DispatcherBroker) -> None: + self._dispatcher_broker = broker def add(self, parameters: ApplicationAddSourceParameters) -> None: """Adds a source file and optional GPG key to be used during Ubuntu application updates.""" @@ -107,7 +107,7 @@ def add(self, parameters: ApplicationAddSourceParameters) -> None: url = parameters.gpg_key_uri #URL slicing to remove the last segment (filename) from the URL source = url[:-(len(url.split('/')[-1]) + 1)] - verify_source(source=source, dispatcher_broker=self.dispatcher_broker) + verify_source(source=source, dispatcher_broker=self._dispatcher_broker) except (DispatcherException, IndexError) as err: raise SourceError(f"Source Gpg key URI verification check failed: {err}") # Step 2: Add key (Optional) diff --git a/inbm/dispatcher-agent/tests/unit/source/test_source_cmd_factory.py b/inbm/dispatcher-agent/tests/unit/source/test_source_cmd_factory.py index 44160db3e..d4c1f0760 100644 --- a/inbm/dispatcher-agent/tests/unit/source/test_source_cmd_factory.py +++ b/inbm/dispatcher-agent/tests/unit/source/test_source_cmd_factory.py @@ -1,5 +1,6 @@ import pytest from dispatcher.source.constants import OsType +from ..common.mock_resources import MockDispatcherBroker from dispatcher.source.source_manager_factory import ( create_application_source_manager, create_os_source_manager, @@ -20,13 +21,13 @@ def test_create_os_source_manager_unsupported(): create_os_source_manager("UnsupportedOS") assert "Unsupported OS type" in str(excinfo.value) - def test_create_application_source_manager_ubuntu(): - command = create_application_source_manager(OsType.Ubuntu) + mock_disp_broker_obj = MockDispatcherBroker.build_mock_dispatcher_broker() + command = create_application_source_manager(OsType.Ubuntu, mock_disp_broker_obj) assert isinstance(command, UbuntuApplicationSourceManager) - def test_create_application_source_manager_unsupported(): + mock_disp_broker_obj = MockDispatcherBroker.build_mock_dispatcher_broker() with pytest.raises(ValueError) as excinfo: create_application_source_manager("UnsupportedOS") assert "Unsupported OS type" in str(excinfo.value) diff --git a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py index 6488025d0..97a421f33 100644 --- a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py +++ b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py @@ -2,6 +2,7 @@ import pytest from unittest.mock import mock_open, patch from dispatcher.source.source_exception import SourceError +from ..common.mock_resources import MockDispatcherBroker from dispatcher.dispatcher_exception import DispatcherException from dispatcher.source.constants import ( UBUNTU_APT_SOURCES_LIST_D, @@ -194,7 +195,9 @@ def test_update_sources_os_error(self): class TestUbuntuApplicationSourceManager: - def test_add_app_with_gpg_key_successfully(self): + #@patch("dispatcher.packagemanager.package_manager.verify_source") + @patch("dispatcher.source.ubuntu_source_manager.verify_source") + def test_add_app_with_gpg_key_successfully(self, mock_verify_source): try: params = ApplicationAddSourceParameters( file_name="intel-gpu-jammy.list", @@ -202,13 +205,15 @@ def test_add_app_with_gpg_key_successfully(self): gpg_key_uri="https://dl-ssl.google.com/linux/linux_signing_key.pub", gpg_key_name="google-chrome.gpg" ) - command = UbuntuApplicationSourceManager() + broker = MockDispatcherBroker.build_mock_dispatcher_broker() + command = UbuntuApplicationSourceManager(broker) with patch("builtins.open", new_callable=mock_open()): command.add(params) except SourceError as err: assert False, f"'UbuntuApplicationSourceManager.add' raised an exception {err}" def test_add_app_deb_822_format_successfully(self): + broker = MockDispatcherBroker.build_mock_dispatcher_broker() try: params = ApplicationAddSourceParameters( file_name="google-chrome.sources", @@ -219,7 +224,7 @@ def test_add_app_deb_822_format_successfully(self): "Suites: stable" "Components: main", ) - command = UbuntuApplicationSourceManager() + command = UbuntuApplicationSourceManager(broker) with patch("builtins.open", new_callable=mock_open()): command.add(params) except SourceError as err: @@ -227,10 +232,11 @@ def test_add_app_deb_822_format_successfully(self): def test_update_app_source_successfully(self): try: + broker = MockDispatcherBroker.build_mock_dispatcher_broker() params = ApplicationUpdateSourceParameters( file_name="intel-gpu-jammy.list", sources=APP_SOURCE ) - command = UbuntuApplicationSourceManager() + command = UbuntuApplicationSourceManager(broker) with patch("builtins.open", new_callable=mock_open()): command.update(params) except SourceError as err: @@ -249,7 +255,8 @@ def test_list(self, sources_list_d_content): with patch("glob.glob", return_value=["/etc/apt/sources.list.d/example.list"]), patch( "builtins.open", mock_open(read_data=sources_list_d_content) ): - command = UbuntuApplicationSourceManager() + broker = MockDispatcherBroker.build_mock_dispatcher_broker() + command = UbuntuApplicationSourceManager(broker) sources = command.list() assert sources[0].name == "example.list" assert sources[0].sources == [ @@ -261,7 +268,8 @@ def test_list_raises_exception(self): with patch("glob.glob", return_value=["/etc/apt/sources.list.d/example.list"]), patch( "builtins.open", side_effect=OSError ): - command = UbuntuApplicationSourceManager() + broker = MockDispatcherBroker.build_mock_dispatcher_broker() + command = UbuntuApplicationSourceManager(broker) with pytest.raises(SourceError) as exc_info: command.list() assert "Error listing application sources" in str(exc_info.value) @@ -274,14 +282,15 @@ def test_successfully_remove_gpg_key_and_source_list( parameters = ApplicationRemoveSourceParameters( gpg_key_name="example_source.gpg", file_name="example_source.list" ) - command = UbuntuApplicationSourceManager() + broker = MockDispatcherBroker.build_mock_dispatcher_broker() + command = UbuntuApplicationSourceManager(broker) try: command.remove(parameters) except SourceError: self.fail("Remove GPG key raised DispatcherException unexpectedly!") - @patch("dispatcher.packagemanager.package_manager.verify_source", side_effect=DispatcherException('error')) + @patch("dispatcher.source.ubuntu_source_manager.verify_source", side_effect=DispatcherException('error')) def test_failed_add_gpg_key_method(self, mock_verify_source): parameters = ApplicationAddSourceParameters( file_name="intel-gpu-jammy.list", @@ -289,14 +298,15 @@ def test_failed_add_gpg_key_method(self, mock_verify_source): gpg_key_uri="https://dl-ssl.google.com/linux/linux_signing_key.pub", gpg_key_name="name" ) - command = UbuntuApplicationSourceManager() + broker = MockDispatcherBroker.build_mock_dispatcher_broker() + command = UbuntuApplicationSourceManager(broker) try: command.add(parameters) except (DispatcherException, SourceError): assert True, f("'Source Gpg key URI verification check failed: error") - @patch("dispatcher.packagemanager.package_manager.verify_source") + @patch("dispatcher.source.ubuntu_source_manager.verify_source") def test_success_add_gpg_key_method(self, mock_verify_source): mock_verify_source.return_value = True parameters = ApplicationAddSourceParameters( @@ -305,10 +315,11 @@ def test_success_add_gpg_key_method(self, mock_verify_source): gpg_key_uri="https://dl-ssl.google.com/linux/linux_signing_key.pub", gpg_key_name="name" ) - command = UbuntuApplicationSourceManager() + broker = MockDispatcherBroker.build_mock_dispatcher_broker() + command = UbuntuApplicationSourceManager(broker) try: command.add(parameters) - except SourceError: + except SourceError as err: assert False, f"'UbuntuApplicationSourceManager.add' raised an exception {err}" @patch("dispatcher.source.ubuntu_source_manager.remove_gpg_key_if_exists") @@ -316,7 +327,8 @@ def test_raises_when_space_check_fails(self, mock_remove_gpg_key): parameters = ApplicationRemoveSourceParameters( gpg_key_name="example_source.gpg", file_name="../example_source.list" ) - command = UbuntuApplicationSourceManager() + broker = MockDispatcherBroker.build_mock_dispatcher_broker() + command = UbuntuApplicationSourceManager(broker) with pytest.raises(SourceError) as ex: command.remove(parameters) assert str(ex.value) == "Invalid file name: ../example_source.list" @@ -327,7 +339,8 @@ def test_raises_when_unable_to_remove_file(self, mock_remove_gpg_key, mock_remov parameters = ApplicationRemoveSourceParameters( gpg_key_name="example_source.gpg", file_name="example_source.list" ) - command = UbuntuApplicationSourceManager() + broker = MockDispatcherBroker.build_mock_dispatcher_broker() + command = UbuntuApplicationSourceManager(broker) with pytest.raises(SourceError) as ex: command.remove(parameters) assert str(ex.value) == "Error removing file: example_source.list" @@ -342,7 +355,8 @@ def test_raises_on_os_error(self, mock_remove_gpg_key, mock_remove_file, mock_os parameters = ApplicationRemoveSourceParameters( gpg_key_name="example_source.gpg", file_name="example_source.list" ) - command = UbuntuApplicationSourceManager() + broker = MockDispatcherBroker.build_mock_dispatcher_broker() + command = UbuntuApplicationSourceManager(broker) with pytest.raises(SourceError) as ex: command.remove(parameters) assert str(ex.value) == "Error removing file: unable to join path" From f624fc7b8de70d08e4ae472035ea4822b7032e8b Mon Sep 17 00:00:00 2001 From: Gavin Lewis Date: Thu, 18 Jan 2024 10:58:45 -0800 Subject: [PATCH 04/16] fix unit tests --- .../tests/unit/source/test_ubuntu_source_cmd.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py index 3409e988a..0a028b575 100644 --- a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py +++ b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py @@ -195,7 +195,6 @@ def test_update_sources_os_error(self): class TestUbuntuApplicationSourceManager: - #@patch("dispatcher.packagemanager.package_manager.verify_source") @patch("dispatcher.source.ubuntu_source_manager.verify_source") def test_add_app_with_gpg_key_successfully(self, mock_verify_source): try: @@ -318,10 +317,9 @@ def test_success_add_gpg_key_method(self, mock_verify_source): ) broker = MockDispatcherBroker.build_mock_dispatcher_broker() command = UbuntuApplicationSourceManager(broker) - try: + with (patch("builtins.open", new_callable=mock_open()), + patch("dispatcher.source.ubuntu_source_manager.add_gpg_key")): command.add(parameters) - except SourceError as err: - assert False, f"'UbuntuApplicationSourceManager.add' raised an exception {err}" @patch("dispatcher.source.ubuntu_source_manager.remove_gpg_key_if_exists") def test_raises_when_space_check_fails(self, mock_remove_gpg_key): From f74528eb45ee2f4363cc5c688ef9845547b58308 Mon Sep 17 00:00:00 2001 From: "Sirlapu, Tejaswini" Date: Thu, 18 Jan 2024 11:10:12 -0800 Subject: [PATCH 05/16] Fix broker input type --- .../dispatcher/source/source_manager_factory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inbm/dispatcher-agent/dispatcher/source/source_manager_factory.py b/inbm/dispatcher-agent/dispatcher/source/source_manager_factory.py index 737aadd7b..2b7f0a1f0 100644 --- a/inbm/dispatcher-agent/dispatcher/source/source_manager_factory.py +++ b/inbm/dispatcher-agent/dispatcher/source/source_manager_factory.py @@ -24,7 +24,7 @@ def create_os_source_manager(os_type: OsType) -> OsSourceManager: raise ValueError(f"Unsupported OS type: {os_type}.") -def create_application_source_manager(os_type: OsType, dispatcher_broker: Optional[Any] = None) -> ApplicationSourceManager: +def create_application_source_manager(os_type: OsType, dispatcher_broker: Optional[Any]) -> ApplicationSourceManager: """Return correct OS application manager based on OS type""" if os_type is OsType.Ubuntu: return UbuntuApplicationSourceManager(dispatcher_broker) From 1817804148cd3677677846d1aad52de14eccedc7 Mon Sep 17 00:00:00 2001 From: "Sirlapu, Tejaswini" Date: Thu, 18 Jan 2024 11:23:19 -0800 Subject: [PATCH 06/16] Fix broker type --- inbm/dispatcher-agent/dispatcher/source/source_command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inbm/dispatcher-agent/dispatcher/source/source_command.py b/inbm/dispatcher-agent/dispatcher/source/source_command.py index af7be5ee2..df977b271 100644 --- a/inbm/dispatcher-agent/dispatcher/source/source_command.py +++ b/inbm/dispatcher-agent/dispatcher/source/source_command.py @@ -23,7 +23,7 @@ logger = logging.getLogger(__name__) -def do_source_command(parsed_head: XmlHandler, os_type: OsType, dispatcher_broker: Optional[Any] = None) -> Result: +def do_source_command(parsed_head: XmlHandler, os_type: OsType, dispatcher_broker: Optional[Any]) -> Result: """ Run a source command. @@ -95,7 +95,7 @@ def _handle_os_source_command(parsed_head: XmlHandler, os_type: OsType, os_actio def _handle_app_source_command( - parsed_head: XmlHandler, os_type: OsType, app_action: dict, dispatcher_broker: Optional[Any] = None) -> Result: + parsed_head: XmlHandler, os_type: OsType, app_action: dict, dispatcher_broker: Optional[Any]) -> Result: """ Handle the application source commands. From c4e9314f0f63fb20b3651ecb2a8044a5855b8582 Mon Sep 17 00:00:00 2001 From: Gavin Lewis Date: Thu, 18 Jan 2024 12:47:03 -0800 Subject: [PATCH 07/16] push type annotations --- inbm/dispatcher-agent/dispatcher/source/source_command.py | 5 +++-- .../dispatcher/source/source_manager_factory.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/inbm/dispatcher-agent/dispatcher/source/source_command.py b/inbm/dispatcher-agent/dispatcher/source/source_command.py index df977b271..9b2f2af23 100644 --- a/inbm/dispatcher-agent/dispatcher/source/source_command.py +++ b/inbm/dispatcher-agent/dispatcher/source/source_command.py @@ -8,6 +8,7 @@ import json from dispatcher.common.result_constants import Result from typing import Optional, Any +from dispatcher.dispatcher_broker import DispatcherBroker from dispatcher.source.constants import ( ApplicationAddSourceParameters, ApplicationRemoveSourceParameters, @@ -23,7 +24,7 @@ logger = logging.getLogger(__name__) -def do_source_command(parsed_head: XmlHandler, os_type: OsType, dispatcher_broker: Optional[Any]) -> Result: +def do_source_command(parsed_head: XmlHandler, os_type: OsType, dispatcher_broker: DispatcherBroker) -> Result: """ Run a source command. @@ -95,7 +96,7 @@ def _handle_os_source_command(parsed_head: XmlHandler, os_type: OsType, os_actio def _handle_app_source_command( - parsed_head: XmlHandler, os_type: OsType, app_action: dict, dispatcher_broker: Optional[Any]) -> Result: + parsed_head: XmlHandler, os_type: OsType, app_action: dict, dispatcher_broker: DispatcherBroker) -> Result: """ Handle the application source commands. diff --git a/inbm/dispatcher-agent/dispatcher/source/source_manager_factory.py b/inbm/dispatcher-agent/dispatcher/source/source_manager_factory.py index 2b7f0a1f0..b89e4e157 100644 --- a/inbm/dispatcher-agent/dispatcher/source/source_manager_factory.py +++ b/inbm/dispatcher-agent/dispatcher/source/source_manager_factory.py @@ -5,6 +5,7 @@ SPDX-License-Identifier: Apache-2.0 """ import logging +from dispatcher.dispatcher_broker import DispatcherBroker from dispatcher.source.constants import OsType from dispatcher.source.source_manager import ApplicationSourceManager, OsSourceManager @@ -24,7 +25,7 @@ def create_os_source_manager(os_type: OsType) -> OsSourceManager: raise ValueError(f"Unsupported OS type: {os_type}.") -def create_application_source_manager(os_type: OsType, dispatcher_broker: Optional[Any]) -> ApplicationSourceManager: +def create_application_source_manager(os_type: OsType, dispatcher_broker: DispatcherBroker) -> ApplicationSourceManager: """Return correct OS application manager based on OS type""" if os_type is OsType.Ubuntu: return UbuntuApplicationSourceManager(dispatcher_broker) From 8f2360f453692cf74abbd7959c16a97ec2b17c8f Mon Sep 17 00:00:00 2001 From: "Sirlapu, Tejaswini" Date: Thu, 18 Jan 2024 13:26:21 -0800 Subject: [PATCH 08/16] Fix unit tests for broker --- .../unit/source/test_source_cmd_factory.py | 2 +- .../tests/unit/source/test_source_command.py | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/inbm/dispatcher-agent/tests/unit/source/test_source_cmd_factory.py b/inbm/dispatcher-agent/tests/unit/source/test_source_cmd_factory.py index d4c1f0760..4a3603640 100644 --- a/inbm/dispatcher-agent/tests/unit/source/test_source_cmd_factory.py +++ b/inbm/dispatcher-agent/tests/unit/source/test_source_cmd_factory.py @@ -29,5 +29,5 @@ def test_create_application_source_manager_ubuntu(): def test_create_application_source_manager_unsupported(): mock_disp_broker_obj = MockDispatcherBroker.build_mock_dispatcher_broker() with pytest.raises(ValueError) as excinfo: - create_application_source_manager("UnsupportedOS") + create_application_source_manager("UnsupportedOS", mock_disp_broker_obj) assert "Unsupported OS type" in str(excinfo.value) diff --git a/inbm/dispatcher-agent/tests/unit/source/test_source_command.py b/inbm/dispatcher-agent/tests/unit/source/test_source_command.py index a0885ee4f..2d7737703 100644 --- a/inbm/dispatcher-agent/tests/unit/source/test_source_command.py +++ b/inbm/dispatcher-agent/tests/unit/source/test_source_command.py @@ -7,6 +7,7 @@ import pytest from dispatcher.common.result_constants import Result +from ..common.mock_resources import MockDispatcherBroker from dispatcher.source.constants import ( ApplicationAddSourceParameters, ApplicationRemoveSourceParameters, @@ -66,8 +67,8 @@ def test_do_source_command_list( mock_source_manager.list.return_value = return_value mocker.patch(patch_target, return_value=mock_source_manager) - - result = do_source_command(xml_handler, OsType.Ubuntu) + broker = MockDispatcherBroker.build_mock_dispatcher_broker() + result = do_source_command(xml_handler, OsType.Ubuntu, broker) assert result == Result(status=200, message=expected_message) mock_source_manager.list.assert_called_once() @@ -113,8 +114,8 @@ def test_do_source_command_remove( mock_manager.remove.return_value = None mocker.patch(manager_mock, return_value=mock_manager) - - result = do_source_command(xml_handler, os_type) + broker = MockDispatcherBroker.build_mock_dispatcher_broker() + result = do_source_command(xml_handler, os_type, broker) mock_manager.remove.assert_called_once_with(expected_call) assert result == Result(status=200, message="SUCCESS") @@ -180,8 +181,8 @@ def test_do_source_command_add( mock_manager.add.return_value = None mocker.patch(manager_mock, return_value=mock_manager) - - result = do_source_command(xml_handler, os_type) + broker = MockDispatcherBroker.build_mock_dispatcher_broker() + result = do_source_command(xml_handler, os_type, broker) mock_manager.add.assert_called_once_with(expected_call) assert result == Result(status=200, message="SUCCESS") @@ -240,8 +241,8 @@ def test_do_source_command_update( mock_manager.update.return_value = None mocker.patch(manager_mock, return_value=mock_manager) - - result = do_source_command(xml_handler, os_type) + broker = MockDispatcherBroker.build_mock_dispatcher_broker() + result = do_source_command(xml_handler, os_type, broker) mock_manager.update.assert_called_once_with(expected_call) assert result == Result(status=200, message="SUCCESS") From d6cc0cfbd275f8fb427ab94cd8b93405c6ccac71 Mon Sep 17 00:00:00 2001 From: "Sirlapu, Tejaswini" Date: Thu, 18 Jan 2024 13:37:34 -0800 Subject: [PATCH 09/16] Fix unit tests for broker --- inbc-program/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/inbc-program/README.md b/inbc-program/README.md index 9fc1b7217..ca3e3b528 100644 --- a/inbc-program/README.md +++ b/inbc-program/README.md @@ -426,6 +426,7 @@ This list file is used during 'sudo apt update' to update the application. **NOTE:** Make sure to add gpgKeyUri to trustedrepositories using INBC Config Append command before using Inbc source application add command Step 1: Refer to Inbc Config Append command to set gpgKeyUri to trustedRepositories in intel-manageability.conf file + Example: inbc append --path trustedRepositories:https://deb.opera.com/ Step 2: Use Inbc source appplication add command ``` From b7131e26617eed32a8e98deaa7b91ed2ebf9ee35 Mon Sep 17 00:00:00 2001 From: "Sirlapu, Tejaswini" Date: Thu, 18 Jan 2024 14:11:30 -0800 Subject: [PATCH 10/16] Fix tests --- .../tests/unit/source/test_ubuntu_source_cmd.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py index 0a028b575..b61842b38 100644 --- a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py +++ b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py @@ -300,10 +300,9 @@ def test_failed_add_gpg_key_method(self, mock_verify_source): ) broker = MockDispatcherBroker.build_mock_dispatcher_broker() command = UbuntuApplicationSourceManager(broker) - try: + with pytest.raises(SourceError) as ex: command.add(parameters) - except (DispatcherException, SourceError): - assert True, f("'Source Gpg key URI verification check failed: error") + assert str(ex.value) == 'Source Gpg key URI verification check failed: error' @patch("dispatcher.source.ubuntu_source_manager.verify_source") From 4ae5cec889dab1fcd6617160b79c60dee550caf9 Mon Sep 17 00:00:00 2001 From: "Sirlapu, Tejaswini" Date: Thu, 18 Jan 2024 15:31:23 -0800 Subject: [PATCH 11/16] fix tests --- .../tests/unit/source/test_ubuntu_source_cmd.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py index b61842b38..7cad36155 100644 --- a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py +++ b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py @@ -199,7 +199,6 @@ class TestUbuntuApplicationSourceManager: def test_add_app_with_gpg_key_successfully(self, mock_verify_source): try: params = ApplicationAddSourceParameters( - file_name="intel-gpu-jammy.list", sources="deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main", gpg_key_uri="https://dl-ssl.google.com/linux/linux_signing_key.pub", gpg_key_name="google-chrome.gpg" @@ -293,7 +292,6 @@ def test_successfully_remove_gpg_key_and_source_list( @patch("dispatcher.source.ubuntu_source_manager.verify_source", side_effect=DispatcherException('error')) def test_failed_add_gpg_key_method(self, mock_verify_source): parameters = ApplicationAddSourceParameters( - file_name="intel-gpu-jammy.list", sources="deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main", gpg_key_uri="https://dl-ssl.google.com/linux/linux_signing_key.pub", gpg_key_name="name" @@ -309,7 +307,6 @@ def test_failed_add_gpg_key_method(self, mock_verify_source): def test_success_add_gpg_key_method(self, mock_verify_source): mock_verify_source.return_value = True parameters = ApplicationAddSourceParameters( - file_name="intel-gpu-jammy.list", sources="deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main", gpg_key_uri="https://dl-ssl.google.com/linux/linux_signing_key.pub", gpg_key_name="name" From 12a885f7105a9956edc0707a55c8d5f82da17a0e Mon Sep 17 00:00:00 2001 From: "Sirlapu, Tejaswini" Date: Thu, 18 Jan 2024 15:46:30 -0800 Subject: [PATCH 12/16] tests --- .../tests/unit/source/test_ubuntu_source_cmd.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py index 16f07fd58..11b28a11a 100644 --- a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py +++ b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py @@ -199,6 +199,7 @@ class TestUbuntuApplicationSourceManager: def test_add_app_with_gpg_key_successfully(self, mock_verify_source): try: params = ApplicationAddSourceParameters( + source_list_file_name="google-chrome.sources", sources="deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main", gpg_key_uri="https://dl-ssl.google.com/linux/linux_signing_key.pub", gpg_key_name="google-chrome.gpg" @@ -290,6 +291,7 @@ def test_successfully_remove_gpg_key_and_source_list( @patch("dispatcher.source.ubuntu_source_manager.verify_source", side_effect=DispatcherException('error')) def test_failed_add_gpg_key_method(self, mock_verify_source): parameters = ApplicationAddSourceParameters( + source_list_file_name="example_source.list", sources="deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main", gpg_key_uri="https://dl-ssl.google.com/linux/linux_signing_key.pub", gpg_key_name="name" @@ -305,6 +307,7 @@ def test_failed_add_gpg_key_method(self, mock_verify_source): def test_success_add_gpg_key_method(self, mock_verify_source): mock_verify_source.return_value = True parameters = ApplicationAddSourceParameters( + source_list_file_name="example_source.list", sources="deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main", gpg_key_uri="https://dl-ssl.google.com/linux/linux_signing_key.pub", gpg_key_name="name" From f10d3efd35b0f4f704cb65b572d1c2f08fa341a5 Mon Sep 17 00:00:00 2001 From: "Sirlapu, Tejaswini" Date: Thu, 18 Jan 2024 15:55:02 -0800 Subject: [PATCH 13/16] tests --- .../tests/unit/source/test_ubuntu_source_cmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py index 11b28a11a..d59253109 100644 --- a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py +++ b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py @@ -348,7 +348,7 @@ def test_raises_when_unable_to_remove_file(self, mock_remove_file): @patch("dispatcher.source.ubuntu_source_manager.remove_gpg_key_if_exists") def test_raises_on_os_error(self, mock_remove_gpg_key, mock_remove_file, mock_os_error): parameters = ApplicationRemoveSourceParameters( - gpg_key_name="example_source.gpg", file_name="example_source.list" + gpg_key_name="example_source.gpg", source_list_file_name="example_source.list" ) broker = MockDispatcherBroker.build_mock_dispatcher_broker() command = UbuntuApplicationSourceManager(broker) From abc46756bafe7a2e258890a7be3f86e2e3a64c48 Mon Sep 17 00:00:00 2001 From: "Sirlapu, Tejaswini" Date: Thu, 18 Jan 2024 16:07:06 -0800 Subject: [PATCH 14/16] Test --- .../unit/source/test_ubuntu_source_cmd.py | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py index d59253109..b2fec966a 100644 --- a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py +++ b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py @@ -338,21 +338,4 @@ def test_raises_when_unable_to_remove_file(self, mock_remove_file): command = UbuntuApplicationSourceManager(broker) with pytest.raises(SourceError) as ex: command.remove(parameters) - assert str(ex.value) == "Error removing file: example_source.list" - - @patch( - "dispatcher.source.ubuntu_source_manager.os.path.join", - side_effect=OSError("unable to join path"), - ) - @patch("dispatcher.source.ubuntu_source_manager.remove_file", return_value=False) - @patch("dispatcher.source.ubuntu_source_manager.remove_gpg_key_if_exists") - def test_raises_on_os_error(self, mock_remove_gpg_key, mock_remove_file, mock_os_error): - parameters = ApplicationRemoveSourceParameters( - gpg_key_name="example_source.gpg", source_list_file_name="example_source.list" - ) - broker = MockDispatcherBroker.build_mock_dispatcher_broker() - command = UbuntuApplicationSourceManager(broker) - with pytest.raises(SourceError) as ex: - command.remove(parameters) - assert str(ex.value) == "Error removing file: unable to join path" - + assert str(ex.value) == "Error removing file: example_source.list" \ No newline at end of file From d0483772ae50e400417e675994dec9fe9f3ead42 Mon Sep 17 00:00:00 2001 From: "Sirlapu, Tejaswini" Date: Thu, 18 Jan 2024 16:15:30 -0800 Subject: [PATCH 15/16] test --- .../tests/unit/source/test_ubuntu_source_cmd.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py index b2fec966a..d50761830 100644 --- a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py +++ b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py @@ -318,13 +318,11 @@ def test_success_add_gpg_key_method(self, mock_verify_source): patch("dispatcher.source.ubuntu_source_manager.add_gpg_key")): command.add(parameters) - @patch("dispatcher.source.ubuntu_source_manager.remove_gpg_key_if_exists") - def test_raises_when_space_check_fails(self, mock_remove_gpg_key): + def test_raises_when_space_check_fails(self): parameters = ApplicationRemoveSourceParameters( gpg_key_name="example_source.gpg", source_list_file_name="../example_source.list" ) - broker = MockDispatcherBroker.build_mock_dispatcher_broker() - command = UbuntuApplicationSourceManager(broker) + command = UbuntuApplicationSourceManager() with pytest.raises(SourceError) as ex: command.remove(parameters) assert str(ex.value) == "Invalid file name: ../example_source.list" From 31c10fea5b39a0ebd8b9b6543f5e6a13405c5665 Mon Sep 17 00:00:00 2001 From: "Sirlapu, Tejaswini" Date: Thu, 18 Jan 2024 16:21:52 -0800 Subject: [PATCH 16/16] test --- .../tests/unit/source/test_ubuntu_source_cmd.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py index d50761830..d2bb0fdd8 100644 --- a/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py +++ b/inbm/dispatcher-agent/tests/unit/source/test_ubuntu_source_cmd.py @@ -322,7 +322,8 @@ def test_raises_when_space_check_fails(self): parameters = ApplicationRemoveSourceParameters( gpg_key_name="example_source.gpg", source_list_file_name="../example_source.list" ) - command = UbuntuApplicationSourceManager() + broker = MockDispatcherBroker.build_mock_dispatcher_broker() + command = UbuntuApplicationSourceManager(broker) with pytest.raises(SourceError) as ex: command.remove(parameters) assert str(ex.value) == "Invalid file name: ../example_source.list"