-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial set of tests #84
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e8ae285
initial tests
PatStLouis 63362ff
improved fixtures with pydantic models
PatStLouis 2ae81d5
implement asyncic pytest
PatStLouis 5ee6ec3
add gh action
PatStLouis 3454bdd
fix gh action
PatStLouis 10bf6ba
fix gh action
PatStLouis 640a69c
fix pytest
PatStLouis 1e07f01
fix signed document test
PatStLouis ff07198
fix endorser value type
PatStLouis a38cf45
remove printed out comment
PatStLouis a1c6933
updated config
PatStLouis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from config import settings | ||
from app.models.did_document import DidDocument, SecuredDidDocument | ||
from app.models.di_proof import DataIntegrityProof | ||
|
||
TEST_DOMAIN = settings.DOMAIN | ||
TEST_DID_NAMESPACE = 'test' | ||
TEST_DID_IDENTIFIER = '01' | ||
TEST_DID = f"{settings.DID_WEB_BASE}:{TEST_DID_NAMESPACE}:{TEST_DID_IDENTIFIER}" | ||
TEST_PROOF_OPTIONS = { | ||
'type': 'DataIntegrityProof', | ||
'cryptosuite': 'eddsa-jcs-2022', | ||
'proofPurpose': 'assertionMethod' | ||
} | ||
TEST_AUTHORISED_KEY = 'z6Mkj8h3kzWZrPiucoyY9LGCTpXhCqBoX3doDmHz5MaPxnvi' | ||
TEST_AUTHORISED_JWK = 'RYirjVOuAh9BXxQaxozaDLK_JqrKPicZeq9bl3Fg8xc' | ||
|
||
TEST_DID_DOCUMENT = DidDocument( | ||
context=['https://www.w3.org/ns/did/v1'], | ||
id=TEST_DID | ||
).model_dump() | ||
|
||
TEST_DID_DOCUMENT_PROOF = DataIntegrityProof( | ||
proofValue='z4NCh2bocHncp9SSpCDETSsWN5ueu7eLPFgaVTNvgCk2RxZvFbVHAN8keGqd8XXbSzrxd3q1VMKQrZuqf672WNncK', | ||
verificationMethod=f'did:key:{TEST_AUTHORISED_KEY}#{TEST_AUTHORISED_KEY}' | ||
).model_dump() | ||
|
||
TEST_DID_DOCUMENT_SIGNED = SecuredDidDocument( | ||
context=['https://www.w3.org/ns/did/v1'], | ||
id=TEST_DID, | ||
proof=TEST_DID_DOCUMENT_PROOF | ||
).model_dump() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from app.routers.identifiers import request_did | ||
from app.routers.resolvers import get_did_document | ||
from app.plugins import AskarStorage, AskarVerifier, DidWebVH | ||
from datetime import datetime, timezone | ||
from tests.fixtures import ( | ||
TEST_DOMAIN, | ||
TEST_DID_NAMESPACE, | ||
TEST_DID_IDENTIFIER, | ||
TEST_DID, | ||
TEST_DID_DOCUMENT, | ||
TEST_DID_DOCUMENT_SIGNED, | ||
TEST_AUTHORISED_KEY, | ||
TEST_PROOF_OPTIONS | ||
) | ||
import asyncio | ||
import json | ||
import uuid | ||
|
||
def test_storage(): | ||
askar = AskarStorage() | ||
asyncio.run(askar.provision(recreate=True)) | ||
|
||
category = 'test' | ||
key = '01' | ||
data = {'value': None} | ||
value_1 = 'value_1' | ||
value_2 = 'value_2' | ||
|
||
data['value'] = value_1 | ||
asyncio.run(askar.store(category, key, data)) | ||
fetched_data = asyncio.run(askar.fetch(category, key)) | ||
assert fetched_data['value'] == value_1 | ||
|
||
data['value'] = value_2 | ||
asyncio.run(askar.update(category, key, data)) | ||
fetched_data = asyncio.run(askar.fetch(category, key)) | ||
assert fetched_data['value'] == value_2 | ||
|
||
def test_request_did(): | ||
did_request = asyncio.run(request_did(TEST_DID_NAMESPACE, TEST_DID_IDENTIFIER)) | ||
did_request = json.loads(did_request.body.decode()) | ||
assert did_request.get('didDocument').get('id') == TEST_DID | ||
assert did_request.get('proofOptions').get("type") == TEST_PROOF_OPTIONS['type'] | ||
assert did_request.get('proofOptions').get("cryptosuite") == TEST_PROOF_OPTIONS['cryptosuite'] | ||
assert did_request.get('proofOptions').get("proofPurpose") == TEST_PROOF_OPTIONS['proofPurpose'] | ||
assert did_request.get('proofOptions').get("domain") == TEST_DOMAIN | ||
assert did_request.get('proofOptions').get("challenge") | ||
assert datetime.fromisoformat( | ||
did_request.get('proofOptions').get("expires") | ||
) > datetime.now(timezone.utc) | ||
|
||
def test_register_did(): | ||
askar = AskarStorage() | ||
asyncio.run(askar.store("didDocument", TEST_DID, TEST_DID_DOCUMENT)) | ||
asyncio.run(askar.store("authorizedKey", TEST_DID, TEST_AUTHORISED_KEY)) | ||
|
||
def test_resolve_did(): | ||
did_doc = asyncio.run(get_did_document(TEST_DID_NAMESPACE, TEST_DID_IDENTIFIER)) | ||
did_doc = json.loads(did_doc.body.decode()) | ||
assert did_doc == TEST_DID_DOCUMENT | ||
assert did_doc.get('id') == TEST_DID | ||
|
||
def test_create_log_entry(): | ||
initial_log_entry = DidWebVH().create(TEST_DID_DOCUMENT, TEST_AUTHORISED_KEY) | ||
assert initial_log_entry.get('versionId') | ||
assert initial_log_entry.get('versionTime') | ||
assert initial_log_entry.get('parameters') | ||
assert initial_log_entry.get('state') | ||
|
||
def test_verify_di_proof(): | ||
document = TEST_DID_DOCUMENT_SIGNED | ||
proof = document.pop('proof') | ||
verifier = AskarVerifier() | ||
assert verifier.verify_proof(document, proof) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you not make this test async and await these asynchronous functions?