dont use raise_for_status
use the webob abort method for http errors Change-Id: Ie56c8197cdee7b522da9d9f91e6314a5cbb30dc5
This commit is contained in:
parent
b5f3a6b2dd
commit
fe6daf5312
@ -20,6 +20,7 @@ from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_middleware import base
|
||||
from oslo_serialization import jsonutils
|
||||
from pecan.core import abort
|
||||
from six.moves import urllib
|
||||
from webob import exc
|
||||
|
||||
@ -108,7 +109,9 @@ class KeycloakAuth(base.ConfigurableMiddleware):
|
||||
else None
|
||||
resp = requests.get(endpoint, headers=headers,
|
||||
verify=verify, cert=cert)
|
||||
resp.raise_for_status()
|
||||
|
||||
if not resp.ok:
|
||||
abort(resp.status_code, resp.reason)
|
||||
|
||||
def _set_req_headers(self, req):
|
||||
req.headers['X-Identity-Status'] = 'Confirmed'
|
||||
|
@ -17,12 +17,10 @@
|
||||
# noinspection PyPackageRequirements
|
||||
from datetime import datetime
|
||||
from mock import mock
|
||||
import requests
|
||||
import requests_mock
|
||||
from webtest import TestRequest
|
||||
|
||||
from vitrage.middleware.keycloak import KeycloakAuth
|
||||
from vitrage.tests.functional.api.v1 import FunctionalTest
|
||||
from webtest import TestRequest
|
||||
|
||||
|
||||
TOKEN = {
|
||||
@ -112,13 +110,13 @@ class KeycloakTest(FunctionalTest):
|
||||
reason='Access token is invalid'
|
||||
)
|
||||
|
||||
self.assertRaises(requests.exceptions.HTTPError,
|
||||
self.post_json,
|
||||
'/topology/',
|
||||
resp = self.post_json('/topology/',
|
||||
params=None,
|
||||
headers=HEADERS,
|
||||
expect_errors=True)
|
||||
|
||||
self.assertEqual('401 Unauthorized', resp.status)
|
||||
|
||||
@mock.patch('jwt.decode', return_value=TOKEN)
|
||||
@requests_mock.Mocker()
|
||||
def test_in_keycloak_mode_auth_success(self, _, req_mock):
|
||||
|
Loading…
Reference in New Issue
Block a user