Skip to content

Commit d0f5552

Browse files
committed
Always use hash_id to hash the user_id
Plus some minor formatting changes Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 57d783d commit d0f5552

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/satosa/base.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,14 @@ def _auth_req_finish(self, context, internal_request):
132132

133133
def _auth_resp_finish(self, context, internal_response):
134134
# re-hash user id since e.g. account linking micro service might have changed it
135-
user_id = UserIdHasher.hash_id(self.config["USER_ID_HASH_SALT"],
136-
internal_response.user_id,
137-
internal_response.requester,
138-
context.state)
135+
user_id = UserIdHasher.hash_id(
136+
self.config["USER_ID_HASH_SALT"],
137+
internal_response.user_id,
138+
internal_response.requester,
139+
context.state)
139140
internal_response.user_id = user_id
140-
internal_response.user_id_hash_type = UserIdHasher.hash_type(context.state)
141+
internal_response.user_id_hash_type = UserIdHasher.hash_type(
142+
context.state)
141143
user_id_to_attr = self.config["INTERNAL_ATTRIBUTES"].get("user_id_to_attr", None)
142144
if user_id_to_attr:
143145
internal_response.attributes[user_id_to_attr] = [internal_response.user_id]
@@ -148,8 +150,10 @@ def _auth_resp_finish(self, context, internal_response):
148150
for attribute in hash_attributes:
149151
# hash all attribute values individually
150152
if attribute in internal_attributes:
151-
hashed_values = [UserIdHasher.hash_data(self.config["USER_ID_HASH_SALT"], v)
152-
for v in internal_attributes[attribute]]
153+
hashed_values = [
154+
UserIdHasher.hash_data(self.config["USER_ID_HASH_SALT"], v)
155+
for v in internal_attributes[attribute]
156+
]
153157
internal_attributes[attribute] = hashed_values
154158

155159
# remove all session state
@@ -188,10 +192,14 @@ def _auth_resp_callback_func(self, context, internal_response):
188192
# not be configured to construct one from asserted attributes.
189193
# So only hash the user_id if it is not None.
190194
if internal_response.user_id:
191-
user_id = UserIdHasher.hash_data(
195+
user_id = UserIdHasher.hash_id(
192196
self.config["USER_ID_HASH_SALT"],
193-
internal_response.user_id)
197+
internal_response.user_id,
198+
internal_response.requester,
199+
context.state)
194200
internal_response.user_id = user_id
201+
internal_response.user_id_hash_type = UserIdHasher.hash_type(
202+
context.state)
195203

196204
if self.response_micro_services:
197205
return self.response_micro_services[0].process(

tests/satosa/test_base.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,17 @@ def test_auth_resp_callback_func_user_id_from_attrs_is_used_to_override_user_id(
5050

5151
base._auth_resp_callback_func(context, internal_resp)
5252

53-
expected_user_id = UserIdHasher.hash_data(satosa_config["USER_ID_HASH_SALT"], "[email protected]")
54-
expected_user_id = UserIdHasher.hash_id(satosa_config["USER_ID_HASH_SALT"],
55-
expected_user_id,
56-
internal_resp.requester,
57-
context.state)
53+
expected_user_id = "[email protected]"
54+
expected_user_id = UserIdHasher.hash_id(
55+
satosa_config["USER_ID_HASH_SALT"],
56+
expected_user_id,
57+
internal_resp.requester,
58+
context.state)
59+
expected_user_id = UserIdHasher.hash_id(
60+
satosa_config["USER_ID_HASH_SALT"],
61+
expected_user_id,
62+
internal_resp.requester,
63+
context.state)
5864
assert internal_resp.user_id == expected_user_id
5965

6066
def test_auth_req_callback_stores_state_for_consent(self, context, satosa_config):

0 commit comments

Comments
 (0)