Skip to content

Commit 9567f85

Browse files
Feat/manage script testing (#906)
* feat(core): support configurable proof format for anoncreds Signed-off-by: Yuki I <[email protected]> * feat(devops): add './manage test' command for isolated testing Signed-off-by: Yuki I <[email protected]> * style: apply black code formatting Signed-off-by: Yuki I <[email protected]> * test(core): isolate tests to prevent pollution and improve logging Signed-off-by: Yuki I <[email protected]> * refactor(core): add config validation and improve proof format fallback Signed-off-by: Yuki I <[email protected]> * test(core): add missing coverage for anoncreds fallback Signed-off-by: Yuki I <[email protected]> * fix(build): align proof format config with project standards Signed-off-by: Yuki I <[email protected]> * style(core): apply black code formatting Signed-off-by: Yuki I <[email protected]> --------- Signed-off-by: Yuki I <[email protected]> Co-authored-by: Yuki I <[email protected]>
1 parent 8fadca2 commit 9567f85

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

docker/manage

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ usage() {
8888
8989
$0 scale 5
9090
91+
test - Builds a test-specific Docker image and runs the test suite
92+
inside the container. You can pass pytest arguments.
93+
94+
$0 test
95+
$0 test -v
96+
$0 test oidc-controller/api/core/tests/
97+
98+
format - Runs 'black' code formatter on the source code.
99+
Automatically fixes formatting issues.
100+
101+
$0 format
102+
91103
logs - Display the logs from the docker compose run (ctrl-c to exit).
92104
93105
stop - Stops the services. This is a non-destructive process. The volumes and containers
@@ -129,7 +141,7 @@ configureEnvironment() {
129141
if [ -f .env ]; then
130142
while read line; do
131143
if [[ ! "$line" =~ ^\# ]] && [[ "$line" =~ .*= ]]; then
132-
export ${line//[$'\r\n']}
144+
export "${line//[$'\r\n']}"
133145
fi
134146
done <.env
135147
fi
@@ -456,6 +468,42 @@ scale)
456468
echo "Scaling controller to ${REPLICAS} replicas..."
457469
docker-compose up -d --force-recreate controller
458470
;;
471+
test)
472+
# 1. Build the test image
473+
# We use the same context ('..') as the production build so we can see pyproject.toml
474+
echoInfo "Building test environment image..."
475+
docker build \
476+
-t 'acapy-vc-authn-oidc-tests' \
477+
-f './oidc-controller/Dockerfile.test' '..'
478+
479+
# 2. Run the container
480+
# We pass $@ (all remaining arguments) to the entrypoint (pytest)
481+
# This allows running specific tests: ./manage test -v -k "test_config"
482+
echoInfo "Running tests in isolated container..."
483+
docker run --rm 'acapy-vc-authn-oidc-tests' "$@"
484+
;;
485+
format)
486+
# 1. Ensure image exists (re-use the test build logic)
487+
echoInfo "Building tool environment image..."
488+
docker build \
489+
-t 'acapy-vc-authn-oidc-tests' \
490+
-f './oidc-controller/Dockerfile.test' '..'
491+
492+
# 2. Run black
493+
# We calculate the absolute path to oidc-controller relative to the script location
494+
# to ensure the mount works regardless of where you run ./manage from
495+
PROJECT_ROOT=$(cd "${SCRIPT_HOME}/../" && pwd)
496+
497+
echoInfo "Formatting code with Black..."
498+
docker run --rm \
499+
--user $(id -u):$(id -g) \
500+
-v "${PROJECT_ROOT}/oidc-controller":/app/src/oidc-controller \
501+
--entrypoint black \
502+
'acapy-vc-authn-oidc-tests' \
503+
/app/src/oidc-controller
504+
505+
echoSuccess "Formatting complete."
506+
;;
459507
single-pod)
460508
if [[ ! -f ".env" ]]; then
461509
# first/clean run, prompt user selections
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM python:3.12
2+
3+
WORKDIR /app/src
4+
5+
# Install Poetry
6+
ENV POETRY_VIRTUALENVS_CREATE=false
7+
RUN pip3 install --no-cache-dir poetry==2.0
8+
9+
# Copy configuration files from the project root (context is ..)
10+
COPY pyproject.toml poetry.lock README.md ./
11+
12+
# Install ALL dependencies including dev (pytest, tox, mock, etc)
13+
# --no-root prevents installing the project itself as a package yet
14+
RUN poetry install --no-root --with dev
15+
16+
# Copy the source code
17+
COPY ./oidc-controller ./oidc-controller
18+
19+
# Set the python path so imports work correctly
20+
ENV PYTHONPATH=/app/src/oidc-controller
21+
22+
# Default command is to run pytest
23+
ENTRYPOINT ["pytest"]

oidc-controller/api/core/oidc/tests/test_issue_token_service.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,23 @@ async def test_get_claims_fallback_migration_logic(auth_session_fixture):
451451
# Assert: Should still find the data under 'indy' key
452452
attributes = json.loads(claims["vc_presented_attributes"])
453453
assert attributes["email"] == "[email protected]"
454+
455+
456+
@pytest.mark.asyncio
457+
async def test_get_claims_fallback_reverse_migration_logic(auth_session_fixture):
458+
"""
459+
Verify fallback when config is 'indy' but data is 'anoncreds'.
460+
This covers the 'elif "anoncreds" in pres_request' branch.
461+
"""
462+
# Arrange: Data has 'anoncreds' key
463+
auth_session_fixture.presentation_exchange = create_mock_presentation_exchange(
464+
"anoncreds"
465+
)
466+
467+
# Act: Config is set to 'indy' (simulating default/legacy config)
468+
with patch.object(settings, "ACAPY_PROOF_FORMAT", "indy"):
469+
claims = Token.get_claims(auth_session_fixture, ver_config)
470+
471+
# Assert: Should correctly find the data under 'anoncreds' key
472+
attributes = json.loads(claims["vc_presented_attributes"])
473+
assert attributes["email"] == "[email protected]"

0 commit comments

Comments
 (0)