Skip to content

Commit

Permalink
Fix for #213 -> test script is stricter than spec and Updated Known I…
Browse files Browse the repository at this point in the history
…ssue List (#224)

* Updated known Issue List

* Updated known issue listing

* Enhanced Error Handling Capability to be able to flag invalid JSON files as knwon failures and updated Known Issue List.

* Enhanced Error Handling Capability to be able to flag invalid JSON files as knwon failures and updated Known Issue List.

* Update dgc-testdata-verification.yml

* Update dgc-testdata-verification.yml

* Update dgc-testdata-verification.yml

* Update dgc-testdata-verification.yml

* Update requirements.txt

* Update dgc-testdata-verification.yml

* Update dgc-testdata-verification.yml

* Update requirements.txt

* Enhanced error handling and reporting for test_picture_decode

* Fix for #213 -> test script is stricter than spec and Updated Known Issue List
  • Loading branch information
bhavin-qryptal authored May 26, 2021
1 parent f1771f3 commit 850c906
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 30 deletions.
4 changes: 2 additions & 2 deletions BE/2DCode/raw/3.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"t": [{
"tg": "840539006",
"tt": "LP6464-4",
"sc": "2021-05-25T09:02:07Z",
"dr": "2021-05-15T19:21:22Z",
"sc": "2021-05-25T09:02:07.000000Z",
"dr": "2021-05-15T19:21:22.000000Z",
"tr": "260415000",
"tc": "81160393",
"co": "BE",
Expand Down
20 changes: 0 additions & 20 deletions tests/known_issues.csv
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
test_name,country,test_set,reason
test_expected_key_usage,NL,,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/146
test_cose_schema,NL,,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/107
test_verification_check,ES,401,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/32
test_verification_check,ES,402,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/32
test_verification_check,ES,403,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/32
,ES,1201,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/32
,ES,1202,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/32
test_expected_key_usage,ES,,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/168
test_verification_check,ES,1203,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/32
test_expiration_check,ES,,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/169
test_cose_schema,ES,1203,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/32
test_cose_json,ES,1203,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/32
test_cose_cbor,ES,1203,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/32
,BE,3,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/150
,FR,test_pcr_ok,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/141
test_expiration_check,PL,1,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/188
test_cose_json,PL,4,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/189
test_cose_json,PL,5,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/189
test_cbor_json,PL,4,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/189
test_cbor_json,PL,5,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/189
,PT,1,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/151
,PT,2,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/151
,PT,3,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/151
Expand All @@ -31,9 +14,6 @@ test_cbor_json,PL,5,https://github.com/eu-digital-green-certificates/dgc-testdat
,CZ,3,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/172
,CZ,4,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/172
,CZ,5,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/172
test_cose_schema,SE,7,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/213 -> test script is stricter than spec
test_cose_json,SE,7,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/213 -> test script is stricter than spec
test_cbor_json,SE,7,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/213 -> test script is stricter than spec
test_cose_schema,SI,1,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/220
test_cose_schema,SI,2,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/220
test_cose_schema,SI,3,https://github.com/eu-digital-green-certificates/dgc-testdata/issues/220
Expand Down
23 changes: 15 additions & 8 deletions tests/test_ehealth_certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from base64 import b64decode
from binascii import hexlify, unhexlify
from csv import DictReader
from datetime import datetime, timezone
from datetime import date, datetime, timezone
from glob import glob
from io import BytesIO
from json import load
Expand Down Expand Up @@ -89,6 +89,7 @@
EXPECTED_SCHEMA_VALIDATION = 'EXPECTEDSCHEMAVALIDATION'
EXPECTED_COMPRESSION = 'EXPECTEDCOMPRESSION'
EXPECTED_KEY_USAGE = 'EXPECTEDKEYUSAGE'
TIMESTAMP_ISO8601_EXTENDED = "%Y-%m-%dT%H:%M:%S.%fZ"

CBOR = 'CBOR'
CERTIFICATE = 'CERTIFICATE'
Expand Down Expand Up @@ -159,10 +160,15 @@ def xfail_known_issues(request, known_issue: str):
request.applymarker(mark.xfail(reason=known_issue))


def _object_hook(decoder, value):
return {k: v.astimezone(timezone.utc).strftime(TIMESTAMP_ISO8601_EXTENDED) if isinstance(v, (date, datetime)) else v
for k, v in value.items()}


def _dgc(config_env: Dict) -> Sign1Message:
if COSE in config_env.keys():
cbor_bytes = unhexlify(config_env[COSE])
cbor_object = loads(cbor_bytes)
cbor_object = loads(cbor_bytes, object_hook=_object_hook)
if isinstance(cbor_object, CBORTag): # Tagged Cose Object
if isinstance(cbor_object.value, CBORTag): # Double Tagged Cose Object
decoded = Sign1Message.from_cose_obj(cbor_object.value.value)
Expand Down Expand Up @@ -265,7 +271,7 @@ def test_cose_schema(config_env: Dict):

if config_env[EXPECTED_RESULTS][EXPECTED_SCHEMA_VALIDATION]:
dgc = _dgc(config_env)
cose_payload = loads(dgc.payload)
cose_payload = loads(dgc.payload, object_hook=_object_hook)
assert PAYLOAD_HCERT in cose_payload.keys()
assert len(cose_payload[PAYLOAD_HCERT]) == 1
assert 1 in cose_payload[PAYLOAD_HCERT].keys()
Expand All @@ -282,7 +288,7 @@ def test_cose_json(config_env: Dict):
if not ({COSE, JSON} <= config_env.keys()):
skip(f'Test dataset does not contain {COSE} and/or {JSON}')
dgc = _dgc(config_env)
cose_payload = loads(dgc.payload)
cose_payload = loads(dgc.payload, object_hook=_object_hook)
if config_env[EXPECTED_RESULTS][EXPECTED_DECODE]:
assert PAYLOAD_HCERT in cose_payload.keys()
assert len(cose_payload[PAYLOAD_HCERT]) == 1
Expand All @@ -302,6 +308,7 @@ def test_cbor_json(config_env: Dict):
skip(f'Test dataset does not contain {CBOR} and/or {JSON}')
cbor_bytes = unhexlify(config_env[CBOR])
cbor_object = loads(cbor_bytes)
cbor_object = loads(cbor_bytes, object_hook=_object_hook)
if config_env[EXPECTED_RESULTS][EXPECTED_DECODE]:
# assert PAYLOAD_HCERT in cbor_object.keys()
if PAYLOAD_HCERT in cbor_object.keys(): # Hack in order to match different level of CBOR Payload
Expand All @@ -319,9 +326,9 @@ def test_cose_cbor(config_env: Dict):
if not ({CBOR, COSE} <= config_env.keys()):
skip(f'Test dataset does not contain {CBOR} and/or {COSE}')
cbor_bytes = unhexlify(config_env[CBOR])
cbor_payload = loads(cbor_bytes)
cbor_payload = loads(cbor_bytes, object_hook=_object_hook)
dgc = _dgc(config_env)
cose_payload = loads(dgc.payload)
cose_payload = loads(dgc.payload, object_hook=_object_hook)

if config_env[EXPECTED_RESULTS][EXPECTED_DECODE]:
if PAYLOAD_HCERT not in cbor_payload.keys(): # Hack in order to match different level of CBOR Payload
Expand Down Expand Up @@ -384,7 +391,7 @@ def test_expiration_check(config_env: Dict):
dsc = _dsc(config_env)
dsc_not_valid_before, dsc_not_valid_after = dsc[3], dsc[4]
dgc = _dgc(config_env)
decoded_payload = loads(dgc.payload)
decoded_payload = loads(dgc.payload, object_hook=_object_hook)
assert {PAYLOAD_EXPIRY_DATE, PAYLOAD_ISSUE_DATE} <= decoded_payload.keys(), \
f'COSE Payload is missing expiry date: {PAYLOAD_EXPIRY_DATE} and/or issue date: {PAYLOAD_ISSUE_DATE}.'
dgc_expiry_date = datetime.fromtimestamp(decoded_payload[PAYLOAD_EXPIRY_DATE], tz=timezone.utc)
Expand Down Expand Up @@ -416,7 +423,7 @@ def test_expected_key_usage(config_env: Dict):
dsc = _dsc(config_env)
dsc_supported_operations = dsc[2]
dgc = _dgc(config_env)
cose_payload = loads(dgc.payload)
cose_payload = loads(dgc.payload, object_hook=_object_hook)
assert PAYLOAD_HCERT in cose_payload.keys()
assert len(cose_payload[PAYLOAD_HCERT]) == 1
assert 1 in cose_payload[PAYLOAD_HCERT].keys()
Expand Down

0 comments on commit 850c906

Please sign in to comment.