-
-
Notifications
You must be signed in to change notification settings - Fork 171
Implement fuzztesting. #1139
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
Open
ahmedxgouda
wants to merge
65
commits into
OWASP:main
Choose a base branch
from
ahmedxgouda:feature/fuzz-testing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+420
−8
Open
Implement fuzztesting. #1139
Changes from 43 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
bc40efb
Add hypothesis to poetry and fuzz test the index endpoint.
ahmedxgouda 6c18da7
Refactor import statements in algolia_test.py for consistency
ahmedxgouda 4a17780
Add the client ip address to the request META.
ahmedxgouda 75aa9fe
Add fuzz testing for Slack event handlers and refactor algolia fuzz t…
ahmedxgouda 625cc0e
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda b078e92
Refactor fuzz tests for Slack event handlers to improve readability a…
ahmedxgouda f1f6718
Fix the poetry lock file.
ahmedxgouda c0ed1f9
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda 998bd29
Remove fuzz testing from algolia_search unit tests
ahmedxgouda 6b240b4
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda f060510
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda ab68f1a
Create a docker file for fuzz-testing, add the run commands to the Ma…
ahmedxgouda d1d48ea
Refactor to improve quality
ahmedxgouda 54f7fbe
Update fuzz testing setup: modify Makefile and Dockerfile, add entryp…
ahmedxgouda 12b5139
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda 21283f7
Update poetry.lock to reflect dependency changes and version updates
ahmedxgouda c47b9fd
Create a fuzz configuration, update docker file, makefile, and the te…
ahmedxgouda de81b25
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda 5f79854
Refactor fuzz configuration by reorganizing imports and cleaning up w…
ahmedxgouda 8330865
Update Dockerfile and entrypoint script to use Alpine base image and …
ahmedxgouda 1ed4452
Run the server on port 8000 after the tests.
ahmedxgouda dd36f25
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda 0a9068d
Create a docker compose file for fuzz testing.
ahmedxgouda c5363db
Add 'graphqler' to custom dictionary
ahmedxgouda ccc28c8
Load data from nest.json and add graphqler to cspell dict.
ahmedxgouda ef20adb
Remove model-bakery dependency from pyproject.toml and update poetry.…
ahmedxgouda 845e1c1
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda 8755056
Update graphqler command in docker compose and the healthcheck
ahmedxgouda 6637d8c
Update graphql command to use backend service URL in docker-compose
ahmedxgouda decec65
Refactor docker-compose to build graphqler service from Dockerfile an…
ahmedxgouda 672f097
Enhance fuzz testing setup: update Dockerfile and entrypoint scripts,…
ahmedxgouda ed62759
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda 49fa5f8
Update fuzz-test-backend command to abort on container exit
ahmedxgouda e1533ab
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda dcba769
Add fuzz testing workflow and update image build steps
ahmedxgouda 5e85b0b
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda 70312c5
Add .env file creation step for fuzz tests in CI/CD workflow
ahmedxgouda 751f105
Add Docker Hub login step for fuzz tests in CI/CD workflow
ahmedxgouda 4cb975a
Refactor for the checks
ahmedxgouda 47daeda
Refactor fuzz testing workflow: replace Docker Hub login with buildx …
ahmedxgouda 5e08107
Fix fuzz tests workflow: rename docker-compose file
ahmedxgouda de6bf2e
Refactor fuzz-tests job.
ahmedxgouda d908fcf
Add environment variables for fuzz tests configuration
ahmedxgouda d3f2987
Update fuzz tests environment variables
ahmedxgouda d3fd074
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda 7d5c20d
Resolve conflicts
ahmedxgouda 03ecb0c
Fix poetry lock file
ahmedxgouda cf07402
Sort the custom-dict.
ahmedxgouda e0459d4
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda 54ce26a
Update content hash in poetry.lock
ahmedxgouda deaf1d0
Add docker cache mounts to the backend image
ahmedxgouda 2236c73
Add Redis configuration
ahmedxgouda 8ada3b9
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda 013537b
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda 8ec969f
refactor yaml
ahmedxgouda 3839ef1
Add docker cache mounts to graphql file
ahmedxgouda f1e2c56
Remove unnecessary chmod command for cache directories in Dockerfile
ahmedxgouda 2fabe70
Merge branch 'main' into feature/fuzz-testing
ahmedxgouda 56acd52
Merge branch 'main' into 'feature/fuzz-testing'
ahmedxgouda a2436f5
Fix poetry lock file
ahmedxgouda 25b98f5
Add cache mounts to backend tests
ahmedxgouda eb8c087
Update cache mounts in graphql image
ahmedxgouda e27ce00
Update mkdir in graphql image
ahmedxgouda 8d8e3fe
Remove duplicates
ahmedxgouda 303f825
Update tests
ahmedxgouda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,62 @@ | ||
FROM python:3.13-alpine AS builder | ||
|
||
SHELL ["/bin/sh", "-o", "pipefail", "-c"] | ||
|
||
# Install necessary dependencies | ||
RUN apk update && apk upgrade && \ | ||
addgroup -S owasp && \ | ||
adduser -S -h /home/owasp -G owasp owasp && \ | ||
python -m pip install --no-cache-dir poetry | ||
|
||
ENV FORCE_COLOR=1 \ | ||
POETRY_VIRTUALENVS_IN_PROJECT=true \ | ||
PYTHONUNBUFFERED=1 | ||
|
||
WORKDIR /home/owasp | ||
USER owasp | ||
|
||
# Copy Poetry configuration and install dependencies | ||
COPY --chmod=444 poetry.lock pyproject.toml ./ | ||
RUN poetry install --no-root | ||
|
||
# Copy application files | ||
COPY apps apps | ||
COPY manage.py wsgi.py ./ | ||
COPY settings settings | ||
COPY static static | ||
COPY templates templates | ||
COPY fuzz_tests fuzz_tests | ||
COPY data data | ||
COPY fuzz_tests/.env .env | ||
COPY docker/entrypoint_fuzz.sh entrypoint.sh | ||
|
||
FROM python:3.13-alpine | ||
|
||
SHELL ["/bin/sh", "-o", "pipefail", "-c"] | ||
|
||
# Install runtime dependencies | ||
RUN addgroup -S owasp && \ | ||
adduser -S -h /home/owasp -G owasp owasp && \ | ||
mkdir -p /home/owasp && \ | ||
chown owasp:owasp /home/owasp | ||
|
||
ENV FORCE_COLOR=1 \ | ||
PATH="/home/owasp/.venv/bin:$PATH" \ | ||
PYTHONUNBUFFERED=1 | ||
|
||
WORKDIR /home/owasp | ||
USER owasp | ||
|
||
# Copy built application from the builder stage | ||
COPY --from=builder --chmod=555 --chown=owasp:owasp /home/owasp /home/owasp | ||
|
||
RUN touch /home/owasp/fuzz_tests.db && \ | ||
chmod +x /home/owasp/fuzz_tests.db /home/owasp/entrypoint.sh | ||
|
||
|
||
# Expose the running port | ||
EXPOSE 8000 | ||
|
||
# Run fuzz tests | ||
|
||
CMD ["/home/owasp/entrypoint.sh"] |
This file contains hidden or 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,25 @@ | ||
FROM python:3.12-alpine | ||
|
||
RUN apk update && apk upgrade && \ | ||
addgroup -S owasp && \ | ||
adduser -S -h /home/owasp -G owasp owasp | ||
|
||
RUN apk add --no-cache curl jq gcc musl-dev libffi-dev linux-headers | ||
RUN pip install --no-cache-dir graphqler | ||
|
||
WORKDIR /home/owasp | ||
|
||
COPY docker/entrypoint_graphql_fuzz.sh entrypoint.sh | ||
|
||
RUN touch /home/owasp/config.toml && \ | ||
chmod +x /home/owasp/config.toml && \ | ||
chown owasp:owasp /home/owasp/config.toml | ||
|
||
# Create the graphql output dir and give permissions to the owasp user | ||
RUN mkdir -p /home/owasp/fuzzing_results && \ | ||
chmod +x /home/owasp/fuzzing_results /home/owasp/entrypoint.sh && \ | ||
chown owasp:owasp /home/owasp/fuzzing_results | ||
|
||
USER owasp | ||
|
||
CMD ["/home/owasp/entrypoint.sh"] |
This file contains hidden or 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,11 @@ | ||
#!/bin/sh | ||
|
||
python manage.py migrate | ||
python manage.py collectstatic --noinput | ||
|
||
# Load initial data | ||
python manage.py load_data | ||
|
||
pytest fuzz_tests | ||
|
||
python manage.py runserver 0.0.0.0:8000 |
This file contains hidden or 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,24 @@ | ||
#!/bin/sh | ||
|
||
echo "Retrieving CSRF token..." | ||
|
||
CSRF_TOKEN=$(curl -s http://backend:8000/csrf/ | jq -r '.csrftoken') | ||
|
||
if [ -z "$CSRF_TOKEN" ]; then | ||
echo "Failed to retrieve CSRF token" | ||
exit 1 | ||
fi | ||
|
||
echo "CSRF token retrieved successfully: $CSRF_TOKEN" | ||
|
||
cat > /home/owasp/config.toml << EOF | ||
[CUSTOM_HEADERS] | ||
X-CSRF-Token = "$CSRF_TOKEN" | ||
EOF | ||
|
||
echo "Custom headers configuration file created successfully" | ||
|
||
sleep 5 | ||
|
||
echo "Starting fuzzing tests..." | ||
python -m graphqler --config /home/owasp/config.toml --url http://backend:8000/graphql/ --mode run --path /home/owasp/fuzzing_results |
Empty file.
Empty file.
This file contains hidden or 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,41 @@ | ||
"""Test Slack contribute event handler.""" | ||
|
||
from unittest.mock import MagicMock, patch | ||
|
||
from django.conf import settings | ||
from hypothesis import given | ||
from hypothesis import strategies as st | ||
|
||
from apps.slack.constants import ( | ||
OWASP_CONTRIBUTE_CHANNEL_ID, | ||
) | ||
from apps.slack.events.member_joined_channel.contribute import contribute_handler | ||
|
||
|
||
class TestContributeEventHandler: | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Test cases for the Contribute Slack event handler.""" | ||
|
||
@given( | ||
events_enabled=st.booleans(), | ||
project_count=st.integers(), | ||
issue_count=st.integers(), | ||
) | ||
@patch("apps.owasp.models.project.Project.active_projects_count") | ||
@patch("apps.github.models.issue.Issue.open_issues_count") | ||
def test_handler_responses( | ||
self, | ||
mock_open_issues_count, | ||
mock_active_projects_count, | ||
events_enabled, | ||
project_count, | ||
issue_count, | ||
): | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Test the contribute event handler responses.""" | ||
settings.SLACK_EVENTS_ENABLED = events_enabled | ||
mock_active_projects_count.return_value = project_count | ||
mock_open_issues_count.return_value = issue_count | ||
mock_slack_event = {"user": "U123456", "channel": OWASP_CONTRIBUTE_CHANNEL_ID} | ||
mock_slack_client = MagicMock() | ||
mock_slack_client.conversations_open.return_value = {"channel": {"id": "C123456"}} | ||
|
||
contribute_handler(event=mock_slack_event, client=mock_slack_client, ack=MagicMock()) |
This file contains hidden or 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,43 @@ | ||
"""Test cases for the GSOC Slack event handler.""" | ||
|
||
from unittest.mock import MagicMock | ||
|
||
from django.conf import settings | ||
from hypothesis import given | ||
from hypothesis import strategies as st | ||
|
||
from apps.slack.constants import OWASP_GSOC_CHANNEL_ID | ||
from apps.slack.events.member_joined_channel.gsoc import gsoc_handler | ||
|
||
|
||
class TestGsocEventHandler: | ||
"""Test cases for the GSOC Slack event handler.""" | ||
|
||
@given( | ||
channel_id=st.text(), | ||
) | ||
def test_check_gsoc_handler(self, channel_id): | ||
"""Test the check_gsoc_handler function.""" | ||
gsoc_module = __import__( | ||
"apps.slack.events.member_joined_channel.gsoc", | ||
fromlist=["gsoc_handler"], | ||
) | ||
check_gsoc_handler = getattr( | ||
gsoc_module, | ||
"check_gsoc_handler", | ||
lambda x: x.get("channel") == OWASP_GSOC_CHANNEL_ID, | ||
) | ||
|
||
check_gsoc_handler({"channel": channel_id}) | ||
|
||
@given( | ||
events_enabled=st.booleans(), | ||
) | ||
def test_handler_responses(self, events_enabled): | ||
"""Test the GSOC event handler responses.""" | ||
settings.SLACK_EVENTS_ENABLED = events_enabled | ||
mock_slack_event = {"user": "U123456", "channel": OWASP_GSOC_CHANNEL_ID} | ||
mock_slack_client = MagicMock() | ||
mock_slack_client.conversations_open.return_value = {"channel": {"id": "C123456"}} | ||
|
||
gsoc_handler(event=mock_slack_event, client=mock_slack_client, ack=MagicMock()) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don’t
touch
an empty config; copy real settings.Creating an empty
config.toml
leaves the fuzzing tool without its required configuration. Also, config files don’t need execute bits.Adjust source path to your repo structure.
📝 Committable suggestion
🤖 Prompt for AI Agents (early access)