def test_create(self, is_group, calnet_uid, callink_oid, expected, fake_new_account_request, fake_credentials): with mock.patch('ocflib.account.creation.create_kerberos_principal_with_keytab') as kerberos, \ mock.patch('ocflib.account.creation.get_kerberos_principal_with_keytab', return_value=None) as kerberos_get, \ mock.patch('ocflib.account.creation.create_ldap_entry_with_keytab') as ldap, \ mock.patch('ocflib.account.creation.create_home_dir') as home_dir, \ mock.patch('ocflib.account.creation.ensure_web_dir') as web_dir, \ mock.patch('ocflib.account.creation.send_created_mail') as send_created_mail, \ mock.patch('ocflib.account.creation._get_first_available_uid', return_value=42) as get_uid, \ mock.patch('ocflib.account.creation.call') as call, \ freeze_time('2015-08-22 14:11:44'): fake_new_account_request = fake_new_account_request._replace( is_group=is_group, calnet_uid=calnet_uid, callink_oid=callink_oid, ) new_uid = create_account( fake_new_account_request, fake_credentials, mock.MagicMock(), known_uid=1, ) assert new_uid == 42 get_uid.assert_called_once_with(1) kerberos_get.assert_called_once_with( fake_new_account_request.user_name, fake_credentials.kerberos_keytab, fake_credentials.kerberos_principal, ) kerberos.assert_called_once_with( fake_new_account_request.user_name, fake_credentials.kerberos_keytab, fake_credentials.kerberos_principal, password='******', ) ldap.assert_called_once_with( 'uid=someuser,ou=People,dc=OCF,dc=Berkeley,dc=EDU', dict( { 'cn': ['Some User'], 'gidNumber': ['1000'], 'objectClass': ['ocfAccount', 'account', 'posixAccount'], 'uidNumber': ['42'], 'homeDirectory': ['/home/s/so/someuser'], 'loginShell': ['/bin/bash'], 'mail': ['*****@*****.**'], 'userPassword': ['{SASL}[email protected]'], 'creationTime': ['20150822141144Z'], }, **expected), fake_credentials.kerberos_keytab, fake_credentials.kerberos_principal, ) call.assert_called_once_with(('sudo', 'nscd', '-i', 'passwd')) home_dir.assert_called_once_with( fake_new_account_request.user_name) web_dir.assert_called_once_with(fake_new_account_request.user_name) send_created_mail.assert_called_once_with(fake_new_account_request)
def test_create( self, is_group, calnet_uid, callink_oid, expected, fake_new_account_request, fake_credentials ): @contextmanager def report_status(start, end, line): yield with mock.patch('ocflib.account.creation.create_kerberos_principal_with_keytab') as kerberos, \ mock.patch('ocflib.account.creation.create_ldap_entry_with_keytab') as ldap, \ mock.patch('ocflib.account.creation.create_home_dir') as home_dir, \ mock.patch('ocflib.account.creation.create_web_dir') as web_dir, \ mock.patch('ocflib.account.creation.send_created_mail') as send_created_mail, \ mock.patch('ocflib.account.creation._get_first_available_uid', return_value=42), \ mock.patch('ocflib.account.creation.call') as call, \ freeze_time('2015-08-22 14:11:44'): fake_new_account_request = fake_new_account_request._replace( is_group=is_group, calnet_uid=calnet_uid, callink_oid=callink_oid, ) create_account( fake_new_account_request, fake_credentials, report_status, ) kerberos.assert_called_once_with( fake_new_account_request.user_name, fake_credentials.kerberos_keytab, fake_credentials.kerberos_principal, password='******', ) ldap.assert_called_once_with( 'uid=someuser,ou=People,dc=OCF,dc=Berkeley,dc=EDU', dict({ 'cn': ['Some User'], 'gidNumber': ['1000'], 'objectClass': ['ocfAccount', 'account', 'posixAccount'], 'uidNumber': ['42'], 'homeDirectory': ['/home/s/so/someuser'], 'loginShell': ['/bin/bash'], 'mail': ['*****@*****.**'], 'userPassword': ['{SASL}[email protected]'], 'creationTime': ['20150822141144Z'], }, **expected), fake_credentials.kerberos_keytab, fake_credentials.kerberos_principal, ) call.assert_called_once_with(('sudo', 'nscd', '-i', 'passwd')) home_dir.assert_called_once_with(fake_new_account_request.user_name) web_dir.assert_called_once_with(fake_new_account_request.user_name) send_created_mail.assert_called_once_with(fake_new_account_request)
def test_create(self, is_group, calnet_uid, callink_oid, expected, fake_new_account_request, fake_credentials): @contextmanager def report_status(start, end, line): yield with mock.patch("ocflib.account.creation.create_kerberos_principal_with_keytab") as kerberos, mock.patch( "ocflib.account.creation.create_ldap_entry_with_keytab" ) as ldap, mock.patch("ocflib.account.creation.create_home_dir") as home_dir, mock.patch( "ocflib.account.creation.create_web_dir" ) as web_dir, mock.patch( "ocflib.account.creation.send_created_mail" ) as send_created_mail, mock.patch( "ocflib.account.creation._get_first_available_uid", return_value=42 ), mock.patch( "ocflib.account.creation.call" ) as call, freeze_time( "2015-08-22 14:11:44" ): fake_new_account_request = fake_new_account_request._replace( is_group=is_group, calnet_uid=calnet_uid, callink_oid=callink_oid ) create_account(fake_new_account_request, fake_credentials, report_status) kerberos.assert_called_once_with( fake_new_account_request.user_name, fake_credentials.kerberos_keytab, fake_credentials.kerberos_principal, password="******", ) ldap.assert_called_once_with( "uid=someuser,ou=People,dc=OCF,dc=Berkeley,dc=EDU", dict( { "cn": ["Some User"], "gidNumber": ["1000"], "objectClass": ["ocfAccount", "account", "posixAccount"], "uidNumber": ["42"], "homeDirectory": ["/home/s/so/someuser"], "loginShell": ["/bin/bash"], "mail": ["*****@*****.**"], "userPassword": ["{SASL}[email protected]"], "creationTime": ["20150822141144Z"], }, **expected ), fake_credentials.kerberos_keytab, fake_credentials.kerberos_principal, ) call.assert_called_once_with(("sudo", "nscd", "-i", "passwd")) home_dir.assert_called_once_with(fake_new_account_request.user_name) web_dir.assert_called_once_with(fake_new_account_request.user_name) send_created_mail.assert_called_once_with(fake_new_account_request)
def test_create(self, is_group, calnet_uid, callink_oid, expected, fake_new_account_request, fake_credentials): @contextmanager def report_status(start, end, line): yield with mock.patch('ocflib.account.creation.create_kerberos_principal_with_keytab') as kerberos, \ mock.patch('ocflib.account.creation.create_ldap_entry_with_keytab') as ldap, \ mock.patch('ocflib.account.creation.create_home_dir') as home_dir, \ mock.patch('ocflib.account.creation.create_web_dir') as web_dir, \ mock.patch('ocflib.account.creation.send_created_mail') as send_created_mail, \ mock.patch('ocflib.account.creation._get_first_available_uid', return_value=42): fake_new_account_request = fake_new_account_request._replace( is_group=is_group, calnet_uid=calnet_uid, callink_oid=callink_oid, ) create_account( fake_new_account_request, fake_credentials, report_status, ) kerberos.assert_called_once_with( fake_new_account_request.user_name, fake_credentials.kerberos_keytab, fake_credentials.kerberos_principal, password='******', ) ldap.assert_called_once_with( 'uid=someuser,ou=People,dc=OCF,dc=Berkeley,dc=EDU', dict( { 'cn': ['Some User'], 'gidNumber': ['1000'], 'objectClass': ['ocfAccount', 'account', 'posixAccount'], 'uidNumber': ['42'], 'homeDirectory': ['/home/s/so/someuser'], 'loginShell': ['/bin/bash'], 'mail': ['*****@*****.**'], 'userPassword': ['{SASL}[email protected]'], }, **expected), fake_credentials.kerberos_keytab, fake_credentials.kerberos_principal, ) home_dir.assert_called_once_with( fake_new_account_request.user_name) web_dir.assert_called_once_with(fake_new_account_request.user_name) send_created_mail.assert_called_once_with(fake_new_account_request)
def test_create( self, is_group, calnet_uid, callink_oid, expected, fake_new_account_request, fake_credentials ): with mock.patch('ocflib.account.creation.create_kerberos_principal_with_keytab') as kerberos, \ mock.patch('ocflib.account.creation.get_kerberos_principal_with_keytab', return_value=None) as kerberos_get, \ mock.patch('ocflib.account.creation.create_ldap_entry_with_keytab') as ldap, \ mock.patch('ocflib.account.creation.create_home_dir') as home_dir, \ mock.patch('ocflib.account.creation.ensure_web_dir') as web_dir, \ mock.patch('ocflib.account.creation.send_created_mail') as send_created_mail, \ mock.patch('ocflib.account.creation._get_first_available_uid', return_value=42) as get_uid, \ mock.patch('ocflib.account.creation.call') as call, \ freeze_time('2015-08-22 14:11:44'): fake_new_account_request = fake_new_account_request._replace( is_group=is_group, calnet_uid=calnet_uid, callink_oid=callink_oid, ) new_uid = create_account( fake_new_account_request, fake_credentials, mock.MagicMock(), known_uid=1, ) assert new_uid == 42 get_uid.assert_called_once_with(1) kerberos_get.assert_called_once_with( fake_new_account_request.user_name, fake_credentials.kerberos_keytab, fake_credentials.kerberos_principal, ) kerberos.assert_called_once_with( fake_new_account_request.user_name, fake_credentials.kerberos_keytab, fake_credentials.kerberos_principal, password='******', ) ldap.assert_called_once_with( 'uid=someuser,ou=People,dc=OCF,dc=Berkeley,dc=EDU', dict({ 'cn': ['Some User'], 'gidNumber': 1000, 'objectClass': ['ocfAccount', 'account', 'posixAccount'], 'uidNumber': 42, 'homeDirectory': '/home/s/so/someuser', 'loginShell': '/bin/bash', 'mail': ['*****@*****.**'], 'userPassword': '******', 'creationTime': datetime.now(), }, **expected), fake_credentials.kerberos_keytab, fake_credentials.kerberos_principal, ) call.assert_called_once_with(('sudo', 'nscd', '-i', 'passwd')) home_dir.assert_called_once_with(fake_new_account_request.user_name) web_dir.assert_called_once_with(fake_new_account_request.user_name) send_created_mail.assert_called_once_with(fake_new_account_request)