Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 49e9483

Browse files
committed
Fixed test
1 parent 754171d commit 49e9483

File tree

2 files changed

+93
-3
lines changed

2 files changed

+93
-3
lines changed

Diff for: src/oidcrp/oauth2/add_on/dpop.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,6 @@ def add_support(services, signing_algorithms: Optional[list] = None):
161161
_service.construct_extra_headers.append(dpop_header)
162162

163163
# The same for userinfo requests
164-
_service = services["userinfo"]
165-
_service.construct_extra_headers.append(dpop_header)
164+
_userinfo_service = services.get("userinfo")
165+
if _userinfo_service:
166+
_userinfo_service.construct_extra_headers.append(dpop_header)

Diff for: tests/test_40_dpop.py

+90-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
key_defs=KEYSPEC, issuer_id='client_id')
2020

2121

22-
class TestDPoP:
22+
class TestDPoPWithoutUserinfo:
2323
@pytest.fixture(autouse=True)
2424
def create_client(self):
2525
config = {
@@ -67,3 +67,92 @@ def test_add_header(self):
6767
assert _header["alg"] == "ES256"
6868
assert _header["jwk"]["kty"] == "EC"
6969
assert _header["jwk"]["crv"] == "P-256"
70+
71+
72+
class TestDPoPWithUserinfo:
73+
@pytest.fixture(autouse=True)
74+
def create_client(self):
75+
config = {
76+
'client_id': 'client_id',
77+
'client_secret': 'a longesh password',
78+
'redirect_uris': ['https://example.com/cli/authz_cb'],
79+
'behaviour': {'response_types': ['code']},
80+
'add_ons': {
81+
"dpop": {
82+
"function": "oidcrp.oauth2.add_on.dpop.add_support",
83+
"kwargs": {
84+
"signing_algorithms": ["ES256", "ES512"]
85+
}
86+
}
87+
}
88+
}
89+
90+
services = {
91+
"discovery": {
92+
'class': 'oidcrp.oauth2.provider_info_discovery.ProviderInfoDiscovery'
93+
},
94+
'authorization': {
95+
'class': 'oidcrp.oauth2.authorization.Authorization'
96+
},
97+
'access_token': {
98+
'class': 'oidcrp.oauth2.access_token.AccessToken'
99+
},
100+
'refresh_access_token': {
101+
'class': 'oidcrp.oauth2.refresh_access_token.RefreshAccessToken'
102+
},
103+
'userinfo': {
104+
'class': 'oidcrp.oidc.userinfo.UserInfo'
105+
}
106+
}
107+
self.client = Client(keyjar=CLI_KEY, config=config, services=services)
108+
109+
self.client.client_get("service_context").provider_info = {
110+
"authorization_endpoint": "https://example.com/auth",
111+
"token_endpoint": "https://example.com/token",
112+
"dpop_signing_alg_values_supported": ["RS256", "ES256"],
113+
"userinfo_endpoint": "https://example.com/user",
114+
}
115+
116+
def test_add_header_token(self):
117+
token_serv = self.client.client_get("service", "accesstoken")
118+
req_args = {
119+
"grant_type": "authorization_code",
120+
"code": "SplxlOBeZQQYbYS6WxSbIA",
121+
"redirect_uri": "https://client/example.com/cb"
122+
}
123+
headers = token_serv.get_headers(request=req_args, http_method="POST")
124+
assert headers
125+
assert "dpop" in headers
126+
127+
# Now for the content of the DPoP proof
128+
_jws = factory(headers["dpop"])
129+
_payload = _jws.jwt.payload()
130+
assert _payload["htu"] == "https://example.com/token"
131+
assert _payload["htm"] == "POST"
132+
_header = _jws.jwt.headers
133+
assert "jwk" in _header
134+
assert _header["typ"] == "dpop+jwt"
135+
assert _header["alg"] == "ES256"
136+
assert _header["jwk"]["kty"] == "EC"
137+
assert _header["jwk"]["crv"] == "P-256"
138+
139+
def test_add_header_userinfo(self):
140+
userinfo_serv = self.client.client_get("service", "userinfo")
141+
req_args = {}
142+
access_token = 'access.token.sign'
143+
headers = userinfo_serv.get_headers(request=req_args, http_method="GET",
144+
access_token=access_token)
145+
assert headers
146+
assert "dpop" in headers
147+
148+
# Now for the content of the DPoP proof
149+
_jws = factory(headers["dpop"])
150+
_payload = _jws.jwt.payload()
151+
assert _payload["htu"] == "https://example.com/user"
152+
assert _payload["htm"] == "GET"
153+
_header = _jws.jwt.headers
154+
assert "jwk" in _header
155+
assert _header["typ"] == "dpop+jwt"
156+
assert _header["alg"] == "ES256"
157+
assert _header["jwk"]["kty"] == "EC"
158+
assert _header["jwk"]["crv"] == "P-256"

0 commit comments

Comments
 (0)