Skip to content

Commit

Permalink
Merge branch 'main' into feat/3316
Browse files Browse the repository at this point in the history
  • Loading branch information
swcurran authored Nov 16, 2024
2 parents f7769ac + a41b4fb commit 104a35e
Show file tree
Hide file tree
Showing 24 changed files with 618 additions and 550 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/nigthly.yml → .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ name: Nightly Publish

on:
schedule:
- cron: '0 0 * * *'
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
tests:
if: github.repository_owner == 'openwallet-foundation' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.12"]
if: github.repository == 'openwallet-foundation/acapy' || github.event_name == 'workflow_dispatch'

steps:
- name: checkout
- name: Checkout
uses: actions/checkout@v4
- name: Tests

- name: Run Tests
uses: ./.github/actions/run-unit-tests
with:
python-version: ${{ matrix.python-version }}
Expand All @@ -30,13 +32,16 @@ jobs:
outputs:
commits_today: ${{ steps.commits.outputs.commits_today }}
date: ${{ steps.date.outputs.date }}
if: github.repository_owner == 'openwallet-foundation' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4
- name: print latest_commit
- name: Print Latest Commit
run: echo ${{ github.sha }}
- name: Get new commits

- name: Get New Commits
id: commits
run: echo "commits_today=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_OUTPUT

- name: Get Date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
Expand Down
1 change: 0 additions & 1 deletion acapy_agent/anoncreds/tests/test_revocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,6 @@ async def test_create_credential_w3c(self, mock_supports_revocation):
assert isinstance(result, tuple)
assert mock_supports_revocation.call_count == 1

@pytest.mark.asyncio
@mock.patch.object(AskarAnoncredsProfileSession, "handle")
async def test_create_credential_w3c_keyerror(self, mock_handle):
mock_handle.fetch = mock.CoroutineMock(side_effect=[MockEntry(), MockEntry()])
Expand Down
2 changes: 1 addition & 1 deletion acapy_agent/config/logging/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def load_resource(path: str, encoding: Optional[str] = None):
else:
# Package resource
package, resource = components
bstream = resources.open_binary(package, resource)
bstream = resources.files(package).joinpath(resource).open("rb")
if encoding:
return io.TextIOWrapper(bstream, encoding=encoding)
return bstream
Expand Down
59 changes: 45 additions & 14 deletions acapy_agent/config/tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import contextlib
from io import StringIO
from io import BufferedReader, StringIO, TextIOWrapper
from tempfile import NamedTemporaryFile
from unittest import IsolatedAsyncioTestCase, mock

Expand Down Expand Up @@ -110,24 +110,55 @@ def test_banner_did(self):
def test_load_resource(self):
# Testing local file access
with mock.patch("builtins.open", mock.MagicMock()) as mock_open:
test_module.load_resource("abc", encoding="utf-8")
# First call succeeds
file_handle = mock.MagicMock(spec=TextIOWrapper)
mock_open.return_value = file_handle
result = test_module.load_resource("abc", encoding="utf-8")
mock_open.assert_called_once_with("abc", encoding="utf-8")
assert result == file_handle # Verify the returned file handle

mock_open.reset_mock()
# Simulate IOError on second call
mock_open.side_effect = IOError("insufficient privilege")
# load_resource should absorb IOError
test_module.load_resource("abc", encoding="utf-8")
result = test_module.load_resource("abc", encoding="utf-8")
mock_open.assert_called_once_with("abc", encoding="utf-8")
assert result is None

