Skip to content

Commit e2454c5

Browse files
authored
Merge pull request #410 from italia/fix/integration_tests
Fix for integration tests
2 parents 1114780 + 61161e5 commit e2454c5

File tree

8 files changed

+86
-58
lines changed

8 files changed

+86
-58
lines changed

example/satosa/pyeudiw_backend.yaml

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,14 @@ config:
114114

115115
# private jwk
116116
metadata_jwks: &metadata_jwks
117-
- crv: P-256 # Please note: this is the first key [0] and it is used for signing the presentation requests
118-
d: KzQBowMMoPmSZe7G8QsdEWc1IvR2nsgE8qTOYmMcLtc
119-
kid: dDwPWXz5sCtczj7CJbqgPGJ2qQ83gZ9Sfs-tJyULi6s
117+
- kty: EC # Please note: this is the first key [0] and it is used for signing the presentation requests
118+
d: i0HQiqDPXf-MqC776ztbgOCI9-eARhcUczqJ-7_httc
120119
use: sig
121-
kty: EC
122-
x: TSO-KOqdnUj5SUuasdlRB2VVFSqtJOxuR5GftUTuBdk
123-
y: ByWgQt1wGBSnF56jQqLdoO1xKUynMY-BHIDB3eXlR7
120+
crv: P-256
121+
kid: SQgNjv4yU8sfuafJ2DPWq2tnOlK1JSibd3V5KqYRhOk
122+
x: Q46FDkhMjewZIP9qP8ZKZIP-ZEemctvjxeP0l3vWHMI
123+
y: IT7lsGxdJewmonk9l1_TAVYx_nixydTtI1Sbn0LkfEA
124+
alg: ES256
124125
- kty: RSA
125126
d: QUZsh1NqvpueootsdSjFQz-BUvxwd3Qnzm5qNb-WeOsvt3rWMEv0Q8CZrla2tndHTJhwioo1U4NuQey7znijhZ177bUwPPxSW1r68dEnL2U74nKwwoYeeMdEXnUfZSPxzs7nY6b7vtyCoA-AjiVYFOlgKNAItspv1HxeyGCLhLYhKvS_YoTdAeLuegETU5D6K1xGQIuw0nS13Icjz79Y8jC10TX4FdZwdX-NmuIEDP5-s95V9DMENtVqJAVE3L-wO-NdDilyjyOmAbntgsCzYVGH9U3W_djh4t3qVFCv3r0S-DA2FD3THvlrFi655L0QHR3gu_Fbj3b9Ybtajpue_Q
126127
e: AQAB
@@ -193,8 +194,6 @@ config:
193194
- module: pyeudiw.openid4vp.vp_sd_jwt_vc
194195
class: VpVcSdJwtParserVerifier
195196
format: dc+sd-jwt
196-
config:
197-
sig_alg_supported: *sig_alg_supported
198197
- module: pyeudiw.openid4vp.vp_mdoc_cbor
199198
class: VpMDocCbor
200199
format: mso_mdoc
@@ -262,28 +261,28 @@ config:
262261
# client_id: *client_id
263262
client_id_scheme: x509_san_dns # this will be prepended in the client id scheme used in the request.
264263
certificate_authorities:
265-
- ca.example.com: |
266-
-----BEGIN CERTIFICATE-----
267-
MIIDYzCCAkugAwIBAgIUHVMNJD9vqAA4mR+QAJyEQFW4kjQwDQYJKoZIhvcNAQEL
268-
BQAwUjEuMCwGA1UEAwwlQ049Y2EuZXhhbXBsZS5jb20sIE89RXhhbXBsZSBDQSwg
269-
Qz1JVDETMBEGA1UECgwKRXhhbXBsZSBDQTELMAkGA1UEBhMCSVQwHhcNMjUwNDAz
270-
MTU0NzU2WhcNMjYwNDA0MTU0NzU2WjBSMS4wLAYDVQQDDCVDTj1jYS5leGFtcGxl
271-
LmNvbSwgTz1FeGFtcGxlIENBLCBDPUlUMRMwEQYDVQQKDApFeGFtcGxlIENBMQsw
272-
CQYDVQQGEwJJVDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMf3zvlY
273-
zX1DYgv9QjRusMQjSRNdZi72/ydnxO/cAQ1GsgLZ8ewqIL1CnXtIs6i2F8poUOec
274-
g957xk1db6sTqEWXRi5h9IfMUFcd5G7gIbJzjXCiLSVz6m9vZlvqR7BDka1VQhuH
275-
rW2xEIE6+F2lWxJ+crimea/c5VlMKBCh+gQldFq3lTu6smGUz8xl8rhleBPgTgZz
276-
TO4VuVO1dOb/S4lq9twfVYCTznF9vgaNaNh3la7yjzCf+zpSTGQD8TFO8ws1SZRq
277-
O0bkabW8/5XsnwFHLT2LMSPkWMgMD8r+7xef93bvbEy7SA4Hw1Iow2xIIcTDYQ7F
278-
77HQ3OjkogHmhrMCAwEAAaMxMC8wEgYDVR0TAQH/BAgwBgEB/wIBATAZBgNVHREE
279-
EjAQgg5jYS5leGFtcGxlLmNvbTANBgkqhkiG9w0BAQsFAAOCAQEApRUUxw5Dn0wd
280-
lFPApjn7n/SZyx5I1XnOHOIk8aWD0KFFa1zsnONlmRDgC8EQ5XKw3nMUwvnCQUR8
281-
6FmrqP5gINHdqfvWiitC0eQdDhMhIHvdfUMBicgZ0XDVjDZhD6W9A+IWwR3ySLCf
282-
lZHA5JwjYhpAjMYFXwSVZklOre34zJL6CRwgIUKjc9uyGPmlnVRFTUcUqLB9Uq/U
283-
dFc7XMPBAbMt1frOJRj6P1OFtubuC0INpEhzivg3+w8bXmpEN6e2hBvIjoNkgnWF
284-
O6HVbDnJXTA34/I4snisJfZQ+Z9gln921+2Q27sMvyS7aBqtocDuWB0w3XZ3aCYk
285-
DTEzMjUtQA==
286-
-----END CERTIFICATE-----
264+
ca.example.com: |
265+
-----BEGIN CERTIFICATE-----
266+
MIIDYzCCAkugAwIBAgIUHVMNJD9vqAA4mR+QAJyEQFW4kjQwDQYJKoZIhvcNAQEL
267+
BQAwUjEuMCwGA1UEAwwlQ049Y2EuZXhhbXBsZS5jb20sIE89RXhhbXBsZSBDQSwg
268+
Qz1JVDETMBEGA1UECgwKRXhhbXBsZSBDQTELMAkGA1UEBhMCSVQwHhcNMjUwNDAz
269+
MTU0NzU2WhcNMjYwNDA0MTU0NzU2WjBSMS4wLAYDVQQDDCVDTj1jYS5leGFtcGxl
270+
LmNvbSwgTz1FeGFtcGxlIENBLCBDPUlUMRMwEQYDVQQKDApFeGFtcGxlIENBMQsw
271+
CQYDVQQGEwJJVDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMf3zvlY
272+
zX1DYgv9QjRusMQjSRNdZi72/ydnxO/cAQ1GsgLZ8ewqIL1CnXtIs6i2F8poUOec
273+
g957xk1db6sTqEWXRi5h9IfMUFcd5G7gIbJzjXCiLSVz6m9vZlvqR7BDka1VQhuH
274+
rW2xEIE6+F2lWxJ+crimea/c5VlMKBCh+gQldFq3lTu6smGUz8xl8rhleBPgTgZz
275+
TO4VuVO1dOb/S4lq9twfVYCTznF9vgaNaNh3la7yjzCf+zpSTGQD8TFO8ws1SZRq
276+
O0bkabW8/5XsnwFHLT2LMSPkWMgMD8r+7xef93bvbEy7SA4Hw1Iow2xIIcTDYQ7F
277+
77HQ3OjkogHmhrMCAwEAAaMxMC8wEgYDVR0TAQH/BAgwBgEB/wIBATAZBgNVHREE
278+
EjAQgg5jYS5leGFtcGxlLmNvbTANBgkqhkiG9w0BAQsFAAOCAQEApRUUxw5Dn0wd
279+
lFPApjn7n/SZyx5I1XnOHOIk8aWD0KFFa1zsnONlmRDgC8EQ5XKw3nMUwvnCQUR8
280+
6FmrqP5gINHdqfvWiitC0eQdDhMhIHvdfUMBicgZ0XDVjDZhD6W9A+IWwR3ySLCf
281+
lZHA5JwjYhpAjMYFXwSVZklOre34zJL6CRwgIUKjc9uyGPmlnVRFTUcUqLB9Uq/U
282+
dFc7XMPBAbMt1frOJRj6P1OFtubuC0INpEhzivg3+w8bXmpEN6e2hBvIjoNkgnWF
283+
O6HVbDnJXTA34/I4snisJfZQ+Z9gln921+2Q27sMvyS7aBqtocDuWB0w3XZ3aCYk
284+
DTEzMjUtQA==
285+
-----END CERTIFICATE-----
287286
relying_party_certificate_chains_by_ca: # X.509 chains in PEM format. Please note: Leaf's certificate MUST be related to metadata_jwks[0]
288287
ca.example.com:
289288
- |

