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

E2E Tests with PyTest Infrastructure and Framework #725

Draft
wants to merge 122 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
c28ab9d
wip: basic opal server started
tobihans Oct 15, 2024
913451b
wip: gather all settings
tobihans Oct 16, 2024
d76deef
feat: generate client token from master token
tobihans Oct 16, 2024
f0129c4
feat: basic opal client container
tobihans Oct 16, 2024
4bff727
wip: interconnect opal client & server
tobihans Oct 17, 2024
66f9f5c
feat: interconnect containers in a custom network
tobihans Oct 18, 2024
6ec1a40
feat: use the same random id for all components
tobihans Oct 18, 2024
b296086
chore: savepoint
tobihans Oct 19, 2024
bcbdd19
feat: refactor debug statements
tobihans Oct 25, 2024
ff890dd
wip: ensure communication passes
tobihans Oct 29, 2024
534c815
feat: cleanup in preparation of WIP PR
tobihans Oct 29, 2024
19a65f2
chore: format
tobihans Oct 31, 2024
74cf12c
chore: add a sample .env to override variables
tobihans Oct 31, 2024
c75d064
Setup
iwphonedo Nov 5, 2024
470c9b6
Co-authored-by: Ari Weinberg <[email protected]>
iwphonedo Nov 6, 2024
a9e8f8c
Added sample flask service and nginx
iwphonedo Nov 6, 2024
ccbce6c
Enable debugging and improve authorization logic
iwphonedo Nov 11, 2024
18d5709
Integrate Gitea for local policy management
iwphonedo Nov 12, 2024
e5a0cff
Update OPAL policy repo URL
iwphonedo Nov 12, 2024
0c2e4d4
new file: CODE_OF_CONDUCT.md
ariWeinberg Nov 14, 2024
ee71d1a
Optimize OPAL server config and enable debugging
iwphonedo Nov 18, 2024
7946f79
Supporting debugging in containers, fixed networking issue, convertin…
iwphonedo Nov 25, 2024
1a5ee95
install opal-client and opal-server cli during execution
iwphonedo Nov 25, 2024
7055cc6
trying to delete test branches from github
iwphonedo Nov 25, 2024
0b9196f
compose env config
ariWeinberg Nov 29, 2024
eb51efb
new file: tests/run.sh
ariWeinberg Dec 3, 2024
0e25845
ari-tests, added docer environment creation by python
ariWeinberg Dec 16, 2024
6918243
new file: .gitignore
ariWeinberg Dec 16, 2024
0d2f3d4
fix
ariWeinberg Dec 16, 2024
0991e62
deleted: ari/gitea.py
ariWeinberg Dec 17, 2024
9a2c358
modified: .gitignore
ariWeinberg Dec 17, 2024
be31d32
modified: .gitignore
ariWeinberg Dec 17, 2024
883cf9d
modified: .gitignore
ariWeinberg Dec 18, 2024
45d1a44
modified: .gitignore
ariWeinberg Dec 18, 2024
a85396f
modified: new_pytest_env/gitea_docker_py.py
ariWeinberg Dec 18, 2024
6712ed0
a
ariWeinberg Dec 18, 2024
2689a6b
a
ariWeinberg Dec 18, 2024
f930464
Update .gitignore and launch configuration; modify test user location…
iwphonedo Dec 18, 2024
6848bc6
Add RBAC policy to restrict access based on user location
iwphonedo Dec 18, 2024
291e1fa
Update Gitea API token and add repository initialization script
iwphonedo Dec 18, 2024
56fecad
modified: new_pytest_env/gitea_docker_py.py
ariWeinberg Dec 18, 2024
0fb0cf0
modified: new_pytest_env/gitea_docker_py.py
ariWeinberg Dec 18, 2024
ef97acb
gitea_access_token via code
ariWeinberg Dec 18, 2024
c69f75e
init_repo.py create a repo
ariWeinberg Dec 18, 2024
3b78b06
check if repo exists before creating it
ariWeinberg Dec 18, 2024
d899521
Refactor access token creation to streamline code and remove unnecess…
iwphonedo Dec 18, 2024
3f99208
Merge branch 'new_pytest' of https://github.com/iwphonedo/opal into n…
iwphonedo Dec 18, 2024
4ce6b86
init_repo.py: clone the repo after making sure it exists (or creating…
ariWeinberg Dec 18, 2024
7a93a61
Merge branch 'new_pytest' of https://github.com/iwphonedo/opal into n…
ariWeinberg Dec 18, 2024
fd57429
init_repo.py: check if repo exists (create if not), clone, update, co…
ariWeinberg Dec 19, 2024
e5e00f7
manual cleanup (before rewriting the code to use a more orgenized fil…
ariWeinberg Dec 19, 2024
e3cefc1
what's in this commit?
ariWeinberg Dec 19, 2024
e3c5035
modified: new_pytest_env/gitea_branch_update.py
ariWeinberg Dec 23, 2024
7c66ec9
finished file orgenization and cleanup
ariWeinberg Dec 23, 2024
7275888
create brodcast channel (not used yet)
ariWeinberg Dec 23, 2024
c1192b7
fixed data-policy test loop
ariWeinberg Dec 23, 2024
bf02357
conditionally prepare broadcast in main function
iwphonedo Dec 23, 2024
d6a7ab4
refactor: update broadcast variable names and paths, adjust settings
iwphonedo Dec 24, 2024
58334f1
removed unnecessary comments
ariWeinberg Dec 24, 2024
019e2a3
set default polling interval to 10 sec
ariWeinberg Dec 24, 2024
ac44b10
merging pytest
ariWeinberg Dec 24, 2024
320e0af
Merge branch 'additions-to-tests' into pytest
ariWeinberg Dec 24, 2024
4c4fd48
Merge branch 'new_pytest' into pytest
ariWeinberg Dec 24, 2024
de6b9bb
fixing mistakenly resolved
ariWeinberg Dec 24, 2024
8711c3c
Merge remote-tracking branch 'Remote/pytest' into pytest
ariWeinberg Dec 24, 2024
3f3e0a4
fix polling interval
ariWeinberg Dec 24, 2024
37fa272
started moving to pytest and testContainers
ariWeinberg Dec 25, 2024
89ca06c
finished gitea test container
ariWeinberg Dec 25, 2024
d4cb9de
mooved opal_server to pytest.
ariWeinberg Dec 25, 2024
7424f8d
refactor: restructure test environment and remove deprecated files
iwphonedo Dec 26, 2024
50fdfb5
refactor: update logging in OpalServerContainer and add GiteaSettings…
iwphonedo Dec 26, 2024
815c25b
feat: add Docker support with devcontainer configuration and settings…
iwphonedo Dec 26, 2024
af7a564
fix: update Gitea repository URL to use dynamic port and enhance Opal…
iwphonedo Dec 26, 2024
b9f1bfc
refactor: enhance GiteaContainer setup with additional labels and lif…
ariWeinberg Dec 26, 2024
da549b9
opal_client_container: network as param (not network name)
ariWeinberg Dec 27, 2024
5f19a41
refactor: update import paths in broadcast and opal client containers
ariWeinberg Dec 27, 2024
f7411f1
refactor: enhance test container setup with network integration and s…
ariWeinberg Dec 27, 2024
611ffbc
refactor: remove deprecated files and update OpalClientSettings for i…
ariWeinberg Dec 27, 2024
f6fb0c7
refactor: clean up test code by removing print statements and increas…
ariWeinberg Dec 27, 2024
a8b8968
Merge branch 'master' of https://github.com/iwphonedo/opal into pytest
iwphonedo Dec 27, 2024
7e6d818
refactor: suppress pip install output and enhance user location publi…
ariWeinberg Dec 29, 2024
dfb71e9
deleted: tests/opal-example-policy-repo
ariWeinberg Dec 29, 2024
1ed6a7a
Merge branch 'pytest' of https://github.com/iwphonedo/opal into pytest
ariWeinberg Dec 29, 2024
71a1869
refactor: integrate PermitContainer into various container classes fo…
ariWeinberg Dec 29, 2024
a5e839b
refactor: enhance container settings and error logging, and improve p…
iwphonedo Dec 30, 2024
99d8667
refactor: update OPAL server URL configuration and enhance data publi…
ariWeinberg Dec 30, 2024
9a61ba6
refactor: correct logger variable name, enhance broadcast container n…
iwphonedo Dec 30, 2024
01c7c65
Merge branch 'pytest' of https://github.com/iwphonedo/opal into pytest
iwphonedo Dec 30, 2024
5931938
refactor: remove obsolete opal-example-policy-repo subproject
iwphonedo Dec 30, 2024
dc37fc4
refactor: comment out log line in PermitContainer for cleaner output
ariWeinberg Dec 30, 2024
7011211
refactor: update publish_data_user_location command to use server URL…
ariWeinberg Dec 30, 2024
b80572c
refactor: update Dockerfile to include gcc and python3-dev, and adjus…
iwphonedo Dec 30, 2024
0b42ae0
Merge branch 'pytest' of https://github.com/iwphonedo/opal into pytest
iwphonedo Dec 30, 2024
0762976
refactor: update PermitContainer log checking logic and remove unnece…
iwphonedo Dec 30, 2024
56cd7c0
refactor: enhance test fixtures and update log waiting logic for impr…
iwphonedo Dec 30, 2024
3baa266
refactor: update publish_data_user_location and data_publish_and_test…
ariWeinberg Dec 30, 2024
7d50884
refactor: correct image assignment in opal_client fixture for clarity
ariWeinberg Dec 30, 2024
1e0d211
refactor: add Docker image build fixtures for testing and enhance wai…
iwphonedo Dec 30, 2024
bf19686
Merge branch 'pytest' of https://github.com/iwphonedo/opal into pytest
iwphonedo Dec 30, 2024
7f9335d
feat: add new container classes and scripts for OPAL key generation a…
iwphonedo Jan 1, 2025
8e78292
refactor: enhance GithubPolicyRepo to manage SSH keys and repository …
iwphonedo Jan 1, 2025
55ba98f
refactor: remove unnecessary whitespace and add abstract methods for …
iwphonedo Jan 1, 2025
4b6e831
refactor: simplify subprocess calls for opal-server and opal-client i…
ariWeinberg Jan 1, 2025
f2d7c28
refactor: update policy repo factory to accept temporary directory an…
iwphonedo Jan 1, 2025
0e0d2d3
refactor: add environment variable for target repository name in Gith…
iwphonedo Jan 1, 2025
cf212c5
refactor: update policy_repo fixture to accept temporary directory pa…
iwphonedo Jan 1, 2025
fa7c0c5
refactor: enhance GithubPolicyRepo with webhook setup and improve pol…
ariWeinberg Jan 1, 2025
ec23fee
Merge remote-tracking branch 'israelw/setup' into pytest
iwphonedo Jan 1, 2025
f4f1509
test: add initial tests for OpalServerConfig and enhance policy repo …
iwphonedo Jan 1, 2025
6cd8830
refactor: update GitHub PAT environment variable handling in TestSett…
iwphonedo Jan 1, 2025
b4fe351
refactor: remove GitHub PAT from HTTPS URL construction in GithubPoli…
ariWeinberg Jan 1, 2025
8a6fcff
refactor: update OPA and Cedar container settings, enhance test cases…
iwphonedo Jan 1, 2025
1c755cc
refactor: replace TestSettings with pytest_settings and conditionally…
iwphonedo Jan 1, 2025
5fafdfa
refactor: update import statements in opal_server_settings.py to use …
iwphonedo Jan 1, 2025
24a5747
refactor: update import statement in opal_server_settings.py to impor…
iwphonedo Jan 1, 2025
82ff340
refactor: update webhook setting variable name for consistency and cl…
iwphonedo Jan 1, 2025
83ac9b7
refactor: enhance logging in PermitContainer and update Gitea and Git…
ariWeinberg Jan 2, 2025
59fa849
refactor: update logging levels to debug in various containers and ch…
ariWeinberg Jan 3, 2025
e4b45e1
refactor: correct variable name in assertion for container log connec…
ariWeinberg Jan 3, 2025
eea4e25
refactor: rename test functions for consistency and clarity
ariWeinberg Jan 3, 2025
61ebec9
refactor: remove deprecated Dockerfile, update devcontainer configura…
iwphonedo Jan 3, 2025
e5f9525
Merge branch 'pytest' of https://github.com/iwphonedo/opal into pytest
iwphonedo Jan 3, 2025
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
25 changes: 25 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye",
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
80 changes: 42 additions & 38 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
# Byte-compiled / optimized / DLL files
# OPAL specific
opal_test_keys/*
.env
opal-example-policy-repo/*
data/
OPAL_DATASOURCE_TOKEN.tkn
OPAL_CLIENT_TOKEN.tkn

# Temporary and Python cache files
**/*.pyc
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Virtual environments
.venv/
venv/
env/
ENV/
env.bak/
venv.bak/

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
Expand All @@ -18,7 +34,6 @@ lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
Expand All @@ -27,16 +42,14 @@ share/python-wheels/
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# PyInstaller
*.manifest
*.spec

# Unit test / coverage reports
htmlcov/
.tox/
Expand All @@ -50,22 +63,23 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
new_pytest_env/temp

# Translations
*.mo
*.pot

# Django stuff:
# Django
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
# Flask
instance/
.webassets-cache

# Scrapy stuff:
# Scrapy
.scrapy

# Sphinx documentation
Expand All @@ -84,53 +98,43 @@ ipython_config.py
# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
# Pipenv
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
# PEP 582
__pypackages__/

# Celery stuff
# Celery
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
# SageMath
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Editors
.vscode/
.idea
*.iml

# Spyder project settings
# Spyder
.spyderproject
.spyproject

# Rope project settings
# Rope
.ropeproject

# mkdocs documentation
/site
# mkdocs
docs/_build/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
# Pyre
.pyre/

# editors
.vscode/
.idea
*.iml

# System files
.DS_Store
pytest_6dbc.env
tests/pytest_1a09.env
40 changes: 40 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Remote to local",
"type": "debugpy",
"request": "attach",
"justMyCode": false,
"subProcess": true,
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "${cwd}"
}
]
},
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Python: Debug with Args",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"args": [
"--deploy",
"--with_broadcast",
],
"console": "integratedTerminal"
}
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"cmake.ignoreCMakeListsMissing": true,
"makefile.configureOnOpen": false,
"python.analysis.extraPaths": [
"./packages/opal-common"
]
}
25 changes: 17 additions & 8 deletions app-tests/docker-compose-app-tests.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
env_file:
- path: ./.env
required: false

