Skip to content

Commit

Permalink
Add #25 Add bdd test for issue_616.feature
Browse files Browse the repository at this point in the history
  • Loading branch information
albinpa authored and georgepadayatti committed Jan 17, 2024
1 parent c4a3d25 commit 25b55ab
Show file tree
Hide file tree
Showing 9 changed files with 964 additions and 11 deletions.
31 changes: 31 additions & 0 deletions fixtures/generate_signatures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import json

from jwcrypto import jwk, jwt



def generate_secp256r1_jwk():
# Generate EC key pair for secp256r1 curve
key = jwk.JWK.generate(kty="EC", crv="P-256")
return key


def sign_jws(payload, private_key):
# Generate JSON web signature
key = jwk.JWK(**private_key)
token = jwt.JWT(header={"alg": "ES256"}, claims=payload)
token.make_signed_token(key)
return token.serialize()

private_key = generate_secp256r1_jwk()

payload = "{\"schemaName\":\"ConsentRecord\",\"objectId\":\"2\",\"signedWithoutObjectId\":false,\"timestamp\":\"2024-01-17T10:15:07Z\",\"authorizedByIndividualId\":\"1\",\"authorizedByOtherId\":\"\",\"objectData\":\"{\\\"id\\\":\\\"2\\\",\\\"dataAgreementId\\\":\\\"2\\\",\\\"dataAgreementRevisionId\\\":\\\"659fd68befcb8216c24c2695\\\",\\\"dataAgreementRevisionHash\\\":\\\"3f0f5aef5e79afb50428ed835ad628db449c4504\\\",\\\"individualId\\\":\\\"1\\\",\\\"optIn\\\":true,\\\"state\\\":\\\"signed\\\",\\\"signatureId\\\":\\\"1\\\"}\"}"

jws_token = sign_jws(payload, private_key.export(as_dict=True))

print(
f"Public key JWK:\n{json.dumps(private_key.export(private_key=False, as_dict=False), indent=2)}\n"
)
print(f"JWS:\n{jws_token}")


42 changes: 42 additions & 0 deletions fixtures/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,46 @@ def populate_policies(db):
except Exception as e:
print(e)

def populate_signatures(db):
try:
signatures_collection = db["signatures"]

# Populate signatures collection
seed_year = 2012
index = 0

for signature in data.get("signatures", []):

# Save signatures to db
signatures_collection.insert_one(
{
"_id": signature.get(
"id", generate_object_id(seed_year + index, 1, 1)
),
"payload": signature.get("payload", ""),
"signature": signature.get("signature", ""),
"verificationmethod": signature.get(
"verificationMethod", ""
),
"verificationpayload": signature.get("verificationPayload", ""),
"verificationpayloadhash": signature.get(
"verificationPayloadHash", ""
),
"verificationartifact": signature.get("verificationArtifact", ""),
"verificationsignedby": signature.get("verificationSignedBy", ""),
"verificationsignedas": signature.get("verificationSignedAs", ""),
"verificationjwsheader": signature.get("verificationJwsHeader", ""),
"timestamp": signature.get("timestamp", ""),
"signedwithoutobjectreference": signature.get("signedWithoutObjectReference", ""),
"objecttype": signature.get("objectType", ""),
"objectreference": signature.get("objectReference", ""),
}
)

index += 1
except Exception as e:
print(e)


def update_organisation_id(db):
try:
Expand Down Expand Up @@ -586,6 +626,8 @@ def main():
populate_policies(db)
# Populate revisions in mongodb
populate_revisions(db=db)
# Populate signatures in mongodb
populate_signatures(db)

# Update caddy with default access token headers for organisation admin and individual endpoints
org_admin_token = login_organisation_admin(
Expand Down
239 changes: 238 additions & 1 deletion fixtures/poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions fixtures/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ python = "^3.10"
pymongo = "^4.6.0"
python-keycloak = "^3.7.0"
requests = "^2.31.0"
jwcrypto = "^1.5.1"


[build-system]
Expand Down
10 changes: 5 additions & 5 deletions gherkin/features/issue_616/issue_616.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ Feature: Review signature workflow in Consent Records
And consent record contains `state` field as signed
And revision contains `signedWithoutObjectId` field as true
And `serializedSnapshot` contains `objectId` field with empty value
And signature container `signedWithoutObjectReference` field as true
And signature contains `signedWithoutObjectReference` field as true
And signature contains `objectReference` field with empty value
And signature is verified by recreating the payload from revision in response

Examples:
| dataAgreementId |
| 1 |
| 4 |

@positive
Scenario Outline: Update consent record and add a new signature
Expand All @@ -36,13 +36,13 @@ Feature: Review signature workflow in Consent Records
And consent record contains `state` field as signed
And revision contains `signedWithoutObjectId` field as false
And `serializedSnapshot` contains `objectId` field with "<consentRecordId>"
And signature container `signedWithoutObjectReference` field as false
And signature contains `signedWithoutObjectReference` field as false
And signature contains `objectReference` field with "<revisionId>"
And signature is verified by recreating the payload from revision in response

Examples:
| consentRecordId | revisionId |
| 1 | 1 |
| 2 | 1 |


@positive
Expand All @@ -53,6 +53,6 @@ Feature: Review signature workflow in Consent Records

Examples:
| consentRecordId | revisionId |
| 1 | 1 |
| 3 | 2 |


Loading

0 comments on commit 25b55ab

Please sign in to comment.