Esempio n. 1
0
def test_oauth_middleware_request_auth_invalid(headers):
    auth_middleware = JwtMiddleware()
    auth_middleware._verification_key = RSA_2048_PUB_KEY

    with pytest.raises(falcon.HTTPUnauthorized):
        auth_middleware.process_resource(
            Request(create_environ(headers=headers)), None, None, None)
Esempio n. 2
0
def test_oauth_middleware_init_bad_response():
    fake_key_url = 'http://fake-url'
    responses.add(responses.GET, fake_key_url, status=404)

    auth_middleware = JwtMiddleware()
    with pytest.raises(UaaError):
        auth_middleware.initialize(fake_key_url)
Esempio n. 3
0
def test_oauth_middleware_init_bad_response():
    fake_key_url = "http://fake-url"
    responses.add(responses.GET, fake_key_url, status=404)

    auth_middleware = JwtMiddleware()
    with pytest.raises(UaaError):
        auth_middleware.initialize(fake_key_url)
Esempio n. 4
0
def test_oauth_middleware_init_fail(mock_get):
    mock_get.side_effect = requests.exceptions.ConnectionError(
        'test exception')
    auth_middleware = JwtMiddleware()

    with pytest.raises(UaaError):
        auth_middleware.initialize('http://some-fake-url')
Esempio n. 5
0
def test_oauth_middleware_init_ok():
    fake_key_url = "http://fake-url"
    responses.add(responses.GET, fake_key_url, status=200, body=json.dumps({"value": RSA_2048_PUB_KEY}))

    auth_middleware = JwtMiddleware()
    auth_middleware.initialize(fake_key_url)

    assert auth_middleware._verification_key == RSA_2048_PUB_KEY
Esempio n. 6
0
def test_oauth_middleware_init_ok():
    fake_key_url = 'http://fake-url'
    responses.add(responses.GET,
                  fake_key_url,
                  status=200,
                  body=json.dumps({'value': RSA_2048_PUB_KEY}))

    auth_middleware = JwtMiddleware()
    auth_middleware.initialize(fake_key_url)

    assert auth_middleware._verification_key == RSA_2048_PUB_KEY
Esempio n. 7
0
def test_oauth_middleware_request_auth_valid():
    auth_middleware = JwtMiddleware()
    auth_middleware._verification_key = RSA_2048_PUB_KEY
    test_req = Request(
        create_environ(headers={'Authorization': TEST_AUTH_HEADER}))
    test_resp = Response()

    auth_middleware.process_resource(test_req, test_resp, None, None)
    auth_middleware.process_request(test_req, test_resp)
    auth_middleware.process_response(test_req, test_resp, None)
Esempio n. 8
0
def test_oauth_middleware_request_auth_valid():
    auth_middleware = JwtMiddleware()
    auth_middleware._verification_key = RSA_2048_PUB_KEY
    test_req = Request(create_environ(headers={"Authorization": TEST_AUTH_HEADER}))
    test_resp = Response()

    auth_middleware.process_resource(test_req, test_resp, None, None)
    auth_middleware.process_request(test_req, test_resp)
    auth_middleware.process_response(test_req, test_resp, None)
Esempio n. 9
0
def test_oauth_middleware_request_auth_invalid(headers):
    auth_middleware = JwtMiddleware()
    auth_middleware._verification_key = RSA_2048_PUB_KEY

    with pytest.raises(falcon.HTTPUnauthorized):
        auth_middleware.process_resource(Request(create_environ(headers=headers)), None, None, None)
Esempio n. 10
0
def test_oauth_middleware_init_fail(mock_get):
    mock_get.side_effect = requests.exceptions.ConnectionError("test exception")
    auth_middleware = JwtMiddleware()

    with pytest.raises(UaaError):
        auth_middleware.initialize("http://some-fake-url")