From d7dc92ae387700f6fc49ed52ee4f043c11ecde9b Mon Sep 17 00:00:00 2001 From: Jamie Hale Date: Thu, 26 Sep 2024 18:07:37 +0000 Subject: [PATCH 1/4] Adjust sonarcloud and integration test workflows Signed-off-by: Jamie Hale --- .github/actions/run-unit-tests/action.yml | 2 +- .github/workflows/bdd-integration-tests.yml | 1 + .github/workflows/bdd-interop-tests.yml | 1 + .github/workflows/scenario-integration-tests.yml | 1 + .github/workflows/sonar-merge-main.yml | 3 ++- .github/workflows/sonar-pr.yml | 3 ++- 6 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/actions/run-unit-tests/action.yml b/.github/actions/run-unit-tests/action.yml index 9675c99bc0..1bff008933 100644 --- a/.github/actions/run-unit-tests/action.yml +++ b/.github/actions/run-unit-tests/action.yml @@ -30,7 +30,7 @@ runs: - name: Tests shell: bash run: | - poetry run pytest --cov=aries_cloudagent --cov-report term-missing --cov-report xml --ignore-glob=/tests/* --ignore-glob=demo/* --ignore-glob=docker/* --ignore-glob=docs/* --ignore-glob=scripts/* 2>&1 | tee pytest.log + poetry run pytest --cov=aries_cloudagent --cov-report term-missing --cov-report xml --ignore-glob=/tests/* --ignore-glob=demo/* --ignore-glob=docker/* --ignore-glob=docs/* --ignore-glob=scripts/* --ignore-glob=scenarios/* 2>&1 | tee pytest.log PYTEST_EXIT_CODE=${PIPESTATUS[0]} if grep -Eq "RuntimeWarning: coroutine .* was never awaited" pytest.log; then echo "Failure: Detected unawaited coroutine warning in pytest output." diff --git a/.github/workflows/bdd-integration-tests.yml b/.github/workflows/bdd-integration-tests.yml index aa1cd47e75..33868ee747 100644 --- a/.github/workflows/bdd-integration-tests.yml +++ b/.github/workflows/bdd-integration-tests.yml @@ -36,6 +36,7 @@ jobs: src: - aries_cloudagent/**/* - poetry.lock + - pyproject.toml demo: "demo/**/*" - name: Check if demo or src files changed id: check-if-demo-or-src-changed diff --git a/.github/workflows/bdd-interop-tests.yml b/.github/workflows/bdd-interop-tests.yml index 42559367cd..c7ffc7c844 100644 --- a/.github/workflows/bdd-interop-tests.yml +++ b/.github/workflows/bdd-interop-tests.yml @@ -36,6 +36,7 @@ jobs: src: - aries_cloudagent/**/* - poetry.lock + - pyproject.toml - name: Check if src files changed id: check-if-src-changed run: | diff --git a/.github/workflows/scenario-integration-tests.yml b/.github/workflows/scenario-integration-tests.yml index 4faa010315..22ba8024e9 100644 --- a/.github/workflows/scenario-integration-tests.yml +++ b/.github/workflows/scenario-integration-tests.yml @@ -35,6 +35,7 @@ jobs: src: - aries_cloudagent/**/* - poetry.lock + - pyproject.toml - name: Check if scenarios or src files changed id: check-if-scenarios-or-src-changed run: | diff --git a/.github/workflows/sonar-merge-main.yml b/.github/workflows/sonar-merge-main.yml index e63f649f7e..4e57d1802c 100644 --- a/.github/workflows/sonar-merge-main.yml +++ b/.github/workflows/sonar-merge-main.yml @@ -30,5 +30,6 @@ jobs: with: args: > -Dsonar.python.coverage.reportPaths=test-reports/coverage.xml - -Dsonar.coverage.exclusions=**/tests/*,**/demo/*,**/docs/*,**/docker/*,**/scripts/* + -Dsonar.coverage.exclusions=**/tests/**,**/demo/**,**/docs/**,**/docker/**,**/scripts/**,**/scenarios/** + -Dsonar.cpd.exclusions=**/tests/**,**/demo/**,**/docs/**,**/docker/**,**/scripts/**,**/scenarios/** -Dsonar.sources=./ \ No newline at end of file diff --git a/.github/workflows/sonar-pr.yml b/.github/workflows/sonar-pr.yml index 660cf8730e..e5a1cacced 100644 --- a/.github/workflows/sonar-pr.yml +++ b/.github/workflows/sonar-pr.yml @@ -68,6 +68,7 @@ jobs: -Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }} -Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} -Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} - -Dsonar.coverage.exclusions=**/tests/*,**/demo/*,**/docs/*,**/docker/*,**/scripts/* + -Dsonar.coverage.exclusions=**/tests/**,**/demo/**,**/docs/**,**/docker/**,**/scripts/**,**/scenarios/** + -Dsonar.cpd.exclusions=**/tests/**,**/demo/**,**/docs/**,**/docker/**,**/scripts/**,**/scenarios/** -Dsonar.python.coverage.reportPaths=test-reports/coverage.xml -Dsonar.sources=./ \ No newline at end of file From 6fb8da241d23fd1f4c7d0187d53faa1d133b517f Mon Sep 17 00:00:00 2001 From: Jamie Hale Date: Thu, 26 Sep 2024 18:23:28 +0000 Subject: [PATCH 2/4] Only run sonarcloud on hyperledger repo Signed-off-by: Jamie Hale --- .github/workflows/sonar-merge-main.yml | 1 + .github/workflows/sonar-pr.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonar-merge-main.yml b/.github/workflows/sonar-merge-main.yml index 4e57d1802c..a766f5223a 100644 --- a/.github/workflows/sonar-merge-main.yml +++ b/.github/workflows/sonar-merge-main.yml @@ -8,6 +8,7 @@ jobs: sonarcloud: name: SonarCloud runs-on: ubuntu-latest + if: github.repository == 'hyperledger/aries-cloudagent-python' steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/sonar-pr.yml b/.github/workflows/sonar-pr.yml index e5a1cacced..a7f47639de 100644 --- a/.github/workflows/sonar-pr.yml +++ b/.github/workflows/sonar-pr.yml @@ -9,7 +9,7 @@ on: jobs: SonarCloud: runs-on: ubuntu-latest - if: github.event.workflow_run.conclusion == 'success' + if: github.event.workflow_run.conclusion == 'success' && github.repository == 'hyperledger/aries-cloudagent-python' steps: - uses: actions/checkout@v4 with: From 785492445ed8f378c69f4cd09be6b8046ac1f028 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Sep 2024 18:13:34 -0400 Subject: [PATCH 3/4] fix: enable refreshing did endpoint using mediator info Signed-off-by: Daniel Bluhm --- aries_cloudagent/wallet/routes.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/aries_cloudagent/wallet/routes.py b/aries_cloudagent/wallet/routes.py index 9e2045dc95..1f9f0b46e6 100644 --- a/aries_cloudagent/wallet/routes.py +++ b/aries_cloudagent/wallet/routes.py @@ -43,6 +43,8 @@ NON_SD_LIST_VALIDATE, SD_JWT_EXAMPLE, SD_JWT_VALIDATE, + UUID4_EXAMPLE, + UUID4_VALIDATE, IndyDID, StrOrDictField, Uri, @@ -172,6 +174,14 @@ class DIDEndpointWithTypeSchema(OpenAPISchema): "example": ENDPOINT_TYPE_EXAMPLE, }, ) + mediation_id = fields.Str( + required=False, + validate=UUID4_VALIDATE, + metadata={ + "description": "Medation ID to use for endpoint information.", + "example": UUID4_EXAMPLE, + }, + ) class JWSCreateSchema(OpenAPISchema): @@ -896,7 +906,7 @@ async def promote_wallet_public_did( async with ( context.session() if is_ctx_admin_request else profile.session() ) as session: - wallet = session.inject_or(BaseWallet) + wallet = session.inject(BaseWallet) did_info = await wallet.get_local_did(did) info = await wallet.set_public_did(did_info) @@ -951,6 +961,7 @@ async def wallet_set_did_endpoint(request: web.BaseRequest): did = body["did"] endpoint = body.get("endpoint") endpoint_type = EndpointType.get(body.get("endpoint_type", EndpointType.ENDPOINT.w3c)) + mediation_id = body.get("mediation_id") create_transaction_for_endorser = json.loads( request.query.get("create_transaction_for_endorser", "false") @@ -960,6 +971,17 @@ async def wallet_set_did_endpoint(request: web.BaseRequest): connection_id = request.query.get("conn_id") attrib_def = None + profile = context.profile + route_manager = profile.inject(RouteManager) + mediation_record = await route_manager.mediation_record_if_id( + profile=profile, mediation_id=mediation_id, or_default=True + ) + routing_keys, mediator_endpoint = await route_manager.routing_info( + profile, + mediation_record, + ) + LOGGER.debug("Mediation info: %s, %s", routing_keys, mediator_endpoint) + # check if we need to endorse if is_author_role(context.profile): # authors cannot write to the ledger @@ -1005,6 +1027,7 @@ async def wallet_set_did_endpoint(request: web.BaseRequest): if not wallet: raise web.HTTPForbidden(reason="No wallet available") try: + endpoint = mediator_endpoint or endpoint ledger = context.profile.inject_or(BaseLedger) attrib_def = await wallet.set_did_endpoint( did, @@ -1013,6 +1036,7 @@ async def wallet_set_did_endpoint(request: web.BaseRequest): endpoint_type, write_ledger=write_ledger, endorser_did=endorser_did, + routing_keys=routing_keys, ) except WalletNotFoundError as err: raise web.HTTPNotFound(reason=err.roll_up) from err From 8a20bfc101cbe603552b62ec967138c4125eb433 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Sep 2024 18:52:38 -0400 Subject: [PATCH 4/4] fix: wallet routes tests Signed-off-by: Daniel Bluhm --- aries_cloudagent/wallet/tests/test_routes.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aries_cloudagent/wallet/tests/test_routes.py b/aries_cloudagent/wallet/tests/test_routes.py index 7fb75df617..1e4a272ae7 100644 --- a/aries_cloudagent/wallet/tests/test_routes.py +++ b/aries_cloudagent/wallet/tests/test_routes.py @@ -29,11 +29,14 @@ class TestWalletRoutes(IsolatedAsyncioTestCase): def setUp(self): self.wallet = mock.create_autospec(BaseWallet) self.session_inject = {BaseWallet: self.wallet} + self.route_mgr = mock.MagicMock() + self.route_mgr.mediation_record_if_id = mock.CoroutineMock(return_value=None) + self.route_mgr.routing_info = mock.CoroutineMock(return_value=(None, None)) self.profile = InMemoryProfile.test_profile( - settings={"admin.admin_api_key": "secret-key"} + settings={"admin.admin_api_key": "secret-key"}, + bind={KeyTypes: KeyTypes(), RouteManager: self.route_mgr}, ) self.context = AdminRequestContext.test_context(self.session_inject, self.profile) - self.context.injector.bind_instance(KeyTypes, KeyTypes()) self.request_dict = { "context": self.context, "outbound_message_router": mock.CoroutineMock(),