def test_update_passwd_mock(self):
        passwd_file = passwd.get_config().get('auth', 'passwd_file')
        if not os.path.exists(passwd_file):
            with open(passwd_file, 'w') as f:
                f.write('')

        passwd.add_user(self.username, 'password')
        self.assertUserExists(self.username)
        self.assertUserPassword(self.username, 'password')

        try:

            class DummySha1(object):
                def __init__(self, string):
                    self.string = string

                def update(self, string):
                    pass

                def digest(self):
                    return self.string

            sha1 = passwd.hashlib.sha1
            encode = passwd.encode
            ssha_hash = authentication.ssha_hash
            get_salt = passwd.get_salt

            try:
                passwd.get_salt = passwd.get_salt_dummy
                passwd.hashlib.sha1 = DummySha1
                passwd.encode = lambda x: x
                passwd.decode = lambda x: x
                authentication.ssha_hash = lambda u, x, y: '{SSHA}' + x + y[-4:
                                                                            ]

                passwd.update_passwd(self.username,
                                     password='******',
                                     force_askpass=False,
                                     group='somegroup')

                self.assertUserExists(self.username)
                self.assertUserPassword(self.username, 'newpassword')
            finally:
                passwd.hashlib.sha1 = sha1
                passwd.encode = encode
                authentication.ssha_hash = ssha_hash
                passwd.get_salt = get_salt

            passwd.update_passwd(self.username,
                                 password='******',
                                 force_askpass=False,
                                 group='somegroup')
            self.assertUserExists(self.username)
            self.assertUserPassword(self.username, 'newpassword')

        finally:
            passwd.delete_user(self.username)
    def test_update_passwd_mock(self):
        passwd_file = passwd.get_config().get('auth', 'passwd_file')
        if not os.path.exists(passwd_file):
            with open(passwd_file, 'w') as f:
                f.write('')

        passwd.add_user(self.username, 'password')
        self.assertUserExists(self.username)
        self.assertUserPassword(self.username, 'password')

        try:
            class DummySha1(object):
                def __init__(self, string):
                    self.string = string

                def update(self, string):
                    pass

                def digest(self):
                    return self.string

            sha1 = passwd.hashlib.sha1
            encode = passwd.encode
            ssha_hash = authentication.ssha_hash
            get_salt = passwd.get_salt

            try:
                passwd.get_salt = passwd.get_salt_dummy
                passwd.hashlib.sha1 = DummySha1
                passwd.encode = lambda x: x
                passwd.decode = lambda x: x
                authentication.ssha_hash = lambda u, x, y: '{SSHA}' + x + y[-4:]

                passwd.update_passwd(self.username, password='******',
                                     force_askpass=False, group='somegroup')

                self.assertUserExists(self.username)
                self.assertUserPassword(self.username, 'newpassword')
            finally:
                passwd.hashlib.sha1 = sha1
                passwd.encode = encode
                authentication.ssha_hash = ssha_hash
                passwd.get_salt = get_salt

            passwd.update_passwd(self.username, password='******',
                                 force_askpass=False, group='somegroup')
            self.assertUserExists(self.username)
            self.assertUserPassword(self.username, 'newpassword')

        finally:
            passwd.delete_user(self.username)
    def test_add_delete_user(self):
        passwd_file = passwd.get_config().get('auth', 'passwd_file')
        if not os.path.exists(passwd_file):
            with open(passwd_file, 'w') as f:
                f.write('')

        try:
            passwd.add_user(self.username, 'password')
            self.assertUserExists(self.username)
            self.assertUserPassword(self.username, 'password')
        finally:
            passwd.delete_user(self.username)

        passwd.delete_user(self.username)
        self.assertRaises(self.failureException, self.assertUserExists,
                          self.username)
    def test_add_delete_user(self):
        passwd_file = passwd.get_config().get('auth', 'passwd_file')
        if not os.path.exists(passwd_file):
            with open(passwd_file, 'w') as f:
                f.write('')

        try:
            passwd.add_user(self.username, 'password')
            self.assertUserExists(self.username)
            self.assertUserPassword(self.username, 'password')
        finally:
            passwd.delete_user(self.username)

        passwd.delete_user(self.username)
        self.assertRaises(self.failureException,
                          self.assertUserExists, self.username)
    def test_update_password_changes_single_record(self):
        passwd.add_user(self.username, 'password')
        passwd.add_user(self.username + '1', 'password')
        passwd.add_user(self.username + '2', 'password')
        self.assertUserExists(self.username)
        self.assertUserExists(self.username + '1')
        self.assertUserExists(self.username + '2')

        self.assertUserPassword(self.username, 'password')
        self.assertUserPassword(self.username + '1', 'password')
        self.assertUserPassword(self.username + '2', 'password')

        try:
            passwd.update_passwd(self.username,
                                 password='******',
                                 force_askpass=False,
                                 group='somegroup')
            self.assertUserExists(self.username)
            self.assertUserPassword(self.username, 'newpassword')
            self.assertUserPassword(self.username + '1', 'password')
            self.assertUserPassword(self.username + '2', 'password')
        finally:
            passwd.delete_user(self.username)
            passwd.delete_user(self.username + '1')
            passwd.delete_user(self.username + '2')
    def test_update_passwd(self):
        passwd.add_user(self.username + 'asdfghj', 'asdfghjkl')
        passwd.add_user(self.username, 'password')
        passwd.add_user(self.username + 'poiuytr', 'poiuytr')
        self.assertUserExists(self.username)
        self.assertUserPassword(self.username, 'password')

        try:
            passwd.update_passwd(self.username, password='******',
                                 force_askpass=False, group='somegroup')
            self.assertUserExists(self.username)
            self.assertUserPassword(self.username, 'pdadsdasdas')
            self.assertRaises(self.failureException, self.assertUserPassword, self.username, 'p')
        finally:
            passwd.delete_user(self.username)
    def test_update_passwd(self):
        passwd.add_user(self.username + 'asdfghj', 'asdfghjkl')
        passwd.add_user(self.username, 'password')
        passwd.add_user(self.username + 'poiuytr', 'poiuytr')
        self.assertUserExists(self.username)
        self.assertUserPassword(self.username, 'password')

        try:
            passwd.update_passwd(self.username,
                                 password='******',
                                 force_askpass=False,
                                 group='somegroup')
            self.assertUserExists(self.username)
            self.assertUserPassword(self.username, 'pdadsdasdas')
            self.assertRaises(self.failureException, self.assertUserPassword,
                              self.username, 'p')
        finally:
            passwd.delete_user(self.username)
    def test_update_password_changes_single_record(self):
        passwd.add_user(self.username, 'password')
        passwd.add_user(self.username + '1', 'password')
        passwd.add_user(self.username + '2', 'password')
        self.assertUserExists(self.username)
        self.assertUserExists(self.username + '1')
        self.assertUserExists(self.username + '2')

        self.assertUserPassword(self.username, 'password')
        self.assertUserPassword(self.username + '1', 'password')
        self.assertUserPassword(self.username + '2', 'password')

        try:
            passwd.update_passwd(self.username, password='******',
                                 force_askpass=False, group='somegroup')
            self.assertUserExists(self.username)
            self.assertUserPassword(self.username, 'newpassword')
            self.assertUserPassword(self.username + '1', 'password')
            self.assertUserPassword(self.username + '2', 'password')
        finally:
            passwd.delete_user(self.username)
            passwd.delete_user(self.username + '1')
            passwd.delete_user(self.username + '2')
예제 #9
0
 def execute(self, args):
     try:
         add_user(args.user, args.password, group=args.g, uid=args.uid)
     except UserManagementError as e:
         self.write('%s\n' % str(e))
예제 #10
0
 def execute(self, args):
     try:
         add_user(args.user, args.password, group=args.g, uid=args.uid)
     except UserManagementError as e:
         self.write('%s\n' % str(e))