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

Commit 630258b

Browse files
authored
Merge pull request #120 from IdentityPython/ui_excp
Missing userinfo in Configuration now raises an exception
2 parents 6e0b9bf + d0eb303 commit 630258b

8 files changed

Lines changed: 54 additions & 3 deletions

src/oidcop/session/claims.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from oidcmsg.oidc import OpenIDSchema
66

77
from oidcop.exception import ServiceError
8+
from oidcop.exception import ImproperlyConfigured
89
from oidcop.scopes import convert_scopes2claims
910

1011
logger = logging.getLogger(__name__)
@@ -127,9 +128,14 @@ def get_user_claims(self, user_id: str, claims_restriction: dict) -> dict:
127128
:param claims_restriction: Specifies the upper limit of which claims can be returned
128129
:return:
129130
"""
131+
meth = self.server_get("endpoint_context").userinfo
132+
if not meth:
133+
raise ImproperlyConfigured(
134+
"userinfo MUST be defined in the configuration"
135+
)
130136
if claims_restriction:
131137
# Get all possible claims
132-
user_info = self.server_get("endpoint_context").userinfo(user_id, client_id=None)
138+
user_info = meth(user_id, client_id=None)
133139
# Filter out the claims that can be returned
134140
return {
135141
k: user_info.get(k)

tests/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
3+
BASEDIR = os.path.abspath(os.path.dirname(__file__))
4+
5+
6+
def full_path(local_file):
7+
return os.path.join(BASEDIR, local_file)

tests/test_01_grant.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from cryptojwt.key_jar import build_keyjar
33
from oidcmsg.oidc import AuthorizationRequest
44

5+
from . import full_path
56
from oidcop.authn_event import create_authn_event
67
from oidcop.server import Server
78
from oidcop.session.grant import TOKEN_MAP
@@ -20,6 +21,7 @@
2021

2122
KEYJAR = build_keyjar(KEYDEFS)
2223

24+
2325
conf = {
2426
"issuer": "https://example.com/",
2527
"template_dir": "template",
@@ -40,6 +42,10 @@
4042
}
4143
},
4244
"claims_interface": {"class": "oidcop.session.claims.ClaimsInterface", "kwargs": {}},
45+
"userinfo": {
46+
"class": "oidcop.user_info.UserInfo",
47+
"kwargs": {"db_file": full_path("users.json")},
48+
},
4349
}
4450

4551
USER_ID = "diana"

tests/test_06_session_manager.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from oidcmsg.time_util import time_sans_frac
33
import pytest
44

5+
from . import full_path
56
from oidcop.authn_event import AuthnEvent
67
from oidcop.authn_event import create_authn_event
78
from oidcop.authz import AuthzHandling
@@ -74,6 +75,10 @@ def create_session_manager(self):
7475
},
7576
"template_dir": "template",
7677
"claims_interface": {"class": "oidcop.session.claims.ClaimsInterface", "kwargs": {}},
78+
"userinfo": {
79+
"class": "oidcop.user_info.UserInfo",
80+
"kwargs": {"db_file": full_path("users.json")},
81+
},
7782
}
7883
server = Server(conf)
7984
self.server = server

tests/test_08_session_life.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from oidcmsg.oidc import RefreshAccessTokenRequest
99
from oidcmsg.time_util import time_sans_frac
1010

11+
from . import full_path
1112
from oidcop import user_info
1213
from oidcop.authn_event import create_authn_event
1314
from oidcop.client_authn import verify_client
@@ -50,6 +51,10 @@ def setup_token_handler(self):
5051
"token_endpoint": {"path": "{}/token", "class": Token, "kwargs": {}},
5152
},
5253
"template_dir": "template",
54+
"userinfo": {
55+
"class": "oidcop.user_info.UserInfo",
56+
"kwargs": {"db_file": full_path("users.json")},
57+
},
5358
}
5459
server = Server(OPConfiguration(conf=conf, base_path=BASEDIR), cwd=BASEDIR)
5560

tests/test_26_oidc_userinfo_endpoint.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from oidcop.authn_event import create_authn_event
1212
from oidcop.configure import OPConfiguration
1313
from oidcop.cookie_handler import CookieHandler
14+
from oidcop.exception import ImproperlyConfigured
1415
from oidcop.oidc import userinfo
1516
from oidcop.oidc.authorization import Authorization
1617
from oidcop.oidc.provider_config import ProviderConfiguration
@@ -439,3 +440,14 @@ def test_userinfo_claims_acr_none(self):
439440
res = self.endpoint.do_response(request=_req, **args)
440441
_response = json.loads(res["response"])
441442
assert _response["acr"] == _acr
443+
444+
def test_process_request_absent_userinfo_conf(self):
445+
# consider to have a configuration without userinfo defined in
446+
ec = self.endpoint.server_get('endpoint_context')
447+
ec.userinfo = None
448+
449+
session_id = self._create_session(AUTH_REQ)
450+
grant = self.session_manager[session_id]
451+
452+
with pytest.raises(ImproperlyConfigured):
453+
code = self._mint_code(grant, session_id)

tests/test_33_oauth2_pkce.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import secrets
55
import string
66

7+
from . import full_path
78
from oidcop.configure import ASConfiguration
89
import pytest
910
import yaml
@@ -161,6 +162,10 @@ def conf():
161162
},
162163
},
163164
},
165+
"userinfo": {
166+
"class": "oidcop.user_info.UserInfo",
167+
"kwargs": {"db_file": full_path("users.json")},
168+
},
164169
}
165170

166171

tests/test_34_oidc_sso.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import os
44

5+
from . import full_path
56
from oidcop.configure import OPConfiguration
67
import pytest
78
import yaml
@@ -89,11 +90,11 @@ def full_path(local_file):
8990
client_1:
9091
client_secret: hemligtkodord,
9192
client_id: client_1,
92-
"redirect_uris":
93+
"redirect_uris":
9394
- ['https://example.com/cb', '']
9495
"client_salt": "salted"
9596
'token_endpoint_auth_method': 'client_secret_post'
96-
'response_types':
97+
'response_types':
9798
- 'code'
9899
- 'token'
99100
- 'code id_token'
@@ -158,6 +159,10 @@ def create_endpoint_context(self):
158159
},
159160
},
160161
"template_dir": "template",
162+
"userinfo": {
163+
"class": "oidcop.user_info.UserInfo",
164+
"kwargs": {"db_file": full_path("users.json")},
165+
},
161166
}
162167
server = Server(OPConfiguration(conf=conf, base_path=BASEDIR), cwd=BASEDIR)
163168

0 commit comments

Comments
 (0)