def find_user_line(self, username):
        passwd_file = passwd.get_config().get('auth', 'passwd_file')
        with open(passwd_file) as f:
            lines = f.readlines()

        for line in lines:
            if line.startswith(username + ':'):
                return line
    def find_user_line(self, username):
        passwd_file = passwd.get_config().get('auth', 'passwd_file')
        with open(passwd_file) as f:
            lines = f.readlines()

        for line in lines:
            if line.startswith(username + ':'):
                return line
    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 setUp(self):
        passwd.get_config = mock_get_config
        passwd_file = passwd.get_config().get('auth', 'passwd_file')

        if not os.path.exists(passwd_file):
            with open(passwd_file, 'a'):
                pass

        self.orig_get_config = passwd.get_config

        passwd.delete_user(self.username)

        self.assertRaises(self.failureException, self.assertUserExists,
                          self.username)
    def setUp(self):
        passwd.get_config = mock_get_config
        passwd_file = passwd.get_config().get('auth', 'passwd_file')

        if not os.path.exists(passwd_file):
            with open(passwd_file, 'a'):
                pass

        self.orig_get_config = passwd.get_config

        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_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 tearDown(self):
     passwd_file = passwd.get_config().get('auth', 'passwd_file')
     os.unlink(passwd_file)
     passwd.get_config = self.orig_get_config
Exemplo n.º 10
0
 def tearDown(self):
     passwd_file = passwd.get_config().get('auth', 'passwd_file')
     os.unlink(passwd_file)
     passwd.get_config = self.orig_get_config