def test_does_not_raises_exception_if_valid(self, middleware, response): request = FACTORY.create_http_request( body="{}", headers={ "X-Hub-Signature": "sha1=fc2bdea0e6a9e0dc333dece7568b5c3337a92342" }) middleware.process_resource(request, response, Mock(), {})
def test_raises_exception_if_no_signature(self, middleware, response): request = FACTORY.create_http_request() with pytest.raises(falcon.HTTPInvalidHeader) as excinfo: middleware.process_resource(request, response, Mock(), {}) exception = excinfo.value assert exception.description == ( "The value provided for the X-Hub-Signature header is invalid. " "The request's signature is missing.")
def test_raises_execption_if_invalid_hash_function(self, middleware, response): request = FACTORY.create_http_request( headers={"X-Hub-Signature": "md5=invalid"}) with pytest.raises(falcon.HTTPInvalidHeader) as excinfo: middleware.process_resource(request, response, Mock(), {}) exception = excinfo.value assert exception.description == ( "The value provided for the X-Hub-Signature header is invalid. " "The request's signature hash function is " "invalid (should be one of ['sha1']).")
def test_returns_true_if_value_is_valid(self, filter): data = {"user": {"id": 1}} request = FACTORY.create_http_request(json=data) assert filter(request)
def test_returns_false_if_value_is_absent(self, filter): data = {"user": None} request = FACTORY.create_http_request(json=data) assert not filter(request)
def test_raise_error_if_no_routes(self, handler, response): request = FACTORY.create_http_request(json={}) with pytest.raises(falcon.HTTPNotFound): handler.on_post(request, response)
def test_raise_error_if_old_request(self, middleware, response): request = FACTORY.create_http_request(headers={"Date": "Thu, 13 Sep 2018 11:48:13 GMT"}) with pytest.raises(falcon.HTTPBadRequest): middleware.process_request(request, response)
def test_does_not_raise_error_if_young_request(self, middleware, response): request = FACTORY.create_http_request(headers={"Date": "Thu, 13 Sep 2018 11:48:13 GMT"}) middleware.process_request(request, response)
def test_raises_exception_if_missing_auth_method(self, middleware, response): auth_value = b64encode(b"admin:p@ssword").decode() request = FACTORY.create_http_request(headers={"Authorization": auth_value}) with pytest.raises(falcon.HTTPForbidden): middleware.process_resource(request, response, Mock(), {})
def http_request(): data = {"topic": "step_reached"} return FACTORY.create_http_request(json=data)
def request(): return FACTORY.create_http_request(body="{}")
def test_returns_true_if_key_is_present(self, filter): data = {"user": {"id": None}} request = FACTORY.create_http_request(json=data) assert filter(request)
def test_does_not_check_auth(self, middleware, response): request = FACTORY.create_http_request(body="{}") middleware.process_resource(request, response, Mock(basic_auth=False), {})
def test_does_not_raise_execption_if_valid_credentials(self, middleware, response): auth_value = b64encode(b"admin:p@ssword").decode() request = FACTORY.create_http_request(headers={"Authorization": "Basic " + auth_value}) middleware.process_resource(request, response, Mock(), {})
def http_request(): data = {"topic": "step_reached", "botID": "507f1f77bcf86cd799439011"} return FACTORY.create_http_request(json=data)
def response(self): return FACTORY.create_http_response()
def test_raises_exception_if_missing_username_or_password(self, middleware, response): auth_value = b64encode(b"invalid_password").decode() request = FACTORY.create_http_request(headers={"Authorization": "Basic " + auth_value}) with pytest.raises(falcon.HTTPForbidden): middleware.process_resource(request, response, Mock(), {})