Skip to content

Commit

Permalink
Merge branch 'main' into fix-preselect
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisser committed Jun 19, 2023
2 parents b49802c + 210a0b3 commit 68a3f0a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions octopoes/bits/https_redirect/https_redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def run(input_ooi: HostnameHTTPURL, additional_oois: List[HTTPHeader], config: D

if "location" not in header_keys:
ft = KATFindingType(id="KAT-NO-HTTPS-REDIRECT")
yield ft
yield Finding(
ooi=input_ooi.reference,
finding_type=ft.reference,
Expand Down
11 changes: 9 additions & 2 deletions rocky/crisis_room/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def total(self) -> int:

@property
def total_critical(self) -> int:
return self.finding_count_per_severity[RiskLevelSeverity.CRITICAL.value]
try:
return self.finding_count_per_severity[RiskLevelSeverity.CRITICAL.value]
except KeyError:
return 0


class CrisisRoomBreadcrumbsMixin(BreadcrumbsMixin):
Expand Down Expand Up @@ -65,7 +68,11 @@ def get_finding_type_severity_count(self, organization: Organization) -> Dict[st
return api_connector.count_findings_by_severity(valid_time=self.get_observed_at())
except ConnectorException:
messages.add_message(
self.request, messages.ERROR, _("Failed to get list of findings, check server logs for more details.")
self.request,
messages.ERROR,
_("Failed to get list of findings for organization {}, check server logs for more details.").format(
organization.code
),
)
logger.exception("Failed to get list of findings for organization %s", organization.code)
return {}
Expand Down
9 changes: 9 additions & 0 deletions rocky/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ def client_member_b(clientuser_b, organization_b):
return member


@pytest.fixture
def client_user_two_organizations(clientuser, organization, organization_b):
member = create_member(clientuser, organization)
add_client_group_permissions(member)
member = create_member(clientuser, organization_b)
add_client_group_permissions(member)
return clientuser


@pytest.fixture
def new_member(django_user_model, organization):
user = create_user(django_user_model, "cl1@openkat.nl", "TestTest123!!", "New user", "default_new_user")
Expand Down
31 changes: 30 additions & 1 deletion rocky/tests/test_crisis_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.urls import resolve, reverse
from pytest_django.asserts import assertContains

from octopoes.connector import ConnectorException
from tests.conftest import setup_request


Expand All @@ -22,7 +23,8 @@ def test_crisis_room(rf, client_member, mock_crisis_room_octopoes):
response = CrisisRoomView.as_view()(request)

assert response.status_code == 200
assertContains(response, "1")
assertContains(response, '<a href="/en/test/findings/?severity=medium">1</a>', html=True)
assertContains(response, '<td><span class="critical">Critical</span></td><td class="number">0</td>', html=True)

assert mock_crisis_room_octopoes().count_findings_by_severity.call_count == 1

Expand All @@ -43,3 +45,30 @@ def test_crisis_room_observed_at(rf, client_member, mock_crisis_room_octopoes):

def test_org_finding_count_total():
assert OrganizationFindingCountPerSeverity("dev", "_dev", {"medium": 1, "low": 2}).total == 3


def test_crisis_room_error(rf, client_user_two_organizations, mock_crisis_room_octopoes):
request = setup_request(rf.get("crisis_room"), client_user_two_organizations)
request.resolver_match = resolve(reverse("crisis_room"))

mock_crisis_room_octopoes().count_findings_by_severity.side_effect = [
{
"medium": 1,
"critical": 0,
},
ConnectorException("error"),
]

response = CrisisRoomView.as_view()(request)

assert response.status_code == 200
assertContains(response, '<a href="/en/test/findings/?severity=medium">1</a>', html=True)
assertContains(response, '<td><span class="critical">Critical</span></td><td class="number">0</td>', html=True)

messages = list(request._messages)
assert (
messages[0].message
== "Failed to get list of findings for organization org_b, check server logs for more details."
)

assert mock_crisis_room_octopoes().count_findings_by_severity.call_count == 2

0 comments on commit 68a3f0a

Please sign in to comment.