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 1 commit
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
53 changes: 43 additions & 10 deletions configurations/system/tests_cases/workflows_tests.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,64 @@
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=WorkflowsSlack,
create_test_tenant = True
)
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=WorkflowsJiraNotifications,
# deployments=join(DEFAULT_WORKFLOWS_DEPLOYMENT_PATH, "http"),
# deployments1=join(DEFAULT_WORKFLOWS_DEPLOYMENT_PATH, "http1"),
# # getMessagesFunc=, // TODO: implement this function
# # enrichAlertChannelFunc=, // TODO: implement this function
# 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
51 changes: 51 additions & 0 deletions configurations/workflows_notifications/slack-alert-channel.json
jnathangreeg marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"channel": {
"name": "My Slack Channel",
"provider": "slack",
"context": {
"channel": {
"id": "abcd1234"
}
}
},
"notifications": [
{
"notificationType": "securityRiskPush:newSecurityRisk",
"disabled": false,
"parameters": {
"minSeverity": 300
}
},
{
"notificationType": "push:newClusterAdmin",
"disabled": false
},
{
"notificationType": "containerScanPush:newVulnerability",
"disabled": false,
"parameters": {
"minSeverity": 500
}
},
{
"notificationType": "containerScanPush:vulnerabilityNewFix",
"disabled": false,
"parameters": {
"minSeverity": 500
}
},
{
"notificationType": "push:complianceDrift",
"disabled": false,
"parameters": {
"driftPercentage": 15
}
}
],
"scope": [
{
"cluster": "cluster",
"namespaces": ["alerts"]
}
]
}
52 changes: 52 additions & 0 deletions configurations/workflows_notifications/teams-alert-channel.json
jnathangreeg marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"channel": {
"name": "My Teams Channel",
"provider": "teams",
"context": {
"webhook": {
"name": "webhook",
"id": "https://teams/mywebhook"
}
}
},
"notifications": [
{
"notificationType": "securityRiskPush:newSecurityRisk",
"disabled": false,
"parameters": {
"minSeverity": 300
}
},
{
"notificationType": "push:newClusterAdmin",
"disabled": false
},
{
"notificationType": "containerScanPush:newVulnerability",
"disabled": false,
"parameters": {
"minSeverity": 500
}
},
{
"notificationType": "containerScanPush:vulnerabilityNewFix",
"disabled": false,
"parameters": {
"minSeverity": 500
}
},
{
"notificationType": "push:complianceDrift",
"disabled": false,
"parameters": {
"driftPercentage": 15
}
}
],
"scope": [
{
"cluster": "cluster",
"namespaces": ["alerts"]
}
]
}
117 changes: 115 additions & 2 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 @@ -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
Loading
Loading