Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete workflows tests #491

Merged
merged 6 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 39 additions & 9 deletions configurations/system/tests_cases/workflows_tests.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,61 @@
import inspect
from .structures import TestConfiguration
from systest_utils.statics import DEFAULT_WORKFLOWS_DEPLOYMENT_PATH
from os.path import join
from tests_scripts.workflows.utils import get_messages_from_slack_channel, enrich_slack_alert_channel, get_messages_from_teams_channel, enrich_teams_alert_channel





class WorkflowsTests(object):
'''
NOTE:
NOTE:

'''

@staticmethod
def slack_alerts_workflows():
from tests_scripts.workflows.workflows import WorkflowsSlack
def slack_notifications_workflows():
from tests_scripts.workflows.slack_workflows import WorkflowsSlackNotifications
return TestConfiguration(
name=inspect.currentframe().f_code.co_name,
test_obj=WorkflowsSlack,
create_test_tenant = True
test_obj=WorkflowsSlackNotifications,
deployments=join(DEFAULT_WORKFLOWS_DEPLOYMENT_PATH, "http"),
deployments1=join(DEFAULT_WORKFLOWS_DEPLOYMENT_PATH, "http1"),
getMessagesFunc=get_messages_from_slack_channel,
enrichAlertChannelFunc=enrich_slack_alert_channel,
create_test_tenant = False
)

@staticmethod
def teams_alerts_workflows():
from tests_scripts.workflows.workflows import WorkflowsSlack
def teams_notifications_workflows():
from tests_scripts.workflows.teams_workflows import WorkflowsTeamsNotifications
return TestConfiguration(
name=inspect.currentframe().f_code.co_name,
test_obj=WorkflowsTeamsNotifications,
deployments=join(DEFAULT_WORKFLOWS_DEPLOYMENT_PATH, "http"),
deployments1=join(DEFAULT_WORKFLOWS_DEPLOYMENT_PATH, "http1"),
getMessagesFunc=get_messages_from_teams_channel,
enrichAlertChannelFunc=enrich_teams_alert_channel,
create_test_tenant = False
)

@staticmethod
def jira_notifications_workflows():
from tests_scripts.workflows.jira_workflows import WorkflowsJiraNotifications
return TestConfiguration(
name=inspect.currentframe().f_code.co_name,
test_obj=WorkflowsSlack,
create_test_tenant = True
test_obj=WorkflowsJiraNotifications,
deployments=join(DEFAULT_WORKFLOWS_DEPLOYMENT_PATH, "http"),
create_test_tenant = False
)

