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

Commit 2939a63

Browse files
authored
Merge pull request #17 from peppelinux/master
nightly contributions
2 parents f1a8d73 + 7dbfb8b commit 2939a63

8 files changed

Lines changed: 60 additions & 29 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ __pycache__/
55
*.py[cod]
66
*$py.class
77

8+
private/
9+
810
# C extensions
911
*.so
1012

.travis.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
dist: buster
2+
sudo: false
3+
4+
language: python
5+
python:
6+
- 3.6
7+
- 3.7
8+
- pypy3
9+
10+
addons:
11+
apt:
12+
packages:
13+
-
14+
15+
install:
16+
- pip install pytest
17+
- pip install codecov
18+
19+
script:
20+
- codecov --version
21+
22+
after_success:
23+
- codecov

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# oidcendpoint
22
Implementation of OIDC OP endpoints.
3+
4+
## Run tests
5+
````
6+
pip install -r requirements-dev.txt
7+
pytest -x --pdb tests/
8+
````

requirements-dev.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pytest
2+
pytest-localserver
3+
requests_mock

src/oidcendpoint/endpoint_context.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ def __init__(
101101
self.keyjar = keyjar or KeyJar()
102102
self.cwd = cwd
103103

104-
# client database
105-
self.cdb = client_db or {}
106-
107104
try:
108105
self.seed = bytes(conf["seed"], "utf-8")
109106
except KeyError:
@@ -129,6 +126,9 @@ def __init__(
129126
# arguments for endpoints add-ons
130127
self.args = {}
131128

129+
# client database
130+
self.cdb = client_db or {}
131+
132132
# session db
133133
self._sub_func = {}
134134
self.do_sub_func()
@@ -217,22 +217,19 @@ def __init__(
217217
self.registration_access_token = {}
218218

219219
def set_session_db(self, conf, sso_db=None):
220-
# this populate self.sdb
221220
sso_db = sso_db if sso_db else SSODb()
222221
self.do_session_db(conf, sso_db)
223-
# this append useinfo db to the session db
222+
# append useinfo db to the session db
224223
self.do_userinfo()
225224
logger.debug('Session DB: {}'.format(self.sdb.__dict__))
226225

227226
def do_add_on(self):
228-
_conf = self.conf.get("add_on")
229-
if 'add_on' in self.conf:
227+
if self.conf.get("add_on"):
230228
for spec in self.conf["add_on"].values():
231229
if isinstance(spec["function"], str):
232230
_func = importer(spec["function"])
233231
else:
234232
_func = spec["function"]
235-
236233
_func(self.endpoint, **spec["kwargs"])
237234

238235
def do_login_hint2acrs(self):
@@ -256,7 +253,9 @@ def do_userinfo(self):
256253
if self.sdb:
257254
self.userinfo = init_user_info(_conf, self.cwd)
258255
self.sdb.userinfo = self.userinfo
259-
256+
else:
257+
logger.warning(('Cannot init_user_info if any '
258+
'session_db was provided.'))
260259

261260
def do_id_token(self):
262261
_conf = self.conf.get("id_token")

src/oidcendpoint/id_token.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,8 @@ def make(self, req, sess_info, authn_req=None, user_claims=False, **kwargs):
249249
_client_id = req["client_id"]
250250

251251
_cinfo = _context.cdb[_client_id]
252-
try:
253-
default_idtoken_claims = self.kwargs["default_claims"]
254-
except KeyError:
255-
default_idtoken_claims = None
256252

253+
default_idtoken_claims = self.kwargs.get("default_claims", None)
257254
lifetime = self.kwargs.get("lifetime")
258255

259256
userinfo = userinfo_in_id_token_claims(

tests/test_24_authorization_endpoint.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -806,13 +806,10 @@ def test_post_logout_uri(self):
806806

807807

808808
def test_inputs():
809-
elems = inputs({"foo": "bar", "home": "stead"})
810-
print(elems)
811-
assert (
812-
elems
813-
== """<input type="hidden" name="foo" value="bar"/>
814-
<input type="hidden" name="home" value="stead"/>"""
815-
)
809+
elems = inputs(dict(foo = "bar", home = "stead"))
810+
test_elems = ('<input type="hidden" name="foo" value="bar"/>',
811+
'<input type="hidden" name="home" value="stead"/>')
812+
assert (test_elems[0] in elems and test_elems[1] in elems)
816813

817814

818815
def test_acr_claims():
@@ -827,4 +824,6 @@ def test_acr_claims():
827824
def test_join_query():
828825
redirect_uris = [("https://rp.example.com/cb", {"foo": ["bar"], "state": ["low"]})]
829826
uri = join_query(*redirect_uris[0])
830-
assert uri == "https://rp.example.com/cb?foo=bar&state=low"
827+
test_uri = ("https://rp.example.com/cb?", "foo=bar", "state=low")
828+
for i in test_uri:
829+
assert i in uri

tests/test_30_end_session.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,11 @@ def test_front_channel_logout_session_required(self):
418418
_cdb["frontchannel_logout_session_required"] = True
419419
_cdb["client_id"] = "client_1"
420420
res = do_front_channel_logout_iframe(_cdb, ISS, "_sid_")
421-
assert (
422-
res
423-
== '<iframe src="https://example.com/fc_logout?iss=https%3A%2F%2Fexample.com%2F&sid=_sid_">'
424-
)
421+
test_res = ('<iframe src="https://example.com/fc_logout?',
422+
'iss=https%3A%2F%2Fexample.com%2F',
423+
'sid=_sid_')
424+
for i in test_res:
425+
assert (i in res)
425426

426427
def test_front_channel_logout_with_query(self):
427428
self._code_auth("1234567")
@@ -431,10 +432,11 @@ def test_front_channel_logout_with_query(self):
431432
_cdb["frontchannel_logout_session_required"] = True
432433
_cdb["client_id"] = "client_1"
433434
res = do_front_channel_logout_iframe(_cdb, ISS, "_sid_")
434-
assert (
435-
res
436-
== '<iframe src="https://example.com/fc_logout?entity_id=foo&iss=https%3A%2F%2Fexample.com%2F&sid=_sid_">'
437-
)
435+
test_res = ('<iframe', 'src="https://example.com/fc_logout?',
436+
'entity_id=foo',
437+
'iss=https%3A%2F%2Fexample.com%2F','sid=_sid_')
438+
for i in test_res:
439+
assert (i in res)
438440

439441
def test_logout_from_client_bc(self):
440442
self._code_auth("1234567")

0 commit comments

Comments
 (0)