Skip to content

Commit

Permalink
[16.0][FIX] users_ldap_groups test coverage
Browse files Browse the repository at this point in the history
add test_users_ldap_groups_ldap_returns_binary_data
  • Loading branch information
oh2fih committed Mar 30, 2024
1 parent 7e2f803 commit 080ae25
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions users_ldap_groups/tests/test_users_ldap_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,70 @@ def _test_users_ldap_groups_not_user_type(self):
self.env["res.users"].sudo().authenticate(
self.env.cr.dbname, "users_ldap_groups-username", "password", {}
)

def test_users_ldap_groups_ldap_returns_binary_data(self):
self._create_ldap_config(
groups=[
{
"ldap_attribute": "name",
"operator": "contains",
"value": "hello3",
"group_id": self.group_system.id,
},
{
"ldap_attribute": "name",
"operator": "contains",
"value": "hello",
"group_id": self.group_user.id,
},
{
"ldap_attribute": "name",
"operator": "contains",
"value": "hello2",
"group_id": self.group_contains.id,
},
{
"ldap_attribute": "name",
"operator": "equals",
"value": "hello",
"group_id": self.group_equals.id,
},
{
"ldap_attribute": "",
"operator": "query",
"value": "is not run because of patching",
"group_id": self.group_query.id,
},
],
only_ldap_groups=True,
)
with mock.patch(
_company_ldap_class + "._connect",
return_value=FakeLdapConnection(
{
"dc=users_ldap_groups,dc=example,dc=com": {
"cn": [b"User Name"],
"name": [b"hello", b"hello2"],
"thumbnailPhoto": [
b"GIF89a\x01\x00\x01\x00\x00\xff\x00,"
b"\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x00;"
],
}
}
),
), mock_cursor(self.cr):
user_id = (
self.env["res.users"]
.sudo()
.authenticate(
self.env.cr.dbname, "users_ldap_groups-username", "password", {}
)
)
# this asserts group mappings from demo data
user = self.env["res.users"].sudo().browse(user_id)
groups = user.groups_id
self.assertIn(self.group_contains, groups)
self.assertIn(self.group_user, groups)
self.assertNotIn(self.group_equals, groups)
self.assertIn(self.group_query, groups)
self.assertNotIn(self.group_system, groups)

0 comments on commit 080ae25

Please sign in to comment.