Skip to content
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
32 changes: 32 additions & 0 deletions .github/workflows/test-build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,38 @@ jobs:
export TOX_SKIP_MISSING_INTERPRETERS="False";
tox -e py

e2e-tests:
runs-on: ubuntu-latest
env:
MITM_BASIC_AUTH_CONTAINER_NAME: e2e_test_mitm_basic_auth
MITM_CUSTOM_CERT_CONTAINER_NAME: e2e_test_mitm_custom_cert
DOCKER_NETWORK_NAME: e2e_test_docker_network
TEST_USER: integrations_testing
TEST_KEY: ${{ secrets.TEST_KEY }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install -r ./requirements/development.txt

- name: Setup E2E environment
run: |
sh ./tests/e2e/scripts/setup_e2e.sh

- name: Run E2E tests
run: |
python -m pytest -s --capture=sys -v --cov=domaintools tests/e2e

- name: Cleanup E2E environment
if: '!cancelled()'
run: |
sh ./tests/e2e/scripts/cleanup_e2e.sh

# run only in main and in pull request to `main` and in publish release
release-build:
if: |
Expand Down
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,44 @@ results = api.nod(sessionID="my-session-id", after=-7200)

for partial_result in results.response() # generator that holds NOD feeds data for the past 2 hours and is expected to request multiple times
# do things to partial_result
```
```


Running E2E Tests Locally
===================
For now, e2e tests only covers proxy and ssl testing. We are expected to broaden our e2e tests to other scenarios moving forward.
To add more e2e tests, put these in the `../tests/e2e` folder.

## Preparation
- Create virtual environment.
```bash
python3 -m venv venv
```

- Activate virtual environment
```bash
source venv/bin/activate
```

- Install dependencies.
```bash
pip install -r requirements/development.txt
```

- From the python_api project root directory, install the package.
```bash
pip install -e .
```

- Export api credentials to use.
```bash
export TEST_USER=<user-key>
export TEST_KEY=<api-key>
```

## Run the end-to-end test script
- Before running the test, be sure that docker is running.
- Execute the e2e test script .
```bash
sh tests/e2e/scripts/test_e2e_runner.sh
```
15 changes: 15 additions & 0 deletions tests/e2e/scripts/cleanup_e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Script Requirements
# docker

# Clean up containers
echo "Bringing down containers..."
docker stop ${MITM_BASIC_AUTH_CONTAINER_NAME} || true
docker stop ${MITM_CUSTOM_CERT_CONTAINER_NAME} || true
docker network rm ${DOCKER_NETWORK_NAME} || true

# Clean up custom certs
echo "Removing custom certs..."
sudo rm -rf tests/e2e/mitmproxy-ca.pem
sudo rm -rf ~/.test_mitmproxy
32 changes: 32 additions & 0 deletions tests/e2e/scripts/setup_e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Script Requirements
# docker

echo "Create a bridge network for the containers to communicate"
docker network create ${DOCKER_NETWORK_NAME}

echo "Spinning ${MITM_BASIC_AUTH_CONTAINER_NAME}"
docker run --rm -d \
--name ${MITM_BASIC_AUTH_CONTAINER_NAME} \
--network ${DOCKER_NETWORK_NAME} \
-p 8080:8080 mitmproxy/mitmproxy mitmdump \
--set proxyauth="username:pass"

echo "Spinning ${MITM_CUSTOM_CERT_CONTAINER_NAME}"
docker run --rm -d -v ~/.test_mitmproxy:/home/mitmproxy/.mitmproxy \
--name ${MITM_CUSTOM_CERT_CONTAINER_NAME} \
--network ${DOCKER_NETWORK_NAME} \
-p 8090:8090 mitmproxy/mitmproxy mitmdump \
--set listen_port=8090

# Check until custom cert from mitmproxy container is copied locally
echo "Checking for valid custom cert..."
while [ ! -f ~/.test_mitmproxy/mitmproxy-ca.pem ] ;
do
sleep 2
done
echo "Valid custom cert found!"

# Copy valid custom cert to target dir
docker cp ${MITM_CUSTOM_CERT_CONTAINER_NAME}:/home/mitmproxy/.mitmproxy/mitmproxy-ca.pem ./tests/e2e/mitmproxy-ca.pem
45 changes: 5 additions & 40 deletions tests/e2e/scripts/test_e2e_runner.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,15 @@
# Script Requirements
# docker

MITM_BASIC_AUTH_CONTAINER_NAME="e2e_test_mitm_basic_auth"
MITM_CUSTOM_CERT_CONTAINER_NAME="e2e_test_mitm_custom_cert"
DOCKER_NETWORK_NAME="e2e_test_docker_network"
export MITM_BASIC_AUTH_CONTAINER_NAME="e2e_test_mitm_basic_auth"
export MITM_CUSTOM_CERT_CONTAINER_NAME="e2e_test_mitm_custom_cert"
export DOCKER_NETWORK_NAME="e2e_test_docker_network"

echo "Starting e2e tests..."

echo "Create a bridge network for the containers to communicate"
docker network create ${DOCKER_NETWORK_NAME}

echo "Spinning ${MITM_BASIC_AUTH_CONTAINER_NAME}"
docker run --rm -d \
--name ${MITM_BASIC_AUTH_CONTAINER_NAME} \
--network ${DOCKER_NETWORK_NAME} \
-p 8080:8080 mitmproxy/mitmproxy mitmdump \
--set proxyauth="username:pass"

echo "Spinning ${MITM_CUSTOM_CERT_CONTAINER_NAME}"
docker run --rm -d -v ~/.test_mitmproxy:/home/mitmproxy/.mitmproxy \
--name ${MITM_CUSTOM_CERT_CONTAINER_NAME} \
--network ${DOCKER_NETWORK_NAME} \
-p 8090:8090 mitmproxy/mitmproxy mitmdump \
--set listen_port=8090

# Check until custom cert from mitmproxy container is copied locally
echo "Checking for valid custom cert..."
while [ ! -f ~/.test_mitmproxy/mitmproxy-ca.pem ] ;
do
sleep 2
done
echo "Valid custom cert found!"

# Copy valid custom cert to target dir
cp ~/.test_mitmproxy/mitmproxy-ca.pem tests/e2e/mitmproxy-ca.pem
sh ./tests/e2e/scripts/setup_e2e.sh

echo "E2E processing..."
python -m pytest -s --capture=sys -v --cov=domaintools tests/e2e

# Clean up containers
echo "Bringing down containers..."
docker stop ${MITM_BASIC_AUTH_CONTAINER_NAME} || true
docker stop ${MITM_CUSTOM_CERT_CONTAINER_NAME} || true
docker network rm ${DOCKER_NETWORK_NAME} || true

# Clean up custom certs
echo "Removing custom certs..."
rm -rf tests/e2e/mitmproxy-ca.pem
rm -rf ~/.test_mitmproxy
sh ./tests/e2e/scripts/cleanup_e2e.sh