@staticmethod
def workflows_configurations():
from tests_scripts.workflows.conf_workflows import WorkflowConfigurations
return TestConfiguration(
name=inspect.currentframe().f_code.co_name,
test_obj=WorkflowConfigurations,
create_test_tenant = False
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: http
labels:
app: http
spec:
replicas: 1
selector:
matchLabels:
app: http
template:
metadata:
labels:
app: http
spec:
containers:
- image: httpd:alpine3.16
name: http
env:
- name: app
value: http
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: http-alt
labels:
app: http-alt
spec:
replicas: 1
selector:
matchLabels:
app: http-alt
template:
metadata:
labels:
app: http-alt
spec:
containers:
- image: httpd:alpine3.16
name: http-alt
env:
- name: app
value: http-alt
123 changes: 118 additions & 5 deletions infrastructure/backend_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ class NotExistingCustomer(Exception):
API_SECCOMP_LIST = "/api/v1/seccomp/list"
API_SECCOMP_GENERATE = "/api/v1/seccomp/generate"

API_WORKFLOWS = "/api/v1/workflows"

API_WEBHOOKS = "/api/v1/notifications/teams"
API_TEAMS_TEST_MESSAGE = "/api/v1/notifications/teams/testMessage"



def deco_cookie(func):
def apply_cookie(*args, **kwargs):
Expand Down Expand Up @@ -1970,7 +1976,9 @@ def delete(self, url, **args):
# for deletion we need to wait a while
if not 'timeout' in args or args["timeout"] < 120:
args["timeout"] = 120
return requests.delete(self.server + url, **args)
url = self.server + url
return requests.delete(url, **args)


def get_cookie(self):
return self.selected_tenant_cookie
Expand Down Expand Up @@ -2359,7 +2367,7 @@ def get_vulns_v2(self, body: dict, expected_results: int = 0, scope: str = None)
if scope:
params = {"scope": scope}
return self.post_list_request(API_VULNERABILITY_V2, body, expected_results, params=params)

def get_vuln_v2_details(self, body: dict):
return self.post_details_request(API_VULNERABILITY_V2, body)

Expand Down Expand Up @@ -2422,8 +2430,8 @@ def get_security_risks_list(self, cluster_name=None, namespace=None, security_ri
raise Exception(
'Error accessing dashboard. Request: get_security_risks_list "%s" (code: %d, message: %s)' % (
self.customer, r.status_code, r.text))
return r

return r.text
def get_security_risks_severities(self, cluster_name=None, namespace=None, security_risk_ids=[]):
params = {"customerGUID": self.selected_tenant_id}

Expand Down Expand Up @@ -2902,17 +2910,122 @@ def get_seccomp_workloads_list(self, body: dict):
return r

def generate_seccomp_profile(self, body: dict):

r = self.post(API_SECCOMP_GENERATE, params={"customerGUID": self.customer_guid},
json=body, timeout=60)
if not 200 <= r.status_code < 300:
raise Exception(
'Error accessing dashboard. Request to: %s "%s" (code: %d, message: %s)' % (
API_SECCOMP_GENERATE, self.customer, r.status_code, r.text))
return r

def get_workflows(self, **kwargs):
url = API_WORKFLOWS + "/list"
params = {"customerGUID": self.selected_tenant_id}
if kwargs:
params.update(**kwargs)
r = self.post(url, params=params, json={"pageSize": 50, "pageNum": 1, "orderBy": "", "innerFilters":[]})
if not 200 <= r.status_code < 300:
raise Exception(
'Error accessing workflows. Customer: "%s" (code: %d, message: %s)' % (
self.customer, r.status_code, r.text))
return r.json()



def create_workflow(self, body):
url = API_WORKFLOWS
params = {"customerGUID": self.selected_tenant_id}
r = self.post(url, params=params, json=body)
if not 200 <= r.status_code < 300:
raise Exception(
'Error creating workflow. Customer: "%s" (code: %d, message: %s)' % (
self.customer, r.status_code, r.text))
return r.json()

def delete_workflow(self, guid):
url = API_WORKFLOWS
params = {"customerGUID": self.selected_tenant_id}
body = {
"innerFilters": [
{
"guid": guid
}
]
}
r = self.delete(url, params=params, json=body)
if not 200 <= r.status_code < 300:
raise Exception(
'Error deleting workflow. Customer: "%s" (code: %d, message: %s)' % (
self.customer, r.status_code, r.text))
return r.json()



def update_workflow(self, body):
url = API_WORKFLOWS
params = {"customerGUID": self.selected_tenant_id}
r = self.put(url, params=params, json=body)
if not 200 <= r.status_code < 300:
raise Exception(
'Error updating workflow. Customer: "%s" (code: %d, message: %s)' % (
self.customer, r.status_code, r.text))
return r.json()

def get_webhooks(self):
url = API_WEBHOOKS
r = self.get(url, params={"customerGUID": self.selected_tenant_id})
if not 200 <= r.status_code < 300:
raise Exception(
'Error accessing webhooks. Customer: "%s" (code: %d, message: %s)' % (
self.customer, r.status_code, r.text))
return r.json()


def create_webhook(self, body):
url = API_WEBHOOKS
params = {"customerGUID": self.selected_tenant_id}
r = self.post(url, params=params, json=body)
if not 200 <= r.status_code < 300:
raise Exception(
'Error creating webhook. Customer: "%s" (code: %d, message: %s)' % (
self.customer, r.status_code, r.text))
return r.json()

def delete_webhook(self, body):
url = API_WEBHOOKS
params = {"customerGUID": self.selected_tenant_id}
r = self.delete(url, params=params, body=body)
if not 200 <= r.status_code < 300:
raise Exception(
'Error deleting webhook. Customer: "%s" (code: %d, message: %s)' % (
self.customer, r.status_code, r.text))
return r.json()

def update_webhook(self, body):
url = API_WEBHOOKS
params = {"customerGUID": self.selected_tenant_id}
r = self.put(url, params=params, json=body)
if not 200 <= r.status_code < 300:
raise Exception(
'Error updating webhook. Customer: "%s" (code: %d, message: %s)' % (
self.customer, r.status_code, r.text))
return r.json()

def test_webhook_message(self, body):
params = {"customerGUID": self.selected_tenant_id}
r = self.post(API_TEAMS_TEST_MESSAGE, params=params, json=body)
if not 200 <= r.status_code < 300:
raise Exception(
'Error testing webhook. Customer: "%s" (code: %d, message: %s)' % (
self.customer, r.status_code, r.text))
return r.json()







class Solution(object):
"""docstring for Solution"""

Expand Down
65 changes: 46 additions & 19 deletions system_test_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@
"skip_on_environment": "",
"owner": ""
},

"scan_local_file": {
"target": [
"CLI"
Expand Down Expand Up @@ -801,7 +800,7 @@
"skip_on_environment": "",
"owner": "[email protected]"
},
"smart_remediation_all_controls":{
"smart_remediation_all_controls": {
"target": [
"In cluster",
"Backend"
Expand Down Expand Up @@ -1380,7 +1379,7 @@
"users-notification-service"
],
"description": "testing teams alert channels with compliance and vulnerabilities notifications",
"skip_on_environment": "production,production-us",
"skip_on_environment": "staging",
"owner": ""
},
"slack_alerts": {
Expand All @@ -1394,7 +1393,7 @@
"users-notification-service"
],
"description": "testing slack alert channels with compliance and vulnerabilities notifications",
"skip_on_environment": "production,production-us,custom",
"skip_on_environment": "staging",
"owner": "[email protected]"
},
"sr_r_0035_attack_chain": {
Expand Down Expand Up @@ -1625,32 +1624,60 @@
"skip_on_environment": "",
"owner": "[email protected]"
},
"slack_alerts_workflows": {
"slack_notifications_workflows": {
"target": [
"Backend"
],
"target_repositories": [
"users-notification-service-dummy",
"config-service-dummy",
"cadashboardbe-dummy",
"event-ingester-service-dummy"
"users-notification-service",
"config-service",
"cadashboardbe",
"event-ingester-service"
],
"description": "Checks slack workflows",
"skip_on_environment": "",
"description": "Checks workflows slack notifications",
"skip_on_environment": "production,production-us",
"owner": "[email protected]"
},
"teams_alerts_workflows": {
"teams_notifications_workflows": {
"target": [
"Backend"
],
"target_repositories": [
"users-notification-service-dummy",
"config-service-dummy",
"cadashboardbe-dummy",
"event-ingester-service-dummy"
"users-notification-service",
"config-service",
"cadashboardbe",
"event-ingester-service"
],
"description": "Checks teams workflows",
"skip_on_environment": "",
"description": "Checks workflows teams notifications",
"skip_on_environment": "production,production-us",
"owner": "[email protected]"
},
"jira_notifications_workflows": {
"target": [
"Backend"
],
"target_repositories": [
"users-notification-service",
"config-service",
"cadashboardbe",
"event-ingester-service"
],
"description": "Checks workflows jira notifications",
"skip_on_environment": "production,production-us",
"owner": "[email protected]"
},
"workflows_configurations": {
"target": [
"Backend"
],
"target_repositories": [
"users-notification-service",
"config-service",
"cadashboardbe",
"event-ingester-service"
],
"description": "Checks workflows configurations",
"skip_on_environment": "production,production-us",
"owner": "[email protected]"
}
}
}
Loading