pyeudiw/openid4vp/presentation_submission/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(
2323
self,
2424
config: dict,
2525
trust_evaluator: CombinedTrustEvaluator,
26+
sig_alg_supported: list[str] = [],
2627
) -> None:
2728
"""
2829
Initialize the PresentationSubmissionHandler handler with the submission data.
@@ -64,7 +65,7 @@ def __init__(
6465
if not issubclass(cls, BaseVPParser):
6566
raise TypeError(f"Class '{class_name}' must inherit from BaseVPParser.")
6667

67-
self.handlers[format_name] = cls(trust_evaluator=self.trust_evaluator, **module_config)
68+
self.handlers[format_name] = cls(trust_evaluator=self.trust_evaluator, **module_config, sig_alg_supported=sig_alg_supported)
6869
except ModuleNotFoundError:
6970
raise ImportError(f"Module '{module_name}' not found for format '{format_conf['name']}'.")
7071
except AttributeError:

pyeudiw/satosa/default/openid4vp_backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def __init__(
116116
credential_presentation_handlers_configuration = self.config.get("credential_presentation_handlers", {})
117117
self.vp_token_parser = PresentationSubmissionHandler(
118118
credential_presentation_handlers_configuration,
119-
self.trust_evaluator
119+
self.trust_evaluator,
120+
self.config.get("jwt", {}).get("sig_alg_supported", [])
120121
)
121122

122123
def get_trust_backend_by_class_name(self, class_name: str) -> TrustHandlerInterface:

pyeudiw/tests/openid4vp/test_presentation_submission.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@
4545

4646
def test_handler_initialization():
4747

48-
ps = PresentationSubmissionHandler(trust_evaluator=trust_ev, config=mock_format_config)
48+
ps = PresentationSubmissionHandler(
49+
trust_evaluator=trust_ev,
50+
config=mock_format_config,
51+
sig_alg_supported=["ES256", "ES384", "ES512"]
52+
)
4953

5054
assert len(ps.handlers) == 3, "Not all handlers were created."
5155

@@ -54,7 +58,11 @@ def test_handler_initialization():
5458
assert isinstance(ps.handlers["fail_parser"], MockFailingParser), "Handler for 'fail_parser' format is incorrect."
5559

5660
def test_handler_correct_parsing():
57-
ps = PresentationSubmissionHandler(trust_evaluator=trust_ev, config=mock_format_config)
61+
ps = PresentationSubmissionHandler(
62+
trust_evaluator=trust_ev,
63+
config=mock_format_config,
64+
sig_alg_supported=["ES256", "ES384", "ES512"]
65+
)
5866

5967
parsed_tokens = ps.parse(valid_submission, ["vp_token_1", "vp_token_2"])
6068

@@ -63,7 +71,10 @@ def test_handler_correct_parsing():
6371
assert parsed_tokens[1] == {"parsed": "vp_token_2"}, "Token 2 was not parsed correctly."
6472

6573
def test_handler_missing_handler():
66-
ps = PresentationSubmissionHandler(trust_evaluator=trust_ev, config=mock_format_config)
74+
ps = PresentationSubmissionHandler(
75+
trust_evaluator=trust_ev,
76+
config=mock_format_config,
77+
sig_alg_supported=["ES256", "ES384", "ES512"])
6778

6879
invalid_submission = {
6980
"id": "submission_id",
@@ -81,7 +92,11 @@ def test_handler_missing_handler():
8192
assert str(e) == "Handler for format 'non_existent_format' not found.", "Incorrect exception message."
8293

8394
def test_handler_invalid_path():
84-
ps = PresentationSubmissionHandler(trust_evaluator=trust_ev, config=mock_format_config)
95+
ps = PresentationSubmissionHandler(
96+
trust_evaluator=trust_ev,
97+
config=mock_format_config,
98+
sig_alg_supported=["ES256", "ES384", "ES512"]
99+
)
85100

86101
invalid_submission = {
87102
"id": "submission_id",
@@ -99,7 +114,11 @@ def test_handler_invalid_path():
99114
assert str(e) == "Invalid path format: invalid_path", "Incorrect exception message."
100115

101116
def test_handler_mismatched_tokens():
102-
ps = PresentationSubmissionHandler(trust_evaluator=trust_ev, config=mock_format_config)
117+
ps = PresentationSubmissionHandler(
118+
trust_evaluator=trust_ev,
119+
config=mock_format_config,
120+
sig_alg_supported=["ES256", "ES384", "ES512"]
121+
)
103122

104123
invalid_submission = {
105124
"id": "submission_id",
@@ -116,7 +135,11 @@ def test_handler_mismatched_tokens():
116135
assert str(e) == "Number of VP tokens (1) does not match the number of descriptors (2).", "Incorrect exception message."
117136

118137
def test_handler_invalid_submission():
119-
ps = PresentationSubmissionHandler(trust_evaluator=trust_ev, config=mock_format_config)
138+
ps = PresentationSubmissionHandler(
139+
trust_evaluator=trust_ev,
140+
config=mock_format_config,
141+
sig_alg_supported=["ES256", "ES384", "ES512"]
142+
)
120143

121144
invalid_submission = {
122145
"fail": "submission"
@@ -130,7 +153,11 @@ def test_handler_invalid_submission():
130153
assert False, f"Incorrect exception type: {type(e)}"
131154

132155
def test_handler_parser_failure():
133-
ps = PresentationSubmissionHandler(trust_evaluator=trust_ev, config=mock_format_config)
156+
ps = PresentationSubmissionHandler(
157+
trust_evaluator=trust_ev,
158+
config=mock_format_config,
159+
sig_alg_supported=["ES256", "ES384", "ES512"]
160+
)
134161

135162
invalid_submission = {
136163
"id": "submission_id",

pyeudiw/tests/settings.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ def base64url_to_int(val):
154154
"A192GCM",
155155
"A256GCM",
156156
],
157+
"sig_alg_supported": [
158+
"RS256",
159+
"ES256",
160+
"ES384",
161+
"ES512",
162+
"EdDSA",
163+
],
157164
},
158165
"authorization": {
159166
"url_scheme": "haip", # haip://
@@ -406,16 +413,7 @@ def base64url_to_int(val):
406413
"module": "pyeudiw.openid4vp.vp_sd_jwt_vc",
407414
"class": "VpVcSdJwtParserVerifier",
408415
"format": "dc+sd-jwt",
409-
"config": {
410-
"sig_alg_supported": [
411-
"RS256",
412-
"RS384",
413-
"RS512",
414-
"ES256",
415-
"ES384",
416-
"ES512",
417-
]
418-
}
416+
"config": {}
419417
},
420418
{
421419
"module": "pyeudiw.openid4vp.vp_mdoc_cbor",

pyeudiw/tests/trust/mock_trust_handler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from pyeudiw.trust.handler.interface import TrustHandlerInterface
22
from pyeudiw.trust.model.trust_source import TrustSourceData
33
from pyeudiw.trust.model.trust_source import TrustEvaluationType
4-
from datetime import datetime
54
from pyeudiw.tools.utils import exp_from_now
65

76
mock_jwk = {
@@ -55,19 +54,20 @@ def extract_and_update_trust_materials(
5554
) -> TrustSourceData:
5655
trust_source = self.get_metadata(issuer, trust_source)
5756

57+
5858
if issuer == self.client_id:
5959
trust_param = TrustEvaluationType(
6060
attribute_name="trust_param_name",
6161
jwks=[mock_jwk, mock_jwk_private],
62-
expiration_date=datetime.fromtimestamp(exp_from_now(self.exp)),
62+
expiration_date=exp_from_now(self.exp),
6363
trust_param_name={'trust_param_key': 'trust_param_value'},
6464
trust_handler_name=str(self.__class__.__name__)
6565
)
6666
else:
6767
trust_param = TrustEvaluationType(
6868
attribute_name="trust_param_name",
6969
jwks=[mock_jwk, mock_jwk_private],
70-
expiration_date=datetime.fromtimestamp(exp_from_now(self.exp)),
70+
expiration_date=exp_from_now(self.exp),
7171
trust_param_name={"trust_param_key": "trust_param_value"},
7272
trust_handler_name=str(self.__class__.__name__)
7373
)
@@ -99,7 +99,7 @@ def extract_and_update_trust_materials(
9999
trust_param = TrustEvaluationType(
100100
attribute_name="trust_param_name",
101101
jwks=[mock_jwk],
102-
expiration_date=datetime.fromtimestamp(exp_from_now(self.exp)),
102+
expiration_date=exp_from_now(self.exp),
103103
trust_param_name={'updated_trust_param_key': 'updated_trust_param_value'},
104104
trust_handler_name=str(self.__class__.__name__)
105105
)

pyeudiw/tests/trust/test_dynamic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from uuid import uuid4
22

3+
import time
34
from pyeudiw.storage.db_engine import DBEngine
45
from pyeudiw.tests.settings import CONFIG
56
from pyeudiw.tests.trust import correct_config, not_conformant
@@ -131,6 +132,7 @@ def test_cache_first_strategy_expired():
131132
uuid_url = f"http://{uuid4()}.issuer.it"
132133

133134
assert trust_ev.get_jwt_header_trust_parameters(uuid_url) == {'trust_param_name': {'trust_param_key': 'trust_param_value'}}
135+
time.sleep(1)
134136
assert trust_ev.get_jwt_header_trust_parameters(uuid_url) == {'trust_param_name': {'updated_trust_param_key': 'updated_trust_param_value'}}
135137

136138
def test_cache_first_strategy_expired_revoked():

pyeudiw/trust/model/trust_source.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from dataclasses import dataclass
2-
from datetime import datetime
32
from typing import Optional
43

54
from cryptojwt.jwk.jwk import key_from_jwk_dict
65

76
from pyeudiw.jwk import JWK
7+
from pyeudiw.tools.utils import iat_now
88

99
@dataclass
1010
class TrustEvaluationType:
@@ -15,7 +15,7 @@ class TrustEvaluationType:
1515
def __init__(
1616
self,
1717
attribute_name: str,
18-
expiration_date: datetime,
18+
expiration_date: int,
1919
jwks: list[dict | JWK ] = [],
2020
trust_handler_name: str = "",
2121
**kwargs
@@ -25,8 +25,8 @@ def __init__(
2525
2626
:param attribute_name: The attribute name of the the field that holds the trust parameter data
2727
:type attribute_name: str
28-
:param expiration_date: The expiration date of the trust parameter data
29-
:type expiration_date: datetime
28+
:param expiration_date: The expiration date in unix timestamp of the trust parameter data
29+
:type expiration_date: int
3030
:param jwks: The jwks of the trust parameter data
3131
:type jwks: list[dict | JWK], optional
3232
:param trust_handler_name: The trust handler that handles the trust parameter data
@@ -69,7 +69,7 @@ def expired(self) -> bool:
6969
:returns: Whether the trust parameter data has expired
7070
:rtype: bool
7171
"""
72-
return datetime.now() > self.expiration_date
72+
return iat_now() > self.expiration_date
7373

7474
def get_jwks(self) -> list[dict]:
7575
return self.jwks

0 commit comments

Comments
 (0)