You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
5.3 KiB
154 lines
5.3 KiB
import re
|
|
|
|
from click.testing import CliRunner
|
|
|
|
from ceo.cli import cli
|
|
|
|
|
|
def test_groups(cli_setup, ldap_user):
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, [
|
|
'groups', 'add', 'test_group_1', '-d', 'Test Group One',
|
|
], input='y\n')
|
|
expected_pat = re.compile((
|
|
"^The following group will be created:\n"
|
|
"cn: test_group_1\n"
|
|
"description: Test Group One\n"
|
|
"Do you want to continue\\? \\[y/N\\]: y\n"
|
|
"Add user to LDAP... Done\n"
|
|
"Add group to LDAP... Done\n"
|
|
"Add sudo role to LDAP... Done\n"
|
|
"Create home directory... Done\n"
|
|
"Transaction successfully completed.\n"
|
|
"cn: test_group_1\n"
|
|
"description: Test Group One\n"
|
|
"gid_number: \\d{5}\n$"
|
|
), re.MULTILINE)
|
|
assert result.exit_code == 0
|
|
assert expected_pat.match(result.output) is not None
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ['groups', 'get', 'test_group_1'])
|
|
expected_pat = re.compile((
|
|
"^cn: test_group_1\n"
|
|
"description: Test Group One\n"
|
|
"gid_number: \\d{5}\n$"
|
|
), re.MULTILINE)
|
|
assert result.exit_code == 0
|
|
assert expected_pat.match(result.output) is not None
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, [
|
|
'groups', 'addmember', 'test_group_1', ldap_user.uid,
|
|
], input='y\n')
|
|
expected = (
|
|
f"Are you sure you want to add {ldap_user.uid} to test_group_1? [y/N]: y\n"
|
|
"Add user to group... Done\n"
|
|
"Add user to auxiliary groups... Skipped\n"
|
|
"Transaction successfully completed.\n"
|
|
"Added to groups: test_group_1\n"
|
|
)
|
|
assert result.exit_code == 0
|
|
assert result.output == expected
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ['groups', 'get', 'test_group_1'])
|
|
expected_pat = re.compile(f"members:\\s+{ldap_user.cn} \\({ldap_user.uid}\\)")
|
|
assert result.exit_code == 0
|
|
assert expected_pat.search(result.output) is not None
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, [
|
|
'groups', 'removemember', 'test_group_1', ldap_user.uid,
|
|
], input='y\n')
|
|
expected = (
|
|
f"Are you sure you want to remove {ldap_user.uid} from test_group_1? [y/N]: y\n"
|
|
"Remove user from group... Done\n"
|
|
"Remove user from auxiliary groups... Skipped\n"
|
|
"Transaction successfully completed.\n"
|
|
"Removed from groups: test_group_1\n"
|
|
)
|
|
assert result.exit_code == 0
|
|
assert result.output == expected
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ['groups', 'delete', 'test_group_1'], input='y\n')
|
|
assert result.exit_code == 0
|
|
|
|
|
|
def create_group(group_name, desc):
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, [
|
|
'groups', 'add', group_name, '-d', desc,
|
|
], input='y\n')
|
|
assert result.exit_code == 0
|
|
|
|
|
|
def delete_group(group_name):
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ['groups', 'delete', group_name], input='y\n')
|
|
assert result.exit_code == 0
|
|
|
|
|
|
def test_groups_with_auxiliary_groups_and_mailing_lists(cli_setup, ldap_user):
|
|
runner = CliRunner()
|
|
# make sure auxiliary groups + mailing lists exist in ceod_test_local.ini
|
|
create_group('syscom', 'Systems Committee')
|
|
create_group('office', 'Office')
|
|
create_group('staff', 'Staff')
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, [
|
|
'groups', 'addmember', 'syscom', ldap_user.uid,
|
|
], input='y\n')
|
|
expected = (
|
|
f"Are you sure you want to add {ldap_user.uid} to syscom? [y/N]: y\n"
|
|
"Add user to group... Done\n"
|
|
"Add user to auxiliary groups... Done\n"
|
|
"Subscribe user to auxiliary mailing lists... Done\n"
|
|
"Transaction successfully completed.\n"
|
|
"Added to groups: syscom\n"
|
|
" office\n"
|
|
" staff\n"
|
|
"Subscribed to lists: syscom@csclub.internal\n"
|
|
" syscom-alerts@csclub.internal\n"
|
|
)
|
|
assert result.exit_code == 0
|
|
assert result.output == expected
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, [
|
|
'groups', 'removemember', 'syscom', ldap_user.uid,
|
|
], input='y\n')
|
|
expected = (
|
|
f"Are you sure you want to remove {ldap_user.uid} from syscom? [y/N]: y\n"
|
|
"Remove user from group... Done\n"
|
|
"Remove user from auxiliary groups... Done\n"
|
|
"Unsubscribe user from auxiliary mailing lists... Done\n"
|
|
"Transaction successfully completed.\n"
|
|
"Removed from groups: syscom\n"
|
|
" office\n"
|
|
" staff\n"
|
|
"Unsubscribed from lists: syscom@csclub.internal\n"
|
|
" syscom-alerts@csclub.internal\n"
|
|
)
|
|
assert result.exit_code == 0
|
|
assert result.output == expected
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, [
|
|
'groups', 'addmember', 'syscom', ldap_user.uid, '--no-subscribe',
|
|
], input='y\n')
|
|
assert result.exit_code == 0
|
|
assert 'Subscribed to lists' not in result.output
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, [
|
|
'groups', 'removemember', 'syscom', ldap_user.uid, '--no-unsubscribe',
|
|
], input='y\n')
|
|
assert result.exit_code == 0
|
|
assert 'Unsubscribed from lists' not in result.output
|
|
|
|
delete_group('syscom')
|
|
delete_group('office')
|
|
delete_group('staff')
|
|
|