services:
broadcast_channel:
image: postgres:alpine
Expand All @@ -7,15 +11,19 @@ services:
- POSTGRES_PASSWORD=postgres

opal_server:
image: permitio/opal-server:${OPAL_IMAGE_TAG:-latest}
#image: permitio/opal-server:${OPAL_IMAGE_TAG:-latest}
build:
context: ../ # Point to the directory containing your Dockerfile
dockerfile: ./docker/Dockerfile.server # Specify your Dockerfile if it's not named 'Dockerfile'
deploy:
mode: replicated
replicas: 2
replicas: 1
endpoint_mode: vip
environment:
- OPAL_BROADCAST_URI=postgres://postgres:postgres@broadcast_channel:5432/postgres
- UVICORN_NUM_WORKERS=4
- OPAL_POLICY_REPO_URL=${OPAL_POLICY_REPO_URL:[email protected]:permitio/opal-tests-policy-repo.git}
- UVICORN_NUM_WORKERS=0
#- OPAL_POLICY_REPO_URL=${OPAL_POLICY_REPO_URL:[email protected]:permitio/opal-tests-policy-repo.git}
- OPAL_POLICY_REPO_URL=${OPAL_POLICY_REPO_URL:[email protected]:permitio/opal-example-policy-repo.git}
- OPAL_POLICY_REPO_MAIN_BRANCH=${POLICY_REPO_BRANCH}
- OPAL_POLICY_REPO_SSH_KEY=${OPAL_POLICY_REPO_SSH_KEY}
- OPAL_DATA_CONFIG_SOURCES={"config":{"entries":[{"url":"http://opal_server:7002/policy-data","config":{"headers":{"Authorization":"Bearer ${OPAL_CLIENT_TOKEN}"}},"topics":["policy_data"],"dst_path":"/static"}]}}
Expand All @@ -35,9 +43,10 @@ services:

