def _pwauth(auth): """ <Purpose> Internally used function that performs authorization based on the account password rather than the account api key. <Arguments> auth An authorization dict of the form {'username':username, 'password':password} <Exceptions> Raises xmlrpclib Fault Objects: FAULTCODE_INVALIDREQUEST if the auth dict is invalid. FAULTCODE_AUTHERROR if user auth fails. <Returns> On successful authentication, returns a geniuser object. Raises a fault otherwise. """ if not isinstance(auth, dict): raise xmlrpclib.Fault(FAULTCODE_INVALIDREQUEST, "Auth dict must be a dictionary, not a " + str(type(auth))) try: username = auth['username'] password = auth['password'] except KeyError: raise xmlrpclib.Fault(FAULTCODE_INVALIDREQUEST, "PasswordAuth dict must contain both a 'username' and an 'password'.") try: geni_user = interface.get_user_with_password(username, password) except DoesNotExistError: raise xmlrpclib.Fault(FAULTCODE_AUTHERROR, "User auth failed.") return geni_user
def _pwauth(auth): """ <Purpose> Internally used function that performs authorization based on the account password rather than the account api key. <Arguments> auth An authorization dict of the form {'username':username, 'password':password} <Exceptions> Raises xmlrpclib Fault Objects: FAULTCODE_INVALIDREQUEST if the auth dict is invalid. FAULTCODE_AUTHERROR if user auth fails. <Returns> On successful authentication, returns a geniuser object. Raises a fault otherwise. """ if not isinstance(auth, dict): raise xmlrpclib.Fault(FAULTCODE_INVALIDREQUEST, "Auth dict must be a dictionary, not a " + str(type(auth))) try: username = auth["username"] password = auth["password"] except KeyError: raise xmlrpclib.Fault( FAULTCODE_INVALIDREQUEST, "PasswordAuth dict must contain both a 'username' and an 'password'." ) try: geni_user = interface.get_user_with_password(username, password) except DoesNotExistError: raise xmlrpclib.Fault(FAULTCODE_AUTHERROR, "User auth failed.") return geni_user
from seattlegeni.common.api import maindb from seattlegeni.common.exceptions import * from seattlegeni.website.control import interface import random def testfailed(reason): raise Exception("Test failed: " + reason) username = '******' + str(random.randint(0, 1000000)) # Create a user. geniuser = interface.register_user(username, 'mypass', '*****@*****.**', 'myaffiliation') # Get the user. geniuser = interface.get_user_with_password(username, 'mypass') # Make sure the private key was created because we didn't provide a pubkey when # creating the user. privkey = interface.get_private_key(geniuser) if privkey is None: testfailed("private key wasn't created") # Delete the private key and make sure it gets deleted. interface.delete_private_key(geniuser) privkey = interface.get_private_key(geniuser) if privkey is not None: testfailed("private key wasn't deleted: " + str(privkey))