Skip to content

Commit

Permalink
add new text and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rieven committed Sep 4, 2023
1 parent 0e28c76 commit 1bd7735
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
15 changes: 10 additions & 5 deletions rocky/katalogus/views/plugin_enable_disable.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,21 @@ def post(self, request, *args, **kwargs):
_("Boefje '{boefje_name}' enabled.").format(boefje_name=self.plugin.name),
)
else:
member_clearance_level_text = (
"Your clearance level is L{}. Contact your administrator to get a higher clearance level."
).format(self.organization_member.trusted_clearance_level)

if self.organization_member.trusted_clearance_level < 0:
member_clearance_level_text = _(
"Your clearance level has not yet been set. Contact your administrator."
)

messages.add_message(
self.request,
messages.ERROR,
_(
"To enable {} you need at least a clearance level of L{}. "
"Your clearance level is L{}. Contact your administrator to get a higher clearance level."
).format(
_("To enable {} you need at least a clearance level of L{}. " + member_clearance_level_text).format(
self.plugin.name.title(),
self.plugin.scan_level.value,
self.organization_member.trusted_clearance_level,
),
)

Expand Down
40 changes: 39 additions & 1 deletion rocky/tests/katalogus/test_katalogus.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def test_katalogus_client(mocker):


def test_enable_disable_plugin_no_clearance(rf, redteam_member, mocker):
redteam_member.trusted_clearance_level = -1
redteam_member.trusted_clearance_level = 1
redteam_member.save()

plugin = get_boefjes_data()[0]
Expand Down Expand Up @@ -226,6 +226,44 @@ def test_enable_disable_plugin_no_clearance(rf, redteam_member, mocker):
)


def test_enable_disable_plugin_no_clearance_other_text(rf, redteam_member, mocker):
redteam_member.trusted_clearance_level = -1
redteam_member.save()

plugin = get_boefjes_data()[0]
mock_requests = mocker.patch("katalogus.client.requests")
mock_response = mocker.MagicMock()
mock_requests.Session().get.return_value = mock_response
mock_response.json.return_value = plugin

request = setup_request(
rf.post(
"plugin_enable_disable",
),
redteam_member.user,
)

response = PluginEnableDisableView.as_view()(
setup_request(request, redteam_member.user),
organization_code=redteam_member.organization.code,
plugin_type=plugin["type"],
plugin_id=plugin["id"],
plugin_state=False,
)

# redirects back to KAT-alogus
assert response.status_code == 302

assert (
list(request._messages).pop().message
== "To enable "
+ plugin["name"].title()
+ " you need at least a clearance level of L"
+ str(plugin["scan_level"])
+ ". Your clearance level has not yet been set. Contact your administrator."
)


def test_enable_disable_plugin_has_clearance(rf, redteam_member, mocker):
plugin = get_boefjes_data()[0]
mock_requests = mocker.patch("katalogus.client.requests")
Expand Down

0 comments on commit 1bd7735

Please sign in to comment.