Skip to content

Commit

Permalink
UT: Improve tests for Chrome credentials collector's plugin.py
Browse files Browse the repository at this point in the history
Issue #3426
PR #3659
  • Loading branch information
shreyamalviya committed Sep 6, 2023
1 parent 5856923 commit 89ddd32
Showing 1 changed file with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

@pytest.fixture
def target_host():
return TargetHost(ip="1.1.1.1")
return TargetHost(ip="127.0.0.1")


def builder_exception():
raise Exception()


class ExceptionCallable:
Expand All @@ -33,17 +37,26 @@ def run(self):
return CREDENTIALS


@pytest.mark.parametrize(
"exception_callable",
[
ExceptionCallable,
lambda *_: ExceptionCallable(),
],
)
def test_chrome_plugin__builder_exception(monkeypatch, target_host, exception_callable):
def test_chrome_plugin__build_exception(monkeypatch, target_host):
monkeypatch.setattr(
"agent_plugins.credentials_collectors.chrome.src.plugin.build_chrome_credentials_collector",
builder_exception,
)
chrome_plugin = Plugin(
agent_id=AGENT_ID, agent_event_publisher=MagicMock(spec=IAgentEventPublisher)
)

actual_credentials = chrome_plugin.run(
host=target_host, options={}, interrupt=threading.Event()
)

assert actual_credentials == []


def test_chrome_plugin__run_exception(monkeypatch, target_host):
monkeypatch.setattr(
"agent_plugins.credentials_collectors.chrome.src.plugin.build_chrome_credentials_collector",
lambda *_: exception_callable(),
lambda *_: ExceptionCallable,
)
chrome_plugin = Plugin(
agent_id=AGENT_ID, agent_event_publisher=MagicMock(spec=IAgentEventPublisher)
Expand Down

0 comments on commit 89ddd32

Please sign in to comment.