Skip to content

Commit

Permalink
dab jwt proxy mock (#2148)
Browse files Browse the repository at this point in the history
add a new oci-env profile with a "jwt proxy" for testing the dab client code in CI.

No-Issue

Signed-off-by: James Tanner <[email protected]>
  • Loading branch information
jctanner authored May 28, 2024
1 parent 84dd94d commit c2d3502
Show file tree
Hide file tree
Showing 19 changed files with 528 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci_oci-env-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- TEST_PROFILE: iqe_rbac
- TEST_PROFILE: x_repo_search
- TEST_PROFILE: community
- TEST_PROFILE: dab_jwt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ gh-action/standalone:
gh-action/community:
python3 dev/oci_env_integration/actions/community.py

.PHONY: gh-action/dab_jwt
gh-action/dab_jwt:
python3 dev/oci_env_integration/actions/dab_jwt.py

.PHONY: gh-action/certified-sync
gh-action/certified-sync:
python3 dev/oci_env_integration/actions/certified-sync.py
Expand Down Expand Up @@ -309,3 +313,7 @@ oci/community:
.PHONY: oci/dab
oci/dab:
dev/oci_start dab

.PHONY: oci/dab_jwt
oci/dab_jwt:
dev/oci_start dab_jwt
17 changes: 12 additions & 5 deletions dev/oci_env_integration/actions/action_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,18 @@ def run_test(self):
time.sleep(wait_time)

if self.envs[env]["run_tests"]:
self.exec_cmd(
env,
"exec bash /src/galaxy_ng/profiles/base/run_integration.sh"
f" {pytest_flags} {self.flags}"
)
if self.envs[env].get("test_script"):
self.exec_cmd(
env,
f"exec bash {self.envs[env]['test_script']}"
f" {pytest_flags} {self.flags}"
)
else:
self.exec_cmd(
env,
"exec bash /src/galaxy_ng/profiles/base/run_integration.sh"
f" {pytest_flags} {self.flags}"
)

def dump_logs(self):
if not self.do_dump_logs:
Expand Down
12 changes: 12 additions & 0 deletions dev/oci_env_integration/actions/dab_jwt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import action_lib

env = action_lib.OCIEnvIntegrationTest(
envs=[
{
"env_file": "dab_jwt.compose.env",
"run_tests": True,
"db_restore": None,
"test_script": "/src/galaxy_ng/profiles/dab_jwt/run_integration.sh"
}
]
)
20 changes: 20 additions & 0 deletions dev/oci_env_integration/oci_env_configs/dab_jwt.compose.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
COMPOSE_PROFILE=galaxy_ng/base:galaxy_ng/dab_jwt
COMPOSE_PROJECT_NAME=ci-dab-proxy

DEV_SOURCE_PATH=galaxy_ng
COMPOSE_BINARY=docker
SETUP_TEST_DATA=0
UPDATE_UI=0
ENABLE_SIGNING=1
HUB_API_ROOT=http://jwtproxy:8080/api/galaxy

DJANGO_SUPERUSER_USERNAME=admin
DJANGO_SUPERUSER_PASSWORD=admin

PULP_GALAXY_API_PATH_PREFIX=/api/galaxy
PULP_ANALYTICS=false

# proxy config ...
API_PORT=5001
JWT_PROXY_PORT=8080

Empty file.
28 changes: 28 additions & 0 deletions galaxy_ng/tests/integration/dab/test_url_resolution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import pytest


@pytest.mark.deployment_standalone
@pytest.mark.skipif(
not os.getenv("ENABLE_DAB_TESTS"),
reason="Skipping test because ENABLE_DAB_TESTS is not set"
)
def test_dab_collection_download_url_hostnames(settings, galaxy_client, published):
"""
We want the download url to point at the gateway
"""
gc = galaxy_client("admin")
cv_url = 'v3/plugin/ansible/content/published/collections/index/'
cv_url += f'{published.namespace}/{published.name}/versions/{published.version}'
cv_info = gc.get(cv_url)
download_url = cv_info['download_url']
assert download_url.startswith(gc.galaxy_root)

# try to GET the tarball ...
dl_resp = gc.get(download_url, parse_json=False)
assert dl_resp.status_code == 200
assert dl_resp.headers.get('Content-Type') == 'application/gzip'

# make sure the final redirect was through the gateway ...
expected_url = gc.galaxy_root.replace('/api/galaxy/', '')
assert dl_resp.url.startswith(expected_url)
5 changes: 4 additions & 1 deletion galaxy_ng/tests/integration/utils/iqe_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,11 @@ def get_hub_version(ansible_config):
gc = GalaxyKitClient(ansible_config).gen_authorized_client(role)
except GalaxyError:
# FIXME: versions prior to 4.7 have different credentials. This needs to be fixed.
gc = GalaxyClient(galaxy_root="http://localhost:5001/api/automation-hub/",
api_root = os.environ.get("HUB_API_ROOT", "http://localhost:5001/api/automation-hub/")
api_root = api_root.rstrip("/") + "/"
gc = GalaxyClient(galaxy_root=api_root,
auth={"username": "admin", "password": "admin"})

return gc.get(gc.galaxy_root)["galaxy_ng_version"]


Expand Down
5 changes: 5 additions & 0 deletions profiles/dab_jwt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# galaxy_ng/dab

## Usage

This profile is used for running Galaxy NG with the JWT authentication integrations provided by django-ansible-base
12 changes: 12 additions & 0 deletions profiles/dab_jwt/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
services:
jwtproxy:
build:
context: "{SRC_DIR}/galaxy_ng/profiles/dab_jwt/proxy"
ports:
- "{JWT_PROXY_PORT}:{JWT_PROXY_PORT}"
environment:
UPSTREAM_URL: "http://pulp:{API_PORT}"
PROXY_PORT: "{JWT_PROXY_PORT}"
volumes:
- "{SRC_DIR}/galaxy_ng/profiles/dab_jwt/proxy:/app:rw"
1 change: 1 addition & 0 deletions profiles/dab_jwt/profile_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
galaxy_ng/base
9 changes: 9 additions & 0 deletions profiles/dab_jwt/proxy/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[build]
bin = "proxy"
cmd = "go build -o proxy proxy.go"
full_bin = "./proxy"

exclude_regex = ["*.swp"]

[run]
cmd = "./proxy"
9 changes: 9 additions & 0 deletions profiles/dab_jwt/proxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:alpine

# hot reloads ...
RUN go install github.com/cosmtrek/air@latest

RUN mkdir -p /app
WORKDIR /app

CMD ["air"]
8 changes: 8 additions & 0 deletions profiles/dab_jwt/proxy/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module mockproxy

go 1.16

require (
github.com/golang-jwt/jwt/v4 v4.4.1
github.com/google/uuid v1.6.0 // indirect
)
4 changes: 4 additions & 0 deletions profiles/dab_jwt/proxy/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/golang-jwt/jwt/v4 v4.4.1 h1:pC5DB52sCeK48Wlb9oPcdhnjkz1TKt1D/P7WKJ0kUcQ=
github.com/golang-jwt/jwt/v4 v4.4.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Loading

0 comments on commit c2d3502

Please sign in to comment.