-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into send-initial-statistics
- Loading branch information
Showing
57 changed files
with
1,060 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Run End-2-End Tests | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Start django-mysql | ||
working-directory: ./sample-apps/django-mysql | ||
run: | | ||
docker compose -f docker-compose.yml -f docker-compose.benchmark.yml up --build -d | ||
- name: Start django-mysql-gunicorn | ||
working-directory: ./sample-apps/django-mysql-gunicorn | ||
run: | | ||
docker compose -f docker-compose.yml -f docker-compose.benchmark.yml up --build -d | ||
- name: Start flask-mongo | ||
working-directory: ./sample-apps/flask-mongo | ||
run: | | ||
docker compose -f docker-compose.yml -f docker-compose.benchmark.yml up --build -d | ||
- name: Start flask-mysql | ||
working-directory: ./sample-apps/flask-mysql | ||
run: | | ||
docker compose -f docker-compose.yml -f docker-compose.benchmark.yml up --build -d | ||
- name: Start flask-mysql-uwsgi | ||
working-directory: ./sample-apps/flask-mysql-uwsgi | ||
run: | | ||
docker compose -f docker-compose.yml -f docker-compose.benchmark.yml up --build -d | ||
- name: Start flask-postgres | ||
working-directory: ./sample-apps/flask-postgres | ||
run: | | ||
docker compose -f docker-compose.yml -f docker-compose.benchmark.yml up --build -d | ||
- name: Start flask-postgres-xml | ||
working-directory: ./sample-apps/flask-postgres-xml | ||
run: | | ||
docker compose -f docker-compose.yml -f docker-compose.benchmark.yml up --build -d | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
make install | ||
- name: Run end2end tests | ||
run: | | ||
make end2end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Exports extract_data_from_xml_body helper function""" | ||
|
||
import aikido_firewall.context as ctx | ||
|
||
|
||
def extract_data_from_xml_body(user_input, root_element): | ||
"""Extracts all attributes from the xml and adds them to context""" | ||
context = ctx.get_current_context() | ||
if not isinstance(context.body, str) or user_input != context.body: | ||
return | ||
|
||
extracted_xml_attrs = context.xml | ||
for el in root_element: | ||
print(extracted_xml_attrs) | ||
for k, v in el.items(): | ||
print("Key : %s, Value : %s", k, v) | ||
if not extracted_xml_attrs.get(k): | ||
extracted_xml_attrs[k] = set() | ||
extracted_xml_attrs[k].add(v) | ||
context.set_as_current_context() |
110 changes: 110 additions & 0 deletions
110
aikido_firewall/helpers/extract_data_from_xml_body_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import pytest | ||
from unittest.mock import MagicMock | ||
import aikido_firewall.context as ctx | ||
from .extract_data_from_xml_body import ( | ||
extract_data_from_xml_body, | ||
) # Replace 'your_module' with the actual module name | ||
|
||
|
||
@pytest.fixture | ||
def mock_context(): | ||
"""Fixture to mock the context.""" | ||
mock_ctx = MagicMock() | ||
mock_ctx.body = "valid_input" | ||
mock_ctx.xml = {} # Initialize with an empty dictionary | ||
ctx.get_current_context = MagicMock(return_value=mock_ctx) | ||
return mock_ctx | ||
|
||
|
||
def test_extract_data_from_xml_body_valid_input(mock_context): | ||
"""Test with valid user input and root_element.""" | ||
user_input = "valid_input" | ||
root_element = [ | ||
{"attr1": "value1", "attr2": "value2"}, | ||
{"attr1": "value3", "attr3": "value4"}, | ||
] | ||
|
||
extract_data_from_xml_body(user_input, root_element) | ||
|
||
assert mock_context.xml == { | ||
"attr1": {"value1", "value3"}, | ||
"attr2": {"value2"}, | ||
"attr3": {"value4"}, | ||
} | ||
|
||
|
||
def test_extract_data_from_xml_body_invalid_user_input(mock_context): | ||
"""Test with invalid user input.""" | ||
user_input = "invalid_input" | ||
root_element = [{"attr1": "value1"}] | ||
|
||
extract_data_from_xml_body(user_input, root_element) | ||
|
||
assert mock_context.xml == {} | ||
|
||
|
||
def test_extract_data_from_xml_body_empty_root_element(mock_context): | ||
"""Test with an empty root_element.""" | ||
user_input = "valid_input" | ||
root_element = [] | ||
|
||
extract_data_from_xml_body(user_input, root_element) | ||
|
||
assert mock_context.xml == {} | ||
|
||
|
||
def test_extract_data_from_xml_body_non_string_context_body(mock_context): | ||
"""Test with non-string context body.""" | ||
mock_context.body = 123 # Set body to a non-string value | ||
user_input = "valid_input" | ||
root_element = [{"attr1": "value1"}] | ||
|
||
extract_data_from_xml_body(user_input, root_element) | ||
|
||
assert mock_context.xml == {} | ||
|
||
|
||
def test_extract_data_from_xml_body_multiple_calls(mock_context): | ||
"""Test multiple calls with the same user input.""" | ||
user_input = "valid_input" | ||
root_element1 = [{"attr1": "value1"}] | ||
root_element2 = [{"attr1": "value2"}] | ||
|
||
extract_data_from_xml_body(user_input, root_element1) | ||
extract_data_from_xml_body(user_input, root_element2) | ||
|
||
assert mock_context.xml == {"attr1": {"value1", "value2"}} | ||
|
||
|
||
def test_extract_data_from_xml_body_duplicate_attributes(mock_context): | ||
"""Test with duplicate attributes in root_element.""" | ||
user_input = "valid_input" | ||
root_element = [ | ||
{"attr1": "value1"}, | ||
{"attr1": "value1"}, # Duplicate | ||
{"attr2": "value2"}, | ||
] | ||
|
||
extract_data_from_xml_body(user_input, root_element) | ||
|
||
assert mock_context.xml == {"attr1": {"value1"}, "attr2": {"value2"}} | ||
|
||
|
||
def test_extract_data_from_xml_body_no_attributes(mock_context): | ||
"""Test with elements that have no attributes.""" | ||
user_input = "valid_input" | ||
root_element = [{}] | ||
|
||
extract_data_from_xml_body(user_input, root_element) | ||
|
||
assert mock_context.xml == {} | ||
|
||
|
||
def test_extract_data_from_xml_body_context_set_as_current(mock_context): | ||
"""Test if context.set_as_current_context is called.""" | ||
user_input = "valid_input" | ||
root_element = [{"attr1": "value1"}] | ||
|
||
extract_data_from_xml_body(user_input, root_element) | ||
|
||
mock_context.set_as_current_context.assert_called_once() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.