@@ -175,7 +175,7 @@ def test_sample_readme_signed_cwt_es256(self):
175175 decoded = cwt .decode (token , public_key )
176176 assert 1 in decoded and decoded [1 ] == "coaps://as.example"
177177
178- def test_sample_readme_signed_cwt_es256_with_cert (self ):
178+ def test_sample_readme_signed_cwt_es256_with_cert_missing_required_extension (self ):
179179 # with open(key_path("cacert.pem")) as f:
180180 # k1 = x509.load_pem_x509_certificate(f.read().encode("utf-8"))
181181
@@ -196,10 +196,14 @@ def test_sample_readme_signed_cwt_es256_with_cert(self):
196196 token = cwt .encode ({"iss" : "coaps://as.example" , "sub" : "dajiaji" , "cti" : "123" }, private_key )
197197
198198 decoder = CWT .new (ca_certs = key_path ("cacert.pem" ))
199- decoded = decoder .decode (token , public_key )
200- assert 1 in decoded and decoded [1 ] == "coaps://as.example"
199+ with pytest .raises (VerifyError ) as err :
200+ decoder .decode (token , public_key )
201+ pytest .fail ("decode() should fail." )
202+ assert "Failed to validate the certificate bound to the key." in str (err .value )
203+ # decoded = decoder.decode(token, public_key)
204+ # assert 1 in decoded and decoded[1] == "coaps://as.example"
201205
202- def test_sample_readme_signed_cwt_es256_with_cert_without_intermediates (self ):
206+ def test_sample_readme_signed_cwt_es256_with_cert_missing_required_extension_without_intermediates (self ):
203207 with open (key_path ("private_key_cert_es256.pem" )) as f :
204208 private_key = COSEKey .from_pem (f .read (), kid = "P-256-01" )
205209
@@ -209,8 +213,12 @@ def test_sample_readme_signed_cwt_es256_with_cert_without_intermediates(self):
209213 token = cwt .encode ({"iss" : "coaps://as.example" , "sub" : "dajiaji" , "cti" : "123" }, private_key )
210214
211215 decoder = CWT .new (ca_certs = key_path ("cacert.pem" ))
212- decoded = decoder .decode (token , public_key )
213- assert 1 in decoded and decoded [1 ] == "coaps://as.example"
216+ with pytest .raises (VerifyError ) as err :
217+ decoder .decode (token , public_key )
218+ pytest .fail ("decode() should fail." )
219+ assert "Failed to validate the certificate bound to the key." in str (err .value )
220+ # decoded = decoder.decode(token, public_key)
221+ # assert 1 in decoded and decoded[1] == "coaps://as.example"
214222
215223 def test_sample_readme_signed_cwt_es256_with_another_ca_cert (self ):
216224 with open (key_path ("private_key_cert_es256.pem" )) as f :
0 commit comments