|
| 1 | +"""Test VC Holder multi-tenancy isolation.""" |
| 2 | + |
| 3 | +import asyncio |
| 4 | +from os import getenv |
| 5 | + |
| 6 | +from acapy_controller import Controller |
| 7 | +from acapy_controller.logging import logging_to_stdout |
| 8 | +from acapy_controller.models import CreateWalletResponse |
| 9 | +from acapy_controller.protocols import DIDResult |
| 10 | + |
| 11 | +AGENCY = getenv("AGENCY", "http://agency:3001") |
| 12 | + |
| 13 | + |
| 14 | +async def main(): |
| 15 | + """Test Controller protocols.""" |
| 16 | + async with Controller(base_url=AGENCY) as agency: |
| 17 | + issuer = await agency.post( |
| 18 | + "/multitenancy/wallet", |
| 19 | + json={ |
| 20 | + "label": "Issuer", |
| 21 | + "wallet_type": "askar", |
| 22 | + }, |
| 23 | + response=CreateWalletResponse, |
| 24 | + ) |
| 25 | + alice = await agency.post( |
| 26 | + "/multitenancy/wallet", |
| 27 | + json={ |
| 28 | + "label": "Alice", |
| 29 | + "wallet_type": "askar", |
| 30 | + }, |
| 31 | + response=CreateWalletResponse, |
| 32 | + ) |
| 33 | + bob = await agency.post( |
| 34 | + "/multitenancy/wallet", |
| 35 | + json={ |
| 36 | + "label": "Bob", |
| 37 | + "wallet_type": "askar", |
| 38 | + }, |
| 39 | + response=CreateWalletResponse, |
| 40 | + ) |
| 41 | + |
| 42 | + async with ( |
| 43 | + Controller( |
| 44 | + base_url=AGENCY, wallet_id=alice.wallet_id, subwallet_token=alice.token |
| 45 | + ) as alice, |
| 46 | + Controller( |
| 47 | + base_url=AGENCY, wallet_id=bob.wallet_id, subwallet_token=bob.token |
| 48 | + ) as bob, |
| 49 | + Controller( |
| 50 | + base_url=AGENCY, wallet_id=issuer.wallet_id, subwallet_token=issuer.token |
| 51 | + ) as issuer, |
| 52 | + ): |
| 53 | + public_did = ( |
| 54 | + await issuer.post( |
| 55 | + "/wallet/did/create", |
| 56 | + json={"method": "key", "options": {"key_type": "ed25519"}}, |
| 57 | + response=DIDResult, |
| 58 | + ) |
| 59 | + ).result |
| 60 | + assert public_did |
| 61 | + cred = await issuer.post( |
| 62 | + "/vc/credentials/issue", |
| 63 | + json={ |
| 64 | + "credential": { |
| 65 | + "@context": [ |
| 66 | + "https://www.w3.org/2018/credentials/v1", |
| 67 | + "https://www.w3.org/2018/credentials/examples/v1", |
| 68 | + ], |
| 69 | + "id": "http://example.edu/credentials/1872", |
| 70 | + "credentialSubject": { |
| 71 | + "id": "did:example:ebfeb1f712ebc6f1c276e12ec21" |
| 72 | + }, |
| 73 | + "issuer": public_did.did, |
| 74 | + "issuanceDate": "2024-12-10T10:00:00Z", |
| 75 | + "type": ["VerifiableCredential", "AlumniCredential"], |
| 76 | + }, |
| 77 | + "options": { |
| 78 | + "challenge": "3fa85f64-5717-4562-b3fc-2c963f66afa6", |
| 79 | + "domain": "example.com", |
| 80 | + "proofPurpose": "assertionMethod", |
| 81 | + "proofType": "Ed25519Signature2018", |
| 82 | + }, |
| 83 | + }, |
| 84 | + ) |
| 85 | + await alice.post( |
| 86 | + "/vc/credentials/store", |
| 87 | + json={"verifiableCredential": cred["verifiableCredential"]}, |
| 88 | + ) |
| 89 | + result = await bob.get("/vc/credentials") |
| 90 | + assert len(result["results"]) == 0 |
| 91 | + |
| 92 | + |
| 93 | +if __name__ == "__main__": |
| 94 | + logging_to_stdout() |
| 95 | + asyncio.run(main()) |
0 commit comments