# Testing package resource access with encoding (text mode)
with mock.patch(
"importlib.resources.open_binary", mock.MagicMock()
) as mock_open_binary, mock.patch(
with mock.patch("importlib.resources.files") as mock_files, mock.patch(
"io.TextIOWrapper", mock.MagicMock()
) as mock_text_io_wrapper:
test_module.load_resource("abc:def", encoding="utf-8")
mock_open_binary.assert_called_once_with("abc", "def")
mock_text_io_wrapper.assert_called_once()
# Setup the mocks
mock_resource_path = mock.MagicMock()
mock_files.return_value.joinpath.return_value = mock_resource_path
mock_resource_handle = mock.MagicMock(spec=BufferedReader)
mock_resource_path.open.return_value = mock_resource_handle
mock_text_io_wrapper.return_value = mock.MagicMock(spec=TextIOWrapper)

result = test_module.load_resource("abc:def", encoding="utf-8")

# Assertions
mock_files.assert_called_once_with("abc")
mock_files.return_value.joinpath.assert_called_once_with("def")
mock_resource_path.open.assert_called_once_with("rb")
mock_text_io_wrapper.assert_called_once_with(
mock_resource_handle, encoding="utf-8"
)
assert result is mock_text_io_wrapper.return_value

# Testing package resource access without encoding (binary mode)
with mock.patch(
"importlib.resources.open_binary", mock.MagicMock()
) as mock_open_binary:
test_module.load_resource("abc:def", encoding=None)
mock_open_binary.assert_called_once_with("abc", "def")
with mock.patch("importlib.resources.files") as mock_files:
# Setup the mocks
mock_resource_path = mock.MagicMock()
mock_files.return_value.joinpath.return_value = mock_resource_path
mock_resource_handle = mock.MagicMock(spec=BufferedReader)
mock_resource_path.open.return_value = mock_resource_handle

result = test_module.load_resource("abc:def", encoding=None)

# Assertions
mock_files.assert_called_once_with("abc")
mock_files.return_value.joinpath.assert_called_once_with("def")
mock_resource_path.open.assert_called_once_with("rb")
assert result == mock_resource_handle # Verify the returned binary stream
6 changes: 3 additions & 3 deletions acapy_agent/connections/tests/test_base_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest import IsolatedAsyncioTestCase
from unittest.mock import call

import pytest
from pydid import DID, DIDDocument, DIDDocumentBuilder
from pydid.doc.builder import ServiceBuilder
from pydid.verification_method import (
Expand All @@ -27,9 +28,7 @@
from ...protocols.connections.v1_0.messages.connection_invitation import (
ConnectionInvitation,
)
from ...protocols.coordinate_mediation.v1_0.models.mediation_record import (
MediationRecord,
)
from ...protocols.coordinate_mediation.v1_0.models.mediation_record import MediationRecord
from ...protocols.coordinate_mediation.v1_0.route_manager import (
CoordinateMediationV1RouteManager,
RouteManager,
Expand Down Expand Up @@ -1065,6 +1064,7 @@ async def test_resolve_connection_targets_x_bad_key_material(self):
await self.manager.resolve_connection_targets(did)
assert "not supported" in str(cm.exception)

@pytest.mark.filterwarnings("ignore::UserWarning")
async def test_resolve_connection_targets_x_unsupported_key(self):
did = "did:sov:" + self.test_did
doc_builder = DIDDocumentBuilder(did)
Expand Down
1 change: 1 addition & 0 deletions acapy_agent/core/tests/test_conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,7 @@ async def test_dispatch_complete_fatal_x(self):
conductor.dispatch_complete(message, mock_task)
mock_notify.assert_called_once_with()

@pytest.mark.filterwarnings("ignore:Aries RFC 0160.*:DeprecationWarning")
async def test_print_invite_connection(self):
builder: ContextBuilder = StubContextBuilder(self.test_settings)
builder.update_settings(
Expand Down
6 changes: 3 additions & 3 deletions acapy_agent/didcomm_v2/tests/test_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..adapters import ResolverAdapter, SecretsAdapter, SecretsAdapterError


class TestDIDResolver(BaseDIDResolver):
class MockDIDResolver(BaseDIDResolver):
async def setup(self, context: InjectionContext):
return await super().setup(context)

Expand All @@ -26,7 +26,7 @@ async def resolve(
self,
profile,
did,
sercive_accept=None,
service_accept=None,
):
return {"did": did, "test": "didDoc"}

Expand All @@ -46,7 +46,7 @@ async def asyncSetUp(self):
self.test_did = "did:test:0"
self.invalid_did = "this shouldn't work"
resolver = DIDResolver()
resolver.register_resolver(TestDIDResolver())
resolver.register_resolver(MockDIDResolver())
self.res_adapter = ResolverAdapter(profile=self.profile, resolver=resolver)

async def test_resolver_adapter_resolve_did(self):
Expand Down
3 changes: 0 additions & 3 deletions acapy_agent/multitenant/admin/tests/test_routes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from unittest import IsolatedAsyncioTestCase

import pytest
from marshmallow.exceptions import ValidationError

from ....admin.request_context import AdminRequestContext
Expand Down Expand Up @@ -143,7 +142,6 @@ async def test_wallets_list_query(self):
}
)

@pytest.mark.asyncio(scope="function")
async def test_wallet_create_tenant_settings(self):
body = {
"wallet_name": "test",
Expand Down Expand Up @@ -796,7 +794,6 @@ async def test_wallet_create_token_x(self):
)
await test_module.wallet_create_token(self.request)

@pytest.mark.asyncio(scope="function")
async def test_wallet_remove_managed(self):
self.request.has_body = False
self.request.match_info = {"wallet_id": "dummy"}
Expand Down
1 change: 1 addition & 0 deletions acapy_agent/multitenant/single_wallet_askar_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async def get_wallet_profile(
sub_wallet_settings = {
"wallet.recreate": False,
"wallet.seed": None,
"wallet.key": "",
"wallet.rekey": None,
"wallet.id": None,
"wallet.name": multitenant_wallet_name,
Expand Down
3 changes: 3 additions & 0 deletions acapy_agent/protocols/connections/v1_0/tests/test_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from unittest import IsolatedAsyncioTestCase

import pytest

from .....cache.base import BaseCache
from .....cache.in_memory import InMemoryCache
from .....connections.models.conn_record import ConnRecord
Expand Down Expand Up @@ -29,6 +31,7 @@
from ..models.connection_detail import ConnectionDetail


@pytest.mark.filterwarnings("ignore:Aries RFC 0160.*:DeprecationWarning")
class TestConnectionManager(IsolatedAsyncioTestCase):
def make_did_doc(self, did, verkey):
doc = DIDDoc(did=did)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from unittest import IsolatedAsyncioTestCase

import pytest

from ......connections.models import connection_target
from ......connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service
from ......messaging.decorators.attach_decorator import AttachDecorator
Expand Down Expand Up @@ -75,7 +73,6 @@ async def asyncSetUp(self):
did_doc_attach=self.did_doc_attach,
)

@pytest.mark.asyncio(scope="function")
@mock.patch.object(test_module, "DIDXManager")
async def test_called(self, mock_didx_mgr):
mock_didx_mgr.return_value.accept_response = mock.CoroutineMock()
Expand All @@ -89,7 +86,6 @@ async def test_called(self, mock_didx_mgr):
)
assert not responder.messages

@pytest.mark.asyncio(scope="function")
@mock.patch.object(test_module, "DIDXManager")
async def test_called_auto_ping(self, mock_didx_mgr):
self.ctx.update_settings({"auto_ping_connection": True})
Expand All @@ -107,7 +103,6 @@ async def test_called_auto_ping(self, mock_didx_mgr):
result, _ = messages[0]
assert isinstance(result, Ping)

@pytest.mark.asyncio(scope="function")
@mock.patch.object(test_module, "DIDXManager")
@mock.patch.object(connection_target, "ConnectionTarget")
async def test_problem_report(self, mock_conn_target, mock_didx_mgr):
Expand Down Expand Up @@ -144,7 +139,6 @@ async def test_problem_report(self, mock_conn_target, mock_didx_mgr):
)
assert target == {"target_list": [mock_conn_target]}

@pytest.mark.asyncio(scope="function")
@mock.patch.object(test_module, "DIDXManager")
@mock.patch.object(connection_target, "ConnectionTarget")
async def test_problem_report_did_doc(
Expand Down Expand Up @@ -191,7 +185,6 @@ async def test_problem_report_did_doc(
)
assert target == {"target_list": [mock_conn_target]}

@pytest.mark.asyncio(scope="function")
@mock.patch.object(test_module, "DIDXManager")
@mock.patch.object(connection_target, "ConnectionTarget")
async def test_problem_report_did_doc_no_conn_target(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,6 @@ async def test_issue_credential_non_revocable(self):
# assert data is encoded as base64
assert attachment.data.base64

@pytest.mark.asyncio
async def test_match_sent_cred_def_id_error(self):
tag_query = {"tag": "test_tag"}

Expand All @@ -737,7 +736,6 @@ async def test_match_sent_cred_def_id_error(self):
context.exception
)

@pytest.mark.asyncio
async def test_store_credential(self):
attr_values = {
"legalName": "value",
Expand Down
24 changes: 14 additions & 10 deletions acapy_agent/protocols/present_proof/dif/pres_exch_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
from ....vc.vc_di.prove import create_signed_anoncreds_presentation
from ....vc.vc_ld.prove import create_presentation, derive_credential, sign_presentation
from ....wallet.base import BaseWallet, DIDInfo
from ....wallet.default_verification_key_strategy import BaseVerificationKeyStrategy
from ....wallet.default_verification_key_strategy import (
BaseVerificationKeyStrategy,
ProofPurposeStr,
)
from ....wallet.error import WalletError, WalletNotFoundError
from ....wallet.key_type import BLS12381G2, ED25519
from .pres_exch import (
Expand Down Expand Up @@ -115,19 +118,19 @@ async def _get_issue_suite(
self,
*,
issuer_id: str,
proof_purpose: Optional[ProofPurposeStr] = None,
):
"""Get signature suite for signing presentation."""
proof_purpose = proof_purpose or "assertionMethod"
did_info = await self._did_info_for_did(issuer_id)
verkey_id_strategy = self.profile.context.inject(BaseVerificationKeyStrategy)
verification_method = await verkey_id_strategy.get_verification_method_id_for_did(
issuer_id, self.profile, proof_purpose="assertionMethod"
vm_id_strategy = self.profile.context.inject(BaseVerificationKeyStrategy)
verification_method = await vm_id_strategy.get_verification_method_id_for_did(
issuer_id,
self.profile,
proof_type=self.proof_type,
proof_purpose=proof_purpose,
)

if verification_method is None:
raise DIFPresExchError(
f"Unable to get retrieve verification method for did {issuer_id}"
)

# Get signature class based on proof type
SignatureClass = self.PROOF_TYPE_SIGNATURE_SUITE_MAPPING[self.proof_type]

Expand Down Expand Up @@ -1302,8 +1305,9 @@ async def create_vp(
)
else:
vp = self.__add_dif_fields_to_vp(vp, submission_property)
assert issuer_id
issue_suite = await self._get_issue_suite(
issuer_id=issuer_id,
issuer_id=issuer_id, proof_purpose="authentication"
)
signed_vp = await sign_presentation(
presentation=vp,
Expand Down
Loading

0 comments on commit 104a35e

Please sign in to comment.