Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anodos325 committed Jun 28, 2024
1 parent 8c1fbd0 commit 5f892e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/middlewared/middlewared/plugins/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def do_update(self, app, audit_callback, pk, data):
audit_callback(username)
raise CallError(
'Users provided by a directory service must be modified through the identity provider '
'(LDAP server or domain controller).'
'(LDAP server or domain controller).', errno.EPERM
)

user = self.middleware.call_sync('user.get_instance', pk)
Expand Down Expand Up @@ -921,7 +921,7 @@ def do_delete(self, audit_callback, pk, options):
audit_callback(username)
raise CallError(
'Users provided by a directory service must be deleted from the identity provider '
'(LDAP server or domain controller).'
'(LDAP server or domain controller).', errno.EPERM
)


Expand Down Expand Up @@ -1962,7 +1962,7 @@ async def do_update(self, audit_callback, pk, data):
audit_callback(groupname)
raise CallError(
'Groups provided by a directory service must be modified through the identity provider '
'(LDAP server or domain controller).'
'(LDAP server or domain controller).', errno.EPERM
)

group = await self.get_instance(pk)
Expand Down Expand Up @@ -2056,7 +2056,7 @@ async def do_delete(self, audit_callback, pk, options):
audit_callback(groupname)
raise CallError(
'Groups provided by a directory service must be deleted from the identity provider '
'(LDAP server or domain controller).'
'(LDAP server or domain controller).', errno.EPERM
)

group = await self.get_instance(pk)
Expand Down
15 changes: 15 additions & 0 deletions tests/api2/test_040_ad_user_group_cache.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env python3

import errno
import pytest
import sys
import os
apifolder = os.getcwd()
sys.path.append(apifolder)
from functions import SSH_TEST
from auto_config import password, user
from middlewared.service_exception import CallError
from middlewared.test.integration.assets.directory_service import active_directory
from middlewared.test.integration.utils import call

Expand Down Expand Up @@ -175,3 +177,16 @@ def test_check_lazy_initialization_of_users_and_groups_by_id(do_ad_connection):
)])

assert cache_names == {ad_group['name']}

@pytest.mark.parametrize('UPDATE', 'DELETE')
def test_update_delete_failures(do_ad_connection, op_type):
ad_user, ad_group = get_ad_user_and_group(do_ad_connection)

for acct, prefix in ((ad_user, 'user'), (ad_group, 'group')):
with pytest.raises(CallError) as ce:
if op_type == 'UPDATE':
call(f'{prefix}.update', acct['id'], {'smb': False})
else:
call(f'{prefix}.delete', acct['id'])

assert ce.value.errno == errno.EPERM

0 comments on commit 5f892e1

Please sign in to comment.