def setUp(self): for testfile in ["restauth-test", "restauth-test-group", "restauth-test-group-unknown", "restauth-test-domain"]: self.assertTrue(os.path.exists("/etc/pam.d/%s" % testfile), """ Missing PAM service configurations exist in /etc/pam.d/. See this test class's documentation for how to create them. """) self.conn = common.RestAuthConnection("http://[::1]:8000", "vowi", "vowi") self.user1 = restauth_user.create(self.conn, "user1", "password1") self.user2 = restauth_user.create(self.conn, "user2", "password2") self.user3 = restauth_user.create(self.conn, "user3", "password3") self.group = group.create(self.conn, "testgroup") self.group.add_user(self.user1)
users = restauth_user.get_all( conn ) if users: print( users ) raise RuntimeError( "Left over users:" ) groups = group.get_all( conn ) if groups: print( groups ) raise RuntimeError( "Left over groups!" ) ########################## ### BASIC USER TESTING ### ########################## print( 'Creating test users... ', end='' ) user0 = restauth_user.create( conn, 'user0', 'password0' ) user1 = restauth_user.create( conn, 'user1', 'password1' ) user2 = restauth_user.create( conn, 'user2', 'password2' ) user3 = restauth_user.create( conn, 'user3', 'password3' ) user4 = restauth_user.create( conn, 'user4', 'password4' ) user5 = restauth_user.create( conn, 'user5', 'password5' ) user6 = restauth_user.create( conn, 'user6', 'password6' ) user7 = restauth_user.create( conn, 'user7', 'password7' ) user8 = restauth_user.create( conn, 'user8', 'password8' ) user9 = restauth_user.create( conn, 'user9', 'password9' ) print( 'Ok.' ) print( 'Verifing added users... ', end='' ) user_list = restauth_user.get_all( conn ) if len( user_list ) == 10: print( 'Ok.' )
# and managing membershipto users at all. If everything works, this script does # not do any output. import os, sys sys.path.append( os.getcwd() ) # so we can import RestAuthClient # common includes the connection handling code, restauth_user handles user- # specific code: from RestAuthClient import common, restauth_user conn = common.RestAuthConnection( '::1', 8000, 'vowi', 'vowi', False ) # create a new user. the standard configuration does not allow spaces in the # username, because this does not work on XMPP, email, ... # The factory-methods for creating users guarantee that the user exist: managed_user = restauth_user.create( conn, 'managed_user', 'password' ) # handle the password: if managed_user.verify_password( 'password' ): pass else: # password is not correct print( "Error: The password is not correct?" ) managed_user.set_password( 'new password' ) # Now we want to get a user from the service - this again guarantees that the # user exists: managed_user = restauth_user.get( conn, 'managed_user' ) # You can always just construct your own object, i.e. if you know that the user