mirror of
https://github.com/ghndrx/prowler.git
synced 2026-02-10 14:55:00 +00:00
feat(azure): check related with App Insights service (#3395)
This commit is contained in:
committed by
GitHub
parent
cc71249e21
commit
4740a7b930
@@ -0,0 +1,77 @@
|
||||
from unittest import mock
|
||||
|
||||
from prowler.providers.azure.services.appinsights.appinsights_service import Component
|
||||
from tests.providers.azure.azure_fixtures import AZURE_SUBSCRIPTION
|
||||
|
||||
|
||||
class Test_appinsights_ensure_is_configured:
|
||||
def test_appinsights_no_subscriptions(self):
|
||||
appinsights_client = mock.MagicMock
|
||||
appinsights_client.components = {}
|
||||
|
||||
with mock.patch(
|
||||
"prowler.providers.azure.services.appinsights.appinsights_ensure_is_configured.appinsights_ensure_is_configured.appinsights_client",
|
||||
new=appinsights_client,
|
||||
):
|
||||
from prowler.providers.azure.services.appinsights.appinsights_ensure_is_configured.appinsights_ensure_is_configured import (
|
||||
appinsights_ensure_is_configured,
|
||||
)
|
||||
|
||||
check = appinsights_ensure_is_configured()
|
||||
result = check.execute()
|
||||
assert len(result) == 0
|
||||
|
||||
def test_no_appinsights(self):
|
||||
appinsights_client = mock.MagicMock
|
||||
appinsights_client.components = {AZURE_SUBSCRIPTION: {}}
|
||||
|
||||
with mock.patch(
|
||||
"prowler.providers.azure.services.appinsights.appinsights_ensure_is_configured.appinsights_ensure_is_configured.appinsights_client",
|
||||
new=appinsights_client,
|
||||
):
|
||||
from prowler.providers.azure.services.appinsights.appinsights_ensure_is_configured.appinsights_ensure_is_configured import (
|
||||
appinsights_ensure_is_configured,
|
||||
)
|
||||
|
||||
check = appinsights_ensure_is_configured()
|
||||
result = check.execute()
|
||||
assert len(result) == 1
|
||||
assert result[0].subscription == AZURE_SUBSCRIPTION
|
||||
assert result[0].status == "FAIL"
|
||||
assert result[0].resource_id == "AppInsights"
|
||||
assert result[0].resource_name == "AppInsights"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== f"There are no AppInsight configured in susbscription {AZURE_SUBSCRIPTION}."
|
||||
)
|
||||
|
||||
def test_appinsights_configured(self):
|
||||
appinsights_client = mock.MagicMock
|
||||
appinsights_client.components = {
|
||||
AZURE_SUBSCRIPTION: {
|
||||
"app_id-1": Component(
|
||||
resource_id="/subscriptions/resource_id",
|
||||
resource_name="AppInsightsTest",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
with mock.patch(
|
||||
"prowler.providers.azure.services.appinsights.appinsights_ensure_is_configured.appinsights_ensure_is_configured.appinsights_client",
|
||||
new=appinsights_client,
|
||||
):
|
||||
from prowler.providers.azure.services.appinsights.appinsights_ensure_is_configured.appinsights_ensure_is_configured import (
|
||||
appinsights_ensure_is_configured,
|
||||
)
|
||||
|
||||
check = appinsights_ensure_is_configured()
|
||||
result = check.execute()
|
||||
assert len(result) == 1
|
||||
assert result[0].subscription == AZURE_SUBSCRIPTION
|
||||
assert result[0].status == "PASS"
|
||||
assert result[0].resource_id == "AppInsights"
|
||||
assert result[0].resource_name == "AppInsights"
|
||||
assert (
|
||||
result[0].status_extended
|
||||
== f"There is at least one AppInsight configured in susbscription {AZURE_SUBSCRIPTION}."
|
||||
)
|
||||
@@ -0,0 +1,50 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from prowler.providers.azure.services.appinsights.appinsights_service import (
|
||||
AppInsights,
|
||||
Component,
|
||||
)
|
||||
from tests.providers.azure.azure_fixtures import (
|
||||
AZURE_SUBSCRIPTION,
|
||||
set_mocked_azure_audit_info,
|
||||
)
|
||||
|
||||
|
||||
def mock_appinsights_get_components(_):
|
||||
return {
|
||||
AZURE_SUBSCRIPTION: {
|
||||
"app_id-1": Component(
|
||||
resource_id="/subscriptions/resource_id",
|
||||
resource_name="AppInsightsTest",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@patch(
|
||||
"prowler.providers.azure.services.appinsights.appinsights_service.AppInsights.__get_components__",
|
||||
new=mock_appinsights_get_components,
|
||||
)
|
||||
class Test_AppInsights_Service:
|
||||
def test__get_client__(self):
|
||||
app_insights = AppInsights(set_mocked_azure_audit_info())
|
||||
assert (
|
||||
app_insights.clients[AZURE_SUBSCRIPTION].__class__.__name__
|
||||
== "ApplicationInsightsManagementClient"
|
||||
)
|
||||
|
||||
def test__get_subscriptions__(self):
|
||||
app_insights = AppInsights(set_mocked_azure_audit_info())
|
||||
assert app_insights.subscriptions.__class__.__name__ == "dict"
|
||||
|
||||
def test__get_componentes(self):
|
||||
appinsights = AppInsights(set_mocked_azure_audit_info())
|
||||
assert len(appinsights.components) == 1
|
||||
assert (
|
||||
appinsights.components[AZURE_SUBSCRIPTION]["app_id-1"].resource_id
|
||||
== "/subscriptions/resource_id"
|
||||
)
|
||||
assert (
|
||||
appinsights.components[AZURE_SUBSCRIPTION]["app_id-1"].resource_name
|
||||
== "AppInsightsTest"
|
||||
)
|
||||
Reference in New Issue
Block a user