opal_client:
image: permitio/opal-client:${OPAL_IMAGE_TAG:-latest}
scale: 0
deploy:
mode: replicated
replicas: 2
replicas: 0
endpoint_mode: vip
environment:
- OPAL_SERVER_URL=http://opal_server:7002
Expand All @@ -50,9 +59,9 @@ services:
- OPAL_AUTH_JWT_AUDIENCE=https://api.opal.ac/v1/
- OPAL_AUTH_JWT_ISSUER=https://opal.ac/
- OPAL_STATISTICS_ENABLED=true
ports:
- "7766-7767:7000"
- "8181-8182:8181"
#ports:
# - "7766-7767:7000"
# - "8181-8182:8181"
depends_on:
- opal_server
command: sh -c "exec ./wait-for.sh opal_server:7002 --timeout=20 -- ./start.sh"
1 change: 1 addition & 0 deletions app-tests/jwks_dir/jwks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"keys": [{"kty": "RSA", "key_ops": ["verify"], "n": "0F2lT_erlBtvBBC6vIndXjlf15fuew9vKc5ftZ3kWs_s00FCTGQ0QU0tsuqpvBBxDLUJLT7LSXhiNUiAx4JOJ25W11lO5XGsiXxHZVkqEv6CxmFBA1PYjUSzi3Lj2q6eODr-d4wmzBDamuQ3rWYaNA7tPofp-ZapqBb2snW0tkBH5qYrtfklRbsPgx_EsCKhiYXtMjfqcMTulZo6eljb0KBxCXLzxLNoRQ6JmkqJZULZiMuw7JgTyFyrQpID4Mqtcv4d5cZFUwawwRdZwZlroQd4ewezbZpJwZGD3u_-nv0LUXuMnvBiVd9-uOFOtn1ok2VX4PC7y1pE9TEVseTMnF9cF3cLPqtVtzKk6lHvHh9NPZiFt5aJrMT-K5L8-d7sxEN1hF5Yb0Y4R5ydu2dtsxCrodkfI1RGiGrwhDi7GsBep_BrEeFCjtH-S9MIhYCCu0VRQKc5xpjrlHH6v2EbL2keJrUt6764yLAvUywVt_DKeDBEBtY6uBRCnUwPMFH6x2Xm1sgOOUWALoK1LDG-XW6cZWXigzLeU2u2a-xgJXbAX9TbPyVwxA-7OlM32flNH3ZJdl-Xp0BpuNxP_idHHXdvzYU9-tFf4NrNL_QBfmV2T5wzVBL4dsmlk3B1qbTwq1HVUUZB8R5WpsZehCQkhBsR95nPJq0msMro99sflJk", "e": "AQAB"}]}
Loading