Esempio n. 1
0
 def test_get_and_set_DatabasePasswordByUser_simple(self):
     from django.conf import settings
     from psafefe.psafe.models import *
     from psafefe.psafe.functions import getUsersPersonalSafe, getDatabasePasswordByUser, setDatabasePasswordByUser
     # Create a user with read/write access to the test safe repo
     username, user = self.getUser(
                                   userClass = 'user',
                                   groups = [
                                             self.groupsByRepo['testsafes']['writes'],
                                             self.groupsByRepo['testsafes']['reads'],
                                             ],
                                   )
     userpass = self.getUserPass(user = user)
     
     mySafe = getUsersPersonalSafe(
                                   user = user,
                                   userPassword = userpass,
                                   wait = True,
                                   )
     self.assertTrue(mySafe)
     
     # Get the DB we're working with
     db = PasswordSafe.objects.get(
                                   repo = self.groupsByRepo['testsafes']['repo'],
                                   filename__endswith = "simple.psafe3",
                                   )
     
     # Save the DB password
     setDatabasePasswordByUser(
                               user = user,
                               userPassword = userpass,
                               psafe = db,
                               psafePassword = '******',
                               wait = True,
                               )
     
     # Try with ppsafe set 
     dbPassword = getDatabasePasswordByUser(
                                            user = user,
                                            userPassword = userpass,
                                            psafe = db,
                                            ppsafe = mySafe,
                                            wait = True,
                                            )  
     self.assertEqual(dbPassword, 'bogus12345', "Password for simple.psafe3 is wrong or has changed. Was trying without passing in a personal psafe to getDatabasePasswordByUser")      
     # try without ppsafe set
     dbPassword = getDatabasePasswordByUser(
                                            user = user,
                                            userPassword = userpass,
                                            psafe = db,
                                            ppsafe = None,
                                            wait = True,
                                            )
     self.assertEqual(dbPassword, 'bogus12345', "Password for simple.psafe3 is wrong or has changed. Was trying with passing in a personal psafe to getDatabasePasswordByUser")
Esempio n. 2
0
def createPersonalPSafe(username, password, **kw):
    """ Create and initialize a personal psafe for the calling user if the user 
    doesn't already have one.
     
    @param username: Requesting user's login
    @type username: string
    @param password: Requesting user's login
    @type password: string
    @return: boolean, True on success, error otherwise
    """
    from psafefe.psafe.functions import getUsersPersonalSafe
    p = getUsersPersonalSafe(user=kw['user'], userPassword=password, wait=True)
    return True
Esempio n. 3
0
 def test_getUsersPersonalSafe_simple(self):
     from django.conf import settings
     from psafefe.psafe.functions import getUsersPersonalSafe
     # Create a user with read/write access to the test safe repo
     username, user = self.getUser(
                                   userClass = 'user',
                                   groups = [
                                             self.groupsByRepo['testsafes']['writes'],
                                             self.groupsByRepo['testsafes']['reads'],
                                             ],
                                   )
     userpass = self.getUserPass(user = user)
     
     mySafe = getUsersPersonalSafe(
                                   user = user,
                                   userPassword = userpass,
                                   wait = True,
                                   )
     self.assertTrue(mySafe)
     
     myMemSafe = mySafe.getCached(canLoad = False)
     self.assertTrue(myMemSafe, "Failed to automatically create and load a new safe and it's cached entry")