def test_password_is_invalid_check_mode(self, mocker): client = mocker.Mock() client.validate_auth_data.return_value = False changed = user.update_password(client, '/path', 'user', 'pass', True) assert changed is True client.validate_auth_data.assert_called_once_with('user', 'pass') client.put.assert_not_called()
def test_password_is_invalid_older_than_5_21_0(self, mocker): client = mocker.Mock() client.validate_auth_data.return_value = False client.version = version.StrictVersion("5.20.2") client.put.return_value = http.Response(201, '') changed = user.update_password(client, '/path', 'user', 'pass', False) assert changed is True client.validate_auth_data.assert_called_once_with('user', 'pass') client.put.assert_called_once_with('/path/password', dict( username='******', password='******', ))
def test_password_is_invalid_5_21_0_or_newer(self, mocker): client = mocker.Mock() client.validate_auth_data.return_value = False client.version = version.StrictVersion("5.21.0") client.put.return_value = http.Response(201, '') changed = user.update_password(client, '/path', 'user', 'pass', False) assert changed is True client.validate_auth_data.assert_called_once_with('user', 'pass') client.put.assert_called_once() path, payload = client.put.call_args[0] assert path == '/path/reset_password' assert payload['username'] == 'user' # (tadeboro): We cannot validate the value without mocking the bcrypt. # And I would rather see that our code gets tested by actually using # the bcrypt rather than mocking it out. This way, the message # encode/decode stuff gets put through its paces. assert 'password_hash' in payload