Skip to content

Commit

Permalink
fix: added static pkey for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalDR committed Feb 5, 2024
1 parent f1f2889 commit 8a1ef02
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 18 deletions.
5 changes: 5 additions & 0 deletions pymdoccbor/tests/pkey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pycose.keys import EC2Key

encoded_pkey = b'\xa6\x01\x02\x03& \x01!X \x8d%C\x91\xe8\x17A\xe1\xc2\xc1\'J\xa7\x1e\xe6J\x03\xc4\xc9\x8a\x91 hV\xcd\x10yb\x9f\xf7\xbe\x9a"X H\x8a\xc3\xd4\xc2\xea\x9bX\x9d\x9d\xf1~\x0c!\x92\xda\xfd\x02s\x0ci\xee\x190i\x88J\xddt\x14\x03\x95#X \xcd\xe1^\x92\xc8z\xd9&&\x0f\x0c\xbd\x8f4r}z\x03\x83\xe0\xf2\x8e\xcc\x04\x13M\xe1\xafXH\xcbT'

PKEY = EC2Key.decode(encoded_pkey)
4 changes: 2 additions & 2 deletions pymdoccbor/tests/test_02_mdoc_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from pymdoccbor.mdoc.issuer import MdocCborIssuer
from pymdoccbor.mdoc.verifier import MdocCbor
from pymdoccbor.mso.issuer import MsoIssuer
from . pid_data import PID_DATA
from pymdoccbor.tests.pid_data import PID_DATA
from pymdoccbor.tests.pkey import PKEY


PKEY = EC2Key.generate_key(crv="P_256", optional_params={"ALG": "ES256"})

def test_mso_writer():
msoi = MsoIssuer(
Expand Down
4 changes: 1 addition & 3 deletions pymdoccbor/tests/test_03_mdoc_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
from pymdoccbor.mdoc.issuer import MdocCborIssuer
from pymdoccbor.tests.micov_data import MICOV_DATA
from pymdoccbor.tests.pid_data import PID_DATA


PKEY = EC2Key.generate_key(crv="P_256", optional_params={"ALG": "ES256"})
from pymdoccbor.tests.pkey import PKEY

mdoc = MdocCborIssuer(PKEY)

Expand Down
2 changes: 1 addition & 1 deletion pymdoccbor/tests/test_04_issuer_signed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from pymdoccbor.mdoc.issuer import MdocCborIssuer
from pymdoccbor.tests.micov_data import MICOV_DATA
from pymdoccbor.tests.test_03_mdoc_issuer import mdoc
from pymdoccbor.tests.pkey import PKEY

PKEY = EC2Key.generate_key(crv="P_256", optional_params={"ALG": "ES256"})

mdoc = MdocCborIssuer(PKEY)
mdoc.new(
Expand Down
43 changes: 33 additions & 10 deletions pymdoccbor/tests/test_05_mdoc_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@
from pymdoccbor.mdoc.verifier import MobileDocument
from pymdoccbor.mdoc.issuer import MdocCborIssuer
from pymdoccbor.tests.micov_data import MICOV_DATA

PKEY = EC2Key.generate_key(crv="P_256", optional_params={"ALG": "ES256"})

mdoc = MdocCborIssuer(PKEY)
mdoc.new(
data=MICOV_DATA,
devicekeyinfo=PKEY, # TODO
doctype="org.micov.medical.1"
)
from pymdoccbor.tests.pkey import PKEY

def test_verifier_must_fail_document_type():
try:
Expand All @@ -25,13 +17,29 @@ def test_verifier_must_fail_issuer_signed():
assert str(e) == "You must provide a signed document"

def test_mobile_document():
mdoc = MdocCborIssuer(PKEY)
mdoc.new(
data=MICOV_DATA,
devicekeyinfo=PKEY, # TODO
doctype="org.micov.medical.1"
)


document = mdoc.signed["documents"][0]
doc = MobileDocument(**document)

assert doc.doctype == "org.micov.medical.1"
assert doc.issuersigned

def test_mobile_document_dump():
mdoc = MdocCborIssuer(PKEY)
mdoc.new(
data=MICOV_DATA,
devicekeyinfo=PKEY, # TODO
doctype="org.micov.medical.1"
)


document = mdoc.signed["documents"][0]
doc = MobileDocument(**document)

Expand All @@ -41,6 +49,14 @@ def test_mobile_document_dump():
assert len(dump) > 0

def test_mobile_document_dumps():
mdoc = MdocCborIssuer(PKEY)
mdoc.new(
data=MICOV_DATA,
devicekeyinfo=PKEY, # TODO
doctype="org.micov.medical.1"
)


document = mdoc.signed["documents"][0]
doc = MobileDocument(**document)

Expand All @@ -50,7 +66,14 @@ def test_mobile_document_dumps():
assert len(dumps) > 0

def test_mobile_document_verify():
mdoc = MdocCborIssuer(PKEY)
mdoc.new(
data=MICOV_DATA,
devicekeyinfo=PKEY, # TODO
doctype="org.micov.medical.1"
)

document = mdoc.signed["documents"][0]
doc = MobileDocument(**document)

assert doc.verify() == True
assert doc.verify()
2 changes: 1 addition & 1 deletion pymdoccbor/tests/test_06_mso_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from pycose.messages import CoseMessage
from pymdoccbor.mso.issuer import MsoIssuer
from pymdoccbor.tests.micov_data import MICOV_DATA
from pymdoccbor.tests.pkey import PKEY

PKEY = EC2Key.generate_key(crv="P_256", optional_params={"ALG": "ES256"})

def test_mso_issuer_fail():
try:
Expand Down
2 changes: 1 addition & 1 deletion pymdoccbor/tests/test_07_mso_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from pymdoccbor.mdoc.issuer import MdocCborIssuer
from pymdoccbor.tests.micov_data import MICOV_DATA
from pycose.messages import CoseMessage
from pymdoccbor.tests.pkey import PKEY

PKEY = EC2Key.generate_key(crv="P_256", optional_params={"ALG": "ES256"})

mdoc = MdocCborIssuer(PKEY)
mdoc.new(
Expand Down

0 comments on commit 8a1ef02

Please sign in to comment.