def test_credentials(self): password = uts.random_name() dn, username = self.udm_test.create_user(password=password) mod = UDM.credentials(identity=username, password=password).version(0).get('users/user') assert mod.connection.binddn == dn password = uts.random_name() dn, username = self.udm_test.create_user(password=password) mod = UDM.credentials(identity=dn, password=password).version(0).get('users/user') assert mod.connection.binddn == dn
def test_credentials_error(self): username = uts.random_name() password = uts.random_name() with self.assertRaises(ConnectionError) as cm: UDM.credentials(identity=username, password=password) assert str(cm.exception) == 'Cannot get DN for username' with self.assertRaises(ConnectionError) as cm: UDM.credentials(identity='Administrator', password=password) assert str(cm.exception) == 'Credentials invalid'
def test_local(self): password = uts.random_name() dn, username = self.udm_test.create_user(password=password) server = self.ucr_test['ldap/server/name'] port = self.ucr_test['ldap/server/port'] mod = UDM.credentials(identity=username, password=password, server=server, port=port).version(0).get('users/user') assert mod.connection.binddn == dn
def simple_udm(ucr): # type: () -> UDM account = utils.UCSTestDomainAdminCredentials() return UDM.credentials( account.binddn, account.bindpw, ucr["ldap/base"], ucr["ldap/master"], ucr["ldap/master/port"], ).version(1)
def list_users(self): """ convenience function for the username entry. Lists all user names. We don't return this as an array of {id, label} tuples because: (1) id and label are always the same here (2) at the frontend, we must do some postprocessing, and an array is easier to handle. (3) the ComboBox is able to handle a plain array. """ ucr = ConfigRegistry() ucr.load() identity = ucr.get('ldap/hostdn') password = open('/etc/machine.secret').read().rstrip('\n') server = ucr.get('ldap/server/name') udm = UDM.credentials(identity, password, server=server).version(1) users = udm.get('users/user').search() return [user.props.username for user in users]
def get_writable_udm(binddn=None, bindpwdfile=None): # type: (Optional[str], Optional[str]) -> univention.udm.udm.UDM if binddn: if not bindpwdfile: error('"binddn" provided but not "bindpwdfile".') try: with open(bindpwdfile, 'r') as f: bindpwd = f.read().strip() except IOError as err: error('Could not open "bindpwdfile" "%s": %s' % ( bindpwdfile, err, )) ucr = ConfigRegistry() ucr.load() try: udm = UDM.credentials(binddn, bindpwd, ucr.get('ldap/base'), ucr.get('ldap/master'), ucr.get('ldap/master/port')) except univention.udm.exceptions.ConnectionError as err: error( 'Could not connect to server "%s" with provided "binddn" "%s" and "bindpwdfile" "%s": %s' % ( ucr.get('ldap/master'), binddn, bindpwdfile, err, )) else: try: udm = UDM.admin() except univention.udm.exceptions.ConnectionError as err: error( 'Could not create a writable connection to UDM on this server. Try to provide "binddn" and "bindpwdfile": %s' % (err, )) udm.version(2) return udm