tests/e2e: improve assertCountEqual diff (#6261)
* tests/e2e: improve assertCountEqual diff Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
parent
27879d9d95
commit
db4f61549d
|
@ -226,103 +226,110 @@ class TestProviderLDAP(SeleniumTestCase):
|
||||||
search_scope=SUBTREE,
|
search_scope=SUBTREE,
|
||||||
attributes=[ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES],
|
attributes=[ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES],
|
||||||
)
|
)
|
||||||
response: dict = _connection.response
|
response: list = _connection.response
|
||||||
# Remove raw_attributes to make checking easier
|
# Remove raw_attributes to make checking easier
|
||||||
for obj in response:
|
for obj in response:
|
||||||
del obj["raw_attributes"]
|
del obj["raw_attributes"]
|
||||||
del obj["raw_dn"]
|
del obj["raw_dn"]
|
||||||
o_user = outpost.user
|
o_user = outpost.user
|
||||||
self.assertCountEqual(
|
expected = [
|
||||||
response,
|
{
|
||||||
[
|
"dn": f"cn={o_user.username},ou=users,dc=ldap,dc=goauthentik,dc=io",
|
||||||
{
|
"attributes": {
|
||||||
"dn": f"cn={o_user.username},ou=users,dc=ldap,dc=goauthentik,dc=io",
|
"cn": o_user.username,
|
||||||
"attributes": {
|
"sAMAccountName": o_user.username,
|
||||||
"cn": o_user.username,
|
"uid": o_user.uid,
|
||||||
"sAMAccountName": o_user.username,
|
"name": o_user.name,
|
||||||
"uid": o_user.uid,
|
"displayName": o_user.name,
|
||||||
"name": o_user.name,
|
"sn": o_user.name,
|
||||||
"displayName": o_user.name,
|
"mail": "",
|
||||||
"sn": o_user.name,
|
"objectClass": [
|
||||||
"mail": "",
|
"user",
|
||||||
"objectClass": [
|
"organizationalPerson",
|
||||||
"user",
|
"inetOrgPerson",
|
||||||
"organizationalPerson",
|
"goauthentik.io/ldap/user",
|
||||||
"inetOrgPerson",
|
"posixAccount",
|
||||||
"goauthentik.io/ldap/user",
|
],
|
||||||
"posixAccount",
|
"uidNumber": 2000 + o_user.pk,
|
||||||
],
|
"gidNumber": 2000 + o_user.pk,
|
||||||
"uidNumber": 2000 + o_user.pk,
|
"memberOf": [],
|
||||||
"gidNumber": 2000 + o_user.pk,
|
"homeDirectory": f"/home/{o_user.username}",
|
||||||
"memberOf": [],
|
"ak-active": True,
|
||||||
"homeDirectory": f"/home/{o_user.username}",
|
"ak-superuser": False,
|
||||||
"ak-active": True,
|
"goauthentikio-user-override-ips": True,
|
||||||
"ak-superuser": False,
|
"goauthentikio-user-service-account": True,
|
||||||
"goauthentikio-user-override-ips": True,
|
|
||||||
"goauthentikio-user-service-account": True,
|
|
||||||
},
|
|
||||||
"type": "searchResEntry",
|
|
||||||
},
|
},
|
||||||
{
|
"type": "searchResEntry",
|
||||||
"dn": f"cn={embedded_account.username},ou=users,dc=ldap,dc=goauthentik,dc=io",
|
},
|
||||||
"attributes": {
|
{
|
||||||
"cn": embedded_account.username,
|
"dn": f"cn={embedded_account.username},ou=users,dc=ldap,dc=goauthentik,dc=io",
|
||||||
"sAMAccountName": embedded_account.username,
|
"attributes": {
|
||||||
"uid": embedded_account.uid,
|
"cn": embedded_account.username,
|
||||||
"name": embedded_account.name,
|
"sAMAccountName": embedded_account.username,
|
||||||
"displayName": embedded_account.name,
|
"uid": embedded_account.uid,
|
||||||
"sn": embedded_account.name,
|
"name": embedded_account.name,
|
||||||
"mail": "",
|
"displayName": embedded_account.name,
|
||||||
"objectClass": [
|
"sn": embedded_account.name,
|
||||||
"user",
|
"mail": "",
|
||||||
"organizationalPerson",
|
"objectClass": [
|
||||||
"inetOrgPerson",
|
"user",
|
||||||
"goauthentik.io/ldap/user",
|
"organizationalPerson",
|
||||||
"posixAccount",
|
"inetOrgPerson",
|
||||||
],
|
"goauthentik.io/ldap/user",
|
||||||
"uidNumber": 2000 + embedded_account.pk,
|
"posixAccount",
|
||||||
"gidNumber": 2000 + embedded_account.pk,
|
],
|
||||||
"memberOf": [],
|
"uidNumber": 2000 + embedded_account.pk,
|
||||||
"homeDirectory": f"/home/{embedded_account.username}",
|
"gidNumber": 2000 + embedded_account.pk,
|
||||||
"ak-active": True,
|
"memberOf": [],
|
||||||
"ak-superuser": False,
|
"homeDirectory": f"/home/{embedded_account.username}",
|
||||||
"goauthentikio-user-override-ips": True,
|
"ak-active": True,
|
||||||
"goauthentikio-user-service-account": True,
|
"ak-superuser": False,
|
||||||
},
|
"goauthentikio-user-override-ips": True,
|
||||||
"type": "searchResEntry",
|
"goauthentikio-user-service-account": True,
|
||||||
},
|
},
|
||||||
{
|
"type": "searchResEntry",
|
||||||
"dn": f"cn={self.user.username},ou=users,dc=ldap,dc=goauthentik,dc=io",
|
},
|
||||||
"attributes": {
|
{
|
||||||
"cn": self.user.username,
|
"dn": f"cn={self.user.username},ou=users,dc=ldap,dc=goauthentik,dc=io",
|
||||||
"sAMAccountName": self.user.username,
|
"attributes": {
|
||||||
"uid": self.user.uid,
|
"cn": self.user.username,
|
||||||
"name": self.user.name,
|
"sAMAccountName": self.user.username,
|
||||||
"displayName": self.user.name,
|
"uid": self.user.uid,
|
||||||
"sn": self.user.name,
|
"name": self.user.name,
|
||||||
"mail": self.user.email,
|
"displayName": self.user.name,
|
||||||
"objectClass": [
|
"sn": self.user.name,
|
||||||
"user",
|
"mail": self.user.email,
|
||||||
"organizationalPerson",
|
"objectClass": [
|
||||||
"inetOrgPerson",
|
"user",
|
||||||
"goauthentik.io/ldap/user",
|
"organizationalPerson",
|
||||||
"posixAccount",
|
"inetOrgPerson",
|
||||||
],
|
"goauthentik.io/ldap/user",
|
||||||
"uidNumber": 2000 + self.user.pk,
|
"posixAccount",
|
||||||
"gidNumber": 2000 + self.user.pk,
|
],
|
||||||
"memberOf": [
|
"uidNumber": 2000 + self.user.pk,
|
||||||
f"cn={group.name},ou=groups,dc=ldap,dc=goauthentik,dc=io"
|
"gidNumber": 2000 + self.user.pk,
|
||||||
for group in self.user.ak_groups.all()
|
"memberOf": [
|
||||||
],
|
f"cn={group.name},ou=groups,dc=ldap,dc=goauthentik,dc=io"
|
||||||
"homeDirectory": f"/home/{self.user.username}",
|
for group in self.user.ak_groups.all()
|
||||||
"ak-active": True,
|
],
|
||||||
"ak-superuser": True,
|
"homeDirectory": f"/home/{self.user.username}",
|
||||||
"extraAttribute": ["bar"],
|
"ak-active": True,
|
||||||
},
|
"ak-superuser": True,
|
||||||
"type": "searchResEntry",
|
"extraAttribute": ["bar"],
|
||||||
},
|
},
|
||||||
],
|
"type": "searchResEntry",
|
||||||
)
|
},
|
||||||
|
]
|
||||||
|
self.assert_list_dict_equal(expected, response)
|
||||||
|
|
||||||
|
def assert_list_dict_equal(self, expected: list[dict], actual: list[dict], match_key="dn"):
|
||||||
|
"""Assert a list of dictionaries is identical, ignoring the ordering of items"""
|
||||||
|
self.assertEqual(len(expected), len(actual))
|
||||||
|
for res_item in actual:
|
||||||
|
all_matching = [x for x in expected if x[match_key] == res_item[match_key]]
|
||||||
|
self.assertEqual(len(all_matching), 1)
|
||||||
|
matching = all_matching[0]
|
||||||
|
self.assertDictEqual(res_item, matching)
|
||||||
|
|
||||||
@retry()
|
@retry()
|
||||||
@apply_blueprint(
|
@apply_blueprint(
|
||||||
|
@ -385,14 +392,13 @@ class TestProviderLDAP(SeleniumTestCase):
|
||||||
search_scope=SUBTREE,
|
search_scope=SUBTREE,
|
||||||
attributes=["cn"],
|
attributes=["cn"],
|
||||||
)
|
)
|
||||||
response: dict = _connection.response
|
response: list = _connection.response
|
||||||
# Remove raw_attributes to make checking easier
|
# Remove raw_attributes to make checking easier
|
||||||
for obj in response:
|
for obj in response:
|
||||||
del obj["raw_attributes"]
|
del obj["raw_attributes"]
|
||||||
del obj["raw_dn"]
|
del obj["raw_dn"]
|
||||||
o_user = outpost.user
|
o_user = outpost.user
|
||||||
self.assertCountEqual(
|
self.assert_list_dict_equal(
|
||||||
response,
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"dn": f"cn={o_user.username},ou=users,dc=ldap,dc=goauthentik,dc=io",
|
"dn": f"cn={o_user.username},ou=users,dc=ldap,dc=goauthentik,dc=io",
|
||||||
|
@ -416,4 +422,5 @@ class TestProviderLDAP(SeleniumTestCase):
|
||||||
"type": "searchResEntry",
|
"type": "searchResEntry",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
response,
|
||||||
)
|
)
|
||||||
|
|
Reference in a new issue