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

Commit 1665a04

Browse files
committed
Works with the new storage interface
1 parent 890a1ff commit 1665a04

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def run_tests(self):
6868
"Topic :: Software Development :: Libraries :: Python Modules"],
6969
install_requires=[
7070
"pyyaml>=5.1.0",
71-
'oidcmsg>=1.0.0',
71+
'oidcmsg>=1.1.0',
7272
],
7373
tests_require=[
7474
"responses",

src/oidcservice/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
__author__ = 'Roland Hedberg'
12-
__version__ = '1.0.0'
12+
__version__ = '1.1.0'
1313

1414

1515
OIDCONF_PATTERN = "{}/.well-known/openid-configuration"

src/oidcservice/state_interface.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ def delete(self, key):
5353
except KeyError:
5454
pass
5555

56+
def __setitem__(self, key, value):
57+
"""Assign a value to a key."""
58+
self._db[key] = value
59+
60+
def __getitem__(self, key):
61+
"""Return the value bound to a key."""
62+
try:
63+
return self._db[key]
64+
except KeyError:
65+
return None
66+
67+
def __delitem__(self, key):
68+
"""Delete a key and its value."""
69+
try:
70+
del self._db[key]
71+
except KeyError:
72+
pass
73+
5674

5775
class StateInterface:
5876
"""A more powerful interface to a state DB."""
@@ -92,7 +110,7 @@ def store_item(self, item, item_type, key):
92110
except AttributeError:
93111
_state[item_type] = item
94112

95-
self.state_db.set(key, _state.to_json())
113+
self.state_db[key] = _state.to_json()
96114

97115
def get_iss(self, key):
98116
"""
@@ -216,7 +234,7 @@ def store_x2state(self, value, state, xtyp):
216234
:param state: The state value
217235
:param xtyp: The type of value x is (e.g. nonce, ...)
218236
"""
219-
self.state_db.set(KEY_PATTERN[xtyp].format(value), state)
237+
self.state_db[KEY_PATTERN[xtyp].format(value)] = state
220238
try:
221239
_val = self.state_db.get("ref{}ref".format(state))
222240
except KeyError:
@@ -227,7 +245,7 @@ def store_x2state(self, value, state, xtyp):
227245
else:
228246
refs = json.loads(_val)
229247
refs[xtyp] = value
230-
self.state_db.set("ref{}ref".format(state), json.dumps(refs))
248+
self.state_db["ref{}ref".format(state)] = json.dumps(refs)
231249

232250
def get_state_by_x(self, value, xtyp):
233251
"""
@@ -346,7 +364,7 @@ def create_state(self, iss, key=''):
346364
'Invalid format. Leading and trailing "__" not allowed')
347365

348366
_state = State(iss=iss)
349-
self.state_db.set(key, _state.to_json())
367+
self.state_db[key] = _state.to_json()
350368
return key
351369

352370
def remove_state(self, state):

tests/test_09_client_auth.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def test_construct(self, services):
196196

197197
def test_construct_with_state(self, services):
198198
_srv = services['authorization']
199-
_srv.state_db.set('FFFFF', State(iss='Issuer').to_json())
199+
_srv.state_db['FFFFF'] = State(iss='Issuer').to_json()
200200

201201
resp = AuthorizationResponse(code="code", state="FFFFF")
202202
_srv.store_item(resp, 'auth_response', 'FFFFF')
@@ -215,8 +215,7 @@ def test_construct_with_state(self, services):
215215

216216
def test_construct_with_request(self, services):
217217
authz_service = services['authorization']
218-
authz_service.service_context.state_db.set('EEEE', State(
219-
iss='Issuer').to_json())
218+
authz_service.service_context.state_db['EEEE'] = State(iss='Issuer').to_json()
220219
resp1 = AuthorizationResponse(code="auth_grant", state="EEEE")
221220
response = authz_service.parse_response(resp1.to_urlencoded(),
222221
"urlencoded")

tests/test_14_pkce.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def create_client(self):
7575
def test_add_code_challenge_default_values(self):
7676
auth_serv = self.service["authorization"]
7777
_state = State(iss='Issuer')
78-
auth_serv.service_context.state_db.set('state', _state.to_json())
78+
auth_serv.service_context.state_db['state'] = _state.to_json()
7979
request_args, _ = add_code_challenge({'state': 'state'}, auth_serv)
8080

8181
# default values are length:64 method:S256
@@ -89,7 +89,7 @@ def test_add_code_challenge_default_values(self):
8989
def test_authorization_and_pkce(self):
9090
auth_serv = self.service["authorization"]
9191
_state = State(iss='Issuer')
92-
auth_serv.service_context.state_db.set('state', _state.to_json())
92+
auth_serv.service_context.state_db['state'] = _state.to_json()
9393

9494
request = auth_serv.construct_request({"state": 'state', "response_type": "code"})
9595
assert set(request.keys()) == {'client_id', 'code_challenge',

tests/test_30_persistence.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,8 @@ def build_service_context() -> object:
127127
"jwks_uri": "{}/static/jwks.json".format(RP_BASEURL),
128128
'jwks': RP_JWKS,
129129
'db_conf': {
130-
'abstract_storage_cls':
131-
'oidcmsg.storage.extension.LabeledAbstractStorage',
132130
'keyjar': {
133-
'handler': 'oidcmsg.storage.abfile.AbstractFileSystem',
131+
'handler': 'oidcmsg.storage.abfile.LabeledAbstractFileSystem',
134132
'fdir': 'db/{issuer}/keyjar',
135133
'key_conv': 'oidcmsg.storage.converter.QPKey',
136134
'value_conv': 'cryptojwt.serialize.item.KeyIssuer',

0 commit comments

Comments
 (0)