Skip to content
Snippets Groups Projects
Commit 771e9250 authored by Mike Sell's avatar Mike Sell
Browse files

added proof request tests

parent 776f2c79
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ Feature: Credentials proofs are generated and accepted
Scenario: Holder accepts proof request from verifier
Given verifier requests proof of issued credential
When holder accepts proof request
Given an issued credential
When a verifier requests credential proof
And holder accepts proof request
Then the credential is proofed
\ No newline at end of file
# # As an OCM user
# # I want to create a new Schema
# Feature: Create a new Schema, and list Schemas
# Create a new Schema on Ledger and save details in DB
# List all Schemas on Ledger
# # Acronyms:
# # DB = Database
# # DID = Decentralized Identifier
# Background:
# Given I can connect to OCM Engine
# Scenario: Register valid Schema Details
# Given I register a DID for 'issuer'
# When I register a new schema
# Then schema is created on the Ledger
# # no name at all?
# Scenario Outline: Scenario Outline name: Attempting to register a Schema with empty details results in error
# Given I register a DID for 'issuer'
# When I register a new schema with a <schema_name>, <issuer_did>, <version> and <attribute_name>
# Then I get HTTP status code 400 Bad Request.
# # And I get a descriptive <error_message>
# # Schema_name and issuer_did generated during test run
# # Below can be expanded to have corresponding bad request message
# Examples:
# | schema_name | issuer_did | version | attribute_name |
# | False | True | "1.0.0" | "attribute" |
# | True | False | "1.0.0" | "attribute" |
# | True | True | "" | "attribute" |
# | True | True | "1.0.0" | "" |
# Scenario: Provide duplicate name and version of the existing Schema.
# Given I register a DID for 'issuer'
# When I register a new schema
# And I register the same schema
# Then I get HTTP status code 409 Conflict.
# Scenario: List schemas by issuer id.
# Given I have a schema registered.
# When fetch schema via issuer id.
# Then I get the schema
# As an OCM user
# I want to create a new Schema
Feature: Create a new Schema, and list Schemas
Create a new Schema on Ledger and save details in DB
List all Schemas on Ledger
# Acronyms:
# DB = Database
# DID = Decentralized Identifier
Background:
Given I can connect to OCM Engine
Scenario: Register valid Schema Details
Given I register a DID for 'issuer'
When I register a new schema
Then schema is created on the Ledger
# no name at all?
Scenario Outline: Scenario Outline name: Attempting to register a Schema with empty details results in error
Given I register a DID for 'issuer'
When I register a new schema with a <schema_name>, <issuer_did>, <version> and <attribute_name>
Then I get HTTP status code 400 Bad Request.
# And I get a descriptive <error_message>
# Schema_name and issuer_did generated during test run
# Below can be expanded to have corresponding bad request message
Examples:
| schema_name | issuer_did | version | attribute_name |
| False | True | "1.0.0" | "attribute" |
| True | False | "1.0.0" | "attribute" |
| True | True | "" | "attribute" |
| True | True | "1.0.0" | "" |
Scenario: Provide duplicate name and version of the existing Schema.
Given I register a DID for 'issuer'
When I register a new schema
And I register the same schema
Then I get HTTP status code 409 Conflict.
Scenario: List schemas by issuer id.
Given I have a schema registered.
When fetch schema via issuer id.
Then I get the schema
# Scenario: List schema error on invalid issuer id.
# Given I have a schema registered.
# When fetch schema via invalid issuer id.
# Then I get HTTP status code 400 Bad Request.
Scenario: List schema error on invalid issuer id.
Given I have a schema registered.
When fetch schema via invalid issuer id.
Then I get HTTP status code 400 Bad Request.
......@@ -3,6 +3,18 @@ import string
import requests
import json
import time
import random
# Lists of business jargon adjectives and nouns
business_adjectives = ["synergistic", "strategic", "innovative", "disruptive", "proactive"]
business_nouns = ["solution", "strategy", "paradigm", "optimization", "monetization"]
# Generate a random business jargon adjective and noun
def generate_random_business_name():
random_business_adjective = random.choice(business_adjectives)
random_business_noun = random.choice(business_nouns)
return f"{random_business_adjective}_{random_business_noun}"
def generate_random_string(length):
"""Generate a secure random alphanumeric string of given length."""
......@@ -13,7 +25,7 @@ def generate_random_string(length):
def register_endorser_did(url_base, payload={}, header={}):
endorser_url = url_base+'/register-endorser-did'
requests.post(endorser_url, headers=header, data=payload)
requests.post(endorser_url, headers=header, data=payload, timeout=60)
def create_issuer_tennant(url_base,
......@@ -22,7 +34,7 @@ def create_issuer_tennant(url_base,
):
url = url_base+"/create-tenant"
return requests.post(url, headers=headers, data=payload)
return requests.post(url, headers=headers, data=payload, timeout=60)
def create_holder_tennant(url_base,
......@@ -31,7 +43,7 @@ def create_holder_tennant(url_base,
):
url = url_base+"/create-tenant"
return requests.post(url, headers=headers, data=payload)
return requests.post(url, headers=headers, data=payload, timeout=60)
def create_verifier_tennant(url_base,
......@@ -40,7 +52,7 @@ def create_verifier_tennant(url_base,
):
url = url_base+"/create-tenant"
return requests.post(url, headers=headers, data=payload)
return requests.post(url, headers=headers, data=payload, timeout=60)
def register_issuer_did(url_base,
......@@ -83,7 +95,7 @@ def register_issuer_did(url_base,
})
url = url_base+'/v1/dids?tenantId='+issuer_id
return requests.post(url, headers=headers, data=payload)
return requests.post(url, headers=headers, data=payload, timeout=60)
def post_schemas(url_base,
......@@ -107,7 +119,7 @@ def post_schemas(url_base,
]
})
return requests.post(url, headers=header, data=payload)
return requests.post(url, headers=header, data=payload, timeout=60)
def get_schemas(url_base,
......@@ -117,7 +129,7 @@ def get_schemas(url_base,
url = url_base+'/v1/schemas?tenantId='+issuer_id
return requests.get(url, headers=headers, data=payload)
return requests.get(url, headers=headers, data=payload, timeout=60)
def post_credential_definition(url_base,
......@@ -134,7 +146,7 @@ def post_credential_definition(url_base,
"supportsRevocation": False
})
return requests.post(url, headers=header, data=payload)
return requests.post(url, headers=header, data=payload, timeout=60)
def list_credential_definitions(url_base,
......@@ -144,7 +156,7 @@ def list_credential_definitions(url_base,
payload = {}
headers = {}
return requests.get(url, headers=headers, data=payload)
return requests.get(url, headers=headers, data=payload, timeout=60)
def create_invitation(url_base,
......@@ -156,7 +168,7 @@ def create_invitation(url_base,
'Content-Type': 'application/json'
}
return requests.post(url, headers=headers, data=payload)
return requests.post(url, headers=headers, data=payload, timeout=60)
def create_connection_to_self(url_base,
......@@ -166,7 +178,7 @@ def create_connection_to_self(url_base,
payload = {}
headers = {}
return requests.post(url, headers=headers, data=payload)
return requests.post(url, headers=headers, data=payload, timeout=60)
def get_connection_id(url_base,
......@@ -177,7 +189,7 @@ def get_connection_id(url_base,
headers = {}
time.sleep(1)
return requests.get(url, headers=headers, data=payload, timeout=10)
return requests.get(url, headers=headers, data=payload, timeout=60)
def receive_invitation(url_base,
......@@ -194,7 +206,7 @@ def receive_invitation(url_base,
'Content-Type': 'application/json'
}
return requests.post(url, headers=headers, data=payload, timeout=10)
return requests.post(url, headers=headers, data=payload, timeout=60)
def get_tenant_holder_connection_id_for_tenant(url_base, tenant_id):
......@@ -233,7 +245,7 @@ def make_credential_offer(url_base,
'Content-Type': 'application/json'
}
return requests.post(url, headers=headers, data=payload, timeout=10)
return requests.post(url, headers=headers, data=payload, timeout=60)
def get_credential_offer(url_base,
tenant_id):
......@@ -244,7 +256,7 @@ def get_credential_offer(url_base,
headers = {}
time.sleep(1)
response = requests.get(url, headers=headers, data=payload, timeout=10)
response = requests.get(url, headers=headers, data=payload, timeout=60)
return response.json()["data"][0]["id"]
def accept_credential_offer(url_base,
......@@ -256,7 +268,7 @@ def accept_credential_offer(url_base,
payload = {}
headers = {}
return requests.post(url, headers=headers, data=payload, timeout=10)
return requests.post(url, headers=headers, data=payload, timeout=60)
def get_credentials(url_base,
tenant_id):
......@@ -265,7 +277,7 @@ def get_credentials(url_base,
payload = {}
headers = {}
return requests.get(url, headers=headers, data=payload, timeout=10)
return requests.get(url, headers=headers, data=payload, timeout=60)
def create_credential_offer_to_self(url_base,
tenant_id,
......@@ -296,4 +308,62 @@ def create_credential_offer_to_self(url_base,
'Content-Type': 'application/json'
}
return requests.post(url, headers=headers, data=payload, timeout=60)
def request_credential_proof(url_base,
tenant_id,
connection_id):
url = url_base+ "/v1/proofs?tenantId="+tenant_id
payload = json.dumps({
"name": generate_random_business_name(),
"connectionId": connection_id,
"requestedAttributes": {
"height": {
"names": [
"height"
]
},
"weight": {
"names": [
"weight"
]
},
"age": {
"names": [
"age"
]
}
},
"requestedPredicates": {}
})
headers = {
'Content-Type': 'application/json'
}
return requests.post(url, headers=headers, data=payload, timeout=60)
def get_tenant_proof_request(url_base,
tenant_id):
url = url_base+ "/v1/proofs?tenantId="+tenant_id
payload = {}
headers = {}
time.sleep(1)
return requests.get(url, headers=headers, data=payload, timeout=60)
def accept_proof_request(url_base,
tenant_id,
proof_record_id):
url = url_base + "/v1/proofs/" + proof_record_id + "/accept?tenantId=" + tenant_id
payload = {}
headers = {}
return requests.post(url, headers=headers, data=payload, timeout=60)
\ No newline at end of file
......@@ -6,7 +6,7 @@ from connection import create_invitation_url, accept_invititation, make_connecti
@given(u'issuer to holder connection established')
def step_impl(context):
def connection_established(context):
post_schema_complete(context)
post_credential_def(context)
create_invitation_url(context)
......@@ -19,7 +19,7 @@ def step_impl(context):
@when(u'issuer makes a credential offer')
def step_impl(context):
def credential_offer(context):
context.response = make_credential_offer(context.credential_manager_base_URL,
context.issuer_id,
context.issuer_holder_connection_id_for_issuer,
......@@ -33,7 +33,7 @@ def step_impl(context):
@when(u'holder accepts credential offer')
def step_impl(context):
def holder_accepts_offer(context):
context.holder_credential_offer_id = get_credential_offer(url_base=context.credential_manager_base_URL,
tenant_id=context.holder_id_2)
......
from behave import *
from helper import create_invitation, receive_invitation, get_tenant_holder_connection_id_for_tenant, request_credential_proof, get_tenant_proof_request, accept_proof_request
from schema import post_schema_complete
from credential_definitions import post_credential_def
from issue_credentials import connection_established, credential_offer, holder_accepts_offer
@given(u'an issued credential')
def step_impl(context):
connection_established(context)
credential_offer(context)
holder_accepts_offer(context)
@when(u'a verifier requests credential proof')
def step_impl(context):
# context.verifier_id
response = create_invitation(url_base=context.connection_manager_base_URL, tenant_id=context.verifier_id)
invitation_url = response.json()["data"]["invitationUrl"]
context.response = receive_invitation(url_base=context.connection_manager_base_URL,
tenant_id=context.holder_id_2,
invitation_url=invitation_url)
verifier_holder_connection_to_verifier = get_tenant_holder_connection_id_for_tenant(url_base=context.connection_manager_base_URL,
tenant_id=context.verifier_id)
request_credential_proof(url_base=context.proof_manager_base_URL,
tenant_id=context.verifier_id,
connection_id=verifier_holder_connection_to_verifier)
@when(u'the proof request is listed')
def step_impl(context):
context.response = get_tenant_proof_request(url_base=context.proof_manager_base_URL,
tenant_id=context.verifier_id)
@then(u'proof request exists')
def step_impl(context):
assert context.response.status_code == 200
@when(u'holder accepts proof request')
def step_impl(context):
response = get_tenant_proof_request(url_base=context.proof_manager_base_URL,
tenant_id=context.holder_id_2)
context.proof_record_id = response.json()["data"][0]["id"]
context.response = accept_proof_request(url_base=context.proof_manager_base_URL,
tenant_id=context.holder_id_2,
proof_record_id=context.proof_record_id)
@then(u'the credential is proofed')
def step_impl(context):
assert context.response.status_code == 200
assert context.response.json()["data"]["state"] == "presentation-sent"
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment