Пример #1
0
    def test_password_is_hashed(self, post, get):
        """
        A password is passed in as plaintext and is hashed before the post
        """
        post.return_value = build()
        get.return_value = build(update={'value': 'dev'})
        Settings(self.url, self.username, 'abc')

        auth_url = self.url + 'auth/'
        post.assert_called_once_with(auth_url,
                                     data={
                                         'username': self.username,
                                         'passhash': _hash_password('abc')
                                     })
Пример #2
0
    def test_update_password(self, put):
        """
        Update your own password
        """
        put.return_value = build()
        self.settings.update_password('')
        auth_url = self.url + 'auth/user/' + self.name + '/'
        put.assert_called_with(auth_url, data={'passhash': ''})

        self.settings.update_password('abc')
        abc_hash = _hash_password('abc')
        put.assert_called_with(auth_url, data={'passhash': abc_hash})

        call = lambda: self.settings.update_password('abc')
        self.failed_call_honored(call, 'requests.Session.put')
        self.logout_honored(call, self.settings)
Пример #3
0
    def test_create_user(self, post):
        """
        Create a user
        """
        post.return_value = build()
        self.settings.create_user('user2', '')
        auth_url = self.url + 'auth/user/user2/'
        post.assert_called_with(auth_url, data={'passhash': ''})

        self.settings.create_user('user2', 'abc')
        abc_hash = _hash_password('abc')
        post.assert_called_with(auth_url, data={'passhash': abc_hash})

        call = lambda: self.settings.create_user('user2', 'abc')
        self.failed_call_honored(call, 'requests.Session.post')
        self.logout_honored(call, self.settings)
Пример #4
0
 def test_hash_password(self):
     self.assertEqual('', _hash_password(''),
                      "by convention, empty strings are passed as-is")
     self.assertNotEqual('abc', _hash_password('abc'))
     self.assertNotEqual('', _hash_password('abc'))