Skip to content

Commit 399184d

Browse files
committed
account for mismatched uid due to test server process
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
1 parent 5c9797c commit 399184d

1 file changed

Lines changed: 23 additions & 30 deletions

File tree

tests/e2e/test_provider_ldap.py

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,28 @@
1919
from tests.live import ChannelsE2ETestCase
2020

2121

22+
def clean_response(response):
23+
# Remove raw_attributes to make checking easier
24+
for obj in response:
25+
del obj["raw_attributes"]
26+
del obj["raw_dn"]
27+
obj["attributes"] = dict(obj["attributes"])
28+
obj["attributes"].pop("uid", None)
29+
return response
30+
31+
2232
class TestProviderLDAP(ChannelsE2ETestCase):
2333
"""LDAP and Outpost e2e tests"""
2434

35+
def assert_list_dict_equal(self, expected: list[dict], actual: list[dict], match_key="dn"):
36+
"""Assert a list of dictionaries is identical, ignoring the ordering of items"""
37+
self.assertEqual(len(expected), len(actual))
38+
for res_item in actual:
39+
all_matching = [x for x in expected if x[match_key] == res_item[match_key]]
40+
self.assertEqual(len(all_matching), 1)
41+
matching = all_matching[0]
42+
self.assertDictEqual(res_item, matching)
43+
2544
def start_ldap(self, outpost: Outpost):
2645
"""Start ldap container based on outpost created"""
2746
self.run_container(
@@ -211,20 +230,14 @@ def test_ldap_bind_search(self):
211230
search_scope=SUBTREE,
212231
attributes=[ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES],
213232
)
214-
response: list = _connection.response
215-
# Remove raw_attributes to make checking easier
216-
for obj in response:
217-
del obj["raw_attributes"]
218-
del obj["raw_dn"]
219-
obj["attributes"] = dict(obj["attributes"])
233+
response = clean_response(_connection.response)
220234
o_user = outpost.user
221235
expected = [
222236
{
223237
"dn": f"cn={o_user.username},ou=users,dc=ldap,dc=goauthentik,dc=io",
224238
"attributes": {
225239
"cn": o_user.username,
226240
"sAMAccountName": o_user.username,
227-
"uid": o_user.uid,
228241
"name": o_user.name,
229242
"displayName": o_user.name,
230243
"sn": o_user.name,
@@ -255,7 +268,6 @@ def test_ldap_bind_search(self):
255268
"attributes": {
256269
"cn": embedded_account.username,
257270
"sAMAccountName": embedded_account.username,
258-
"uid": embedded_account.uid,
259271
"name": embedded_account.name,
260272
"displayName": embedded_account.name,
261273
"sn": embedded_account.name,
@@ -286,7 +298,6 @@ def test_ldap_bind_search(self):
286298
"attributes": {
287299
"cn": self.user.username,
288300
"sAMAccountName": self.user.username,
289-
"uid": self.user.uid,
290301
"name": self.user.name,
291302
"displayName": self.user.name,
292303
"sn": self.user.name,
@@ -355,19 +366,13 @@ def test_ldap_bind_search_no_perms(self):
355366
search_scope=SUBTREE,
356367
attributes=[ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES],
357368
)
358-
response: list = _connection.response
359-
# Remove raw_attributes to make checking easier
360-
for obj in response:
361-
del obj["raw_attributes"]
362-
del obj["raw_dn"]
363-
obj["attributes"] = dict(obj["attributes"])
369+
response = clean_response(_connection.response)
364370
expected = [
365371
{
366372
"dn": f"cn={user.username},ou=users,dc=ldap,dc=goauthentik,dc=io",
367373
"attributes": {
368374
"cn": user.username,
369375
"sAMAccountName": user.username,
370-
"uid": user.uid,
371376
"name": user.name,
372377
"displayName": user.name,
373378
"sn": user.name,
@@ -399,15 +404,6 @@ def test_ldap_bind_search_no_perms(self):
399404
]
400405
self.assert_list_dict_equal(expected, response)
401406

402-
def assert_list_dict_equal(self, expected: list[dict], actual: list[dict], match_key="dn"):
403-
"""Assert a list of dictionaries is identical, ignoring the ordering of items"""
404-
self.assertEqual(len(expected), len(actual))
405-
for res_item in actual:
406-
all_matching = [x for x in expected if x[match_key] == res_item[match_key]]
407-
self.assertEqual(len(all_matching), 1)
408-
matching = all_matching[0]
409-
self.assertDictEqual(res_item, matching)
410-
411407
@retry()
412408
@apply_blueprint(
413409
"default/flow-default-authentication-flow.yaml",
@@ -471,11 +467,8 @@ def test_ldap_search_attrs_filter(self):
471467
search_scope=SUBTREE,
472468
attributes=["cn"],
473469
)
474-
response: list = _connection.response
475-
# Remove raw_attributes to make checking easier
476-
for obj in response:
477-
del obj["raw_attributes"]
478-
del obj["raw_dn"]
470+
response = clean_response(_connection.response)
471+
479472
o_user = outpost.user
480473
self.assert_list_dict_equal(
481474
[

0 commit comments

Comments
 (0)