Skip to content

Commit c2d3502

Browse files
authored
dab jwt proxy mock (#2148)
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 <tanner.jc@gmail.com>
1 parent 84dd94d commit c2d3502

File tree

19 files changed

+528
-6
lines changed

19 files changed

+528
-6
lines changed

.github/workflows/ci_oci-env-integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
- TEST_PROFILE: iqe_rbac
2525
- TEST_PROFILE: x_repo_search
2626
- TEST_PROFILE: community
27+
- TEST_PROFILE: dab_jwt
2728
runs-on: ubuntu-latest
2829
steps:
2930
- uses: actions/checkout@v4

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ gh-action/standalone:
142142
gh-action/community:
143143
python3 dev/oci_env_integration/actions/community.py
144144

145+
.PHONY: gh-action/dab_jwt
146+
gh-action/dab_jwt:
147+
python3 dev/oci_env_integration/actions/dab_jwt.py
148+
145149
.PHONY: gh-action/certified-sync
146150
gh-action/certified-sync:
147151
python3 dev/oci_env_integration/actions/certified-sync.py
@@ -309,3 +313,7 @@ oci/community:
309313
.PHONY: oci/dab
310314
oci/dab:
311315
dev/oci_start dab
316+
317+
.PHONY: oci/dab_jwt
318+
oci/dab_jwt:
319+
dev/oci_start dab_jwt

dev/oci_env_integration/actions/action_lib.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,18 @@ def run_test(self):
121121
time.sleep(wait_time)
122122

123123
if self.envs[env]["run_tests"]:
124-
self.exec_cmd(
125-
env,
126-
"exec bash /src/galaxy_ng/profiles/base/run_integration.sh"
127-
f" {pytest_flags} {self.flags}"
128-
)
124+
if self.envs[env].get("test_script"):
125+
self.exec_cmd(
126+
env,
127+
f"exec bash {self.envs[env]['test_script']}"
128+
f" {pytest_flags} {self.flags}"
129+
)
130+
else:
131+
self.exec_cmd(
132+
env,
133+
"exec bash /src/galaxy_ng/profiles/base/run_integration.sh"
134+
f" {pytest_flags} {self.flags}"
135+
)
129136

130137
def dump_logs(self):
131138
if not self.do_dump_logs:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import action_lib
2+
3+
env = action_lib.OCIEnvIntegrationTest(
4+
envs=[
5+
{
6+
"env_file": "dab_jwt.compose.env",
7+
"run_tests": True,
8+
"db_restore": None,
9+
"test_script": "/src/galaxy_ng/profiles/dab_jwt/run_integration.sh"
10+
}
11+
]
12+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
COMPOSE_PROFILE=galaxy_ng/base:galaxy_ng/dab_jwt
2+
COMPOSE_PROJECT_NAME=ci-dab-proxy
3+
4+
DEV_SOURCE_PATH=galaxy_ng
5+
COMPOSE_BINARY=docker
6+
SETUP_TEST_DATA=0
7+
UPDATE_UI=0
8+
ENABLE_SIGNING=1
9+
HUB_API_ROOT=http://jwtproxy:8080/api/galaxy
10+
11+
DJANGO_SUPERUSER_USERNAME=admin
12+
DJANGO_SUPERUSER_PASSWORD=admin
13+
14+
PULP_GALAXY_API_PATH_PREFIX=/api/galaxy
15+
PULP_ANALYTICS=false
16+
17+
# proxy config ...
18+
API_PORT=5001
19+
JWT_PROXY_PORT=8080
20+

galaxy_ng/tests/integration/dab/__init__.py

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
import pytest
3+
4+
5+
@pytest.mark.deployment_standalone
6+
@pytest.mark.skipif(
7+
not os.getenv("ENABLE_DAB_TESTS"),
8+
reason="Skipping test because ENABLE_DAB_TESTS is not set"
9+
)
10+
def test_dab_collection_download_url_hostnames(settings, galaxy_client, published):
11+
"""
12+
We want the download url to point at the gateway
13+
"""
14+
gc = galaxy_client("admin")
15+
cv_url = 'v3/plugin/ansible/content/published/collections/index/'
16+
cv_url += f'{published.namespace}/{published.name}/versions/{published.version}'
17+
cv_info = gc.get(cv_url)
18+
download_url = cv_info['download_url']
19+
assert download_url.startswith(gc.galaxy_root)
20+
21+
# try to GET the tarball ...
22+
dl_resp = gc.get(download_url, parse_json=False)
23+
assert dl_resp.status_code == 200
24+
assert dl_resp.headers.get('Content-Type') == 'application/gzip'
25+
26+
# make sure the final redirect was through the gateway ...
27+
expected_url = gc.galaxy_root.replace('/api/galaxy/', '')
28+
assert dl_resp.url.startswith(expected_url)

galaxy_ng/tests/integration/utils/iqe_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,11 @@ def get_hub_version(ansible_config):
685685
gc = GalaxyKitClient(ansible_config).gen_authorized_client(role)
686686
except GalaxyError:
687687
# FIXME: versions prior to 4.7 have different credentials. This needs to be fixed.
688-
gc = GalaxyClient(galaxy_root="http://localhost:5001/api/automation-hub/",
688+
api_root = os.environ.get("HUB_API_ROOT", "http://localhost:5001/api/automation-hub/")
689+
api_root = api_root.rstrip("/") + "/"
690+
gc = GalaxyClient(galaxy_root=api_root,
689691
auth={"username": "admin", "password": "admin"})
692+
690693
return gc.get(gc.galaxy_root)["galaxy_ng_version"]
691694

692695

profiles/dab_jwt/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# galaxy_ng/dab
2+
3+
## Usage
4+
5+
This profile is used for running Galaxy NG with the JWT authentication integrations provided by django-ansible-base

profiles/dab_jwt/compose.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
services:
3+
jwtproxy:
4+
build:
5+
context: "{SRC_DIR}/galaxy_ng/profiles/dab_jwt/proxy"
6+
ports:
7+
- "{JWT_PROXY_PORT}:{JWT_PROXY_PORT}"
8+
environment:
9+
UPSTREAM_URL: "http://pulp:{API_PORT}"
10+
PROXY_PORT: "{JWT_PROXY_PORT}"
11+
volumes:
12+
- "{SRC_DIR}/galaxy_ng/profiles/dab_jwt/proxy:/app:rw"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
galaxy_ng/base

profiles/dab_jwt/proxy/.air.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[build]
2+
bin = "proxy"
3+
cmd = "go build -o proxy proxy.go"
4+
full_bin = "./proxy"
5+
6+
exclude_regex = ["*.swp"]
7+
8+
[run]
9+
cmd = "./proxy"

profiles/dab_jwt/proxy/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM golang:alpine
2+
3+
# hot reloads ...
4+
RUN go install github.com/cosmtrek/air@latest
5+
6+
RUN mkdir -p /app
7+
WORKDIR /app
8+
9+
CMD ["air"]

profiles/dab_jwt/proxy/go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module mockproxy
2+
3+
go 1.16
4+
5+
require (
6+
github.com/golang-jwt/jwt/v4 v4.4.1
7+
github.com/google/uuid v1.6.0 // indirect
8+
)

profiles/dab_jwt/proxy/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
github.com/golang-jwt/jwt/v4 v4.4.1 h1:pC5DB52sCeK48Wlb9oPcdhnjkz1TKt1D/P7WKJ0kUcQ=
2+
github.com/golang-jwt/jwt/v4 v4.4.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
3+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=

0 commit comments

Comments
 (0)