Skip to content

Commit

Permalink
Merge pull request #853 from nodlesh/fix/json-ld-verified-check
Browse files Browse the repository at this point in the history
JSON-LD tests adding credentialSubject.id
  • Loading branch information
nodlesh authored Jul 25, 2024
2 parents c37c2cf + 04eb983 commit e4ceeb3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
9 changes: 6 additions & 3 deletions aries-test-harness/agent_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def get_relative_timestamp_to_epoch(timestamp):


def format_cred_proposal_by_aip_version(
context, aip_version, cred_data, connection_id: Optional[str] = None, filters=None
context, aip_version, cred_data, connection_id: Optional[str] = None, filters=None, did_for_id=None
):
if aip_version == "AIP20":
filters = amend_filters_with_runtime_data(context, filters)
filters = amend_filters_with_runtime_data(context, filters, did_for_id)
credential_proposal = {
"credential_preview": {
"@type": "issue-credential/2.0/credential-preview",
Expand All @@ -80,7 +80,7 @@ def get_schema_name(context):
return context.schema["schema_name"]


def amend_filters_with_runtime_data(context, filters):
def amend_filters_with_runtime_data(context, filters, did_for_id=None):
schema_name = get_schema_name(context)
# This method will need comdification as new types of filters are used. Intially "indy" is used.
if "indy" in filters:
Expand Down Expand Up @@ -131,6 +131,9 @@ def amend_filters_with_runtime_data(context, filters):
+ "Z"
)
credential["issuanceDate"] = created_datetime
# Check if "credentialSubject" is in json_ld and then check if "id" is not already in "credentialSubject"
if did_for_id and "credentialSubject" in json_ld["credential"] and "id" not in json_ld["credential"]["credentialSubject"]:
json_ld["credential"]["credentialSubject"]["id"] = did_for_id

return filters

Expand Down
6 changes: 2 additions & 4 deletions aries-test-harness/features/steps/0037-present-proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,8 @@ def step_impl(context, verifier):
resp_json = json.loads(resp_text)
assert resp_json["state"] == "done"

# FIXME: why do we only store the verified property if support_revocation is enabled?
if context.support_revocation:
verified = resp_json["verified"] == True or resp_json["verified"] == "true"
context.credential_verification_dict[context.presentation_thread_id] = verified
verified = resp_json["verified"] == True or resp_json["verified"] == "true"
context.credential_verification_dict[context.presentation_thread_id] = verified


@then('"{prover}" has the proof verified')
Expand Down
29 changes: 29 additions & 0 deletions aries-test-harness/features/steps/0453-issue-credential-v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,20 @@ def step_impl(context, holder, cred_format, issuer, credential_data):
), f"credential data has no filter for cred format {cred_format}"
filters = {cred_format: context.filters[cred_format]}

# It the credential format is json-ls then get a holder did for the credentialSubject.id by calling the prepare-json-ld command.
if cred_format == CRED_FORMAT_JSON_LD:
holder_did_for_id = create_did_for_id(context, holder, cred_format)
else:
holder_did_for_id = None

# This call may need to be formated by cred_format instead of version. Reassess when more types are used.
credential_offer = format_cred_proposal_by_aip_version(
context,
"AIP20",
context.credential_data,
context.connection_id_dict[holder][issuer],
filters,
holder_did_for_id,
)

(resp_status, resp_text) = agent_backchannel_POST(
Expand All @@ -110,6 +117,28 @@ def step_impl(context, holder, cred_format, issuer, credential_data):
context.cred_thread_id = resp_json["thread_id"]


def create_did_for_id(context, agent: str, cred_format: str = CRED_FORMAT_INDY):
if cred_format == CRED_FORMAT_JSON_LD:
agent_url = context.config.userdata.get(agent)

data = {"did_method": context.did_method, "proof_type": context.proof_type}

(resp_status, resp_text) = agent_backchannel_POST(
agent_url + "/agent/command/",
"issue-credential-v2",
operation="prepare-json-ld",
data=data,
)

assert (
resp_status == 200
), f"issue-credential-v2/prepare-json-ld: resp_status {resp_status} is not 200; {resp_text}"
resp_json = json.loads(resp_text)

return resp_json["did"]
else:
raise Exception(f"Unknown credential format {cred_format}")

@given('"{issuer}" offers the "{cred_format}" credential')
@when('"{issuer}" offers the "{cred_format}" credential')
def step_impl(context, issuer, cred_format):
Expand Down
9 changes: 4 additions & 5 deletions aries-test-harness/features/steps/0454-present-proof-v2-v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,10 @@ def step_impl(context, verifier):
resp_json = json.loads(resp_text)
assert resp_json["state"] == "done"

if context.support_revocation:
# Add the verified property returned to the credential verification dictionary to check in subsequent steps. Key by presentation thread id
context.credential_verification_dict[
context.presentation_thread_id
] = strtobool(resp_json["verified"])
# Add the verified property returned to the credential verification dictionary to check in subsequent steps. Key by presentation thread id
context.credential_verification_dict[
context.presentation_thread_id
] = strtobool(resp_json["verified"])


@then('"{prover}" has the proof with formats verified')
Expand Down

0 comments on commit e4ceeb3

Please sign in to comment.