Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connexion does not validate connexion.problem responses properly #964

Closed
gasmith-nutanix opened this issue May 28, 2019 · 0 comments · Fixed by #1649
Closed

Connexion does not validate connexion.problem responses properly #964

gasmith-nutanix opened this issue May 28, 2019 · 0 comments · Fixed by #1649

Comments

@gasmith-nutanix
Copy link

Description

Connexion does not validate connexion.problem responses properly. This is a regression introduced by 9bef8c4, and first appearing in version 2.1.0.

Steps to reproduce

spec.yml:

openapi: "3.0.0"
info:
  title: Sample API
  version: "0.1"
paths:
  /:
    get:
      operationId: main.get
      responses:
        403:
          description: Forbidden
          content:
            application/problem+json:
              schema:
                type: object

main.py:

import connexion
import logging
import unittest

def get():
  return connexion.problem(403, "Forbidden", "Forbidden")

class Test(unittest.TestCase):
  def test(self):
    app = connexion.FlaskApp(
        __name__,
        specification_dir=".",
        options={ "swagger_ui": False })
    app.add_api("spec.yml", validate_responses=True)
    client = app.app.test_client()
    resp = client.get("/")
    self.assertEqual(resp.status_code, 403)

if __name__ == "__main__":
  logging.basicConfig(level=logging.INFO)
  unittest.main()

Expected behaviour

$ python main.py
.
----------------------------------------------------------------------
Ran 1 test in 0.017s

OK

Actual behaviour

$ python main.py
ERROR:connexion.decorators.validation:http://localhost/ validation error: None is not of type 'object'

Failed validating 'type' in schema:
    {'type': 'object'}

On instance:
    None
F
======================================================================
FAIL: test (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/gasmith/cx/main.py", line 21, in test
    self.assertEqual(resp.status_code, 403)
AssertionError: 500 != 403

----------------------------------------------------------------------
Ran 1 test in 0.023s

FAILED (failures=1)

Bisection

bisect.sh:

export PYTHONPATH=$(pwd)
git checkout master
git bisect start
git bisect bad
git bisect good 1.5.3
git bisect run python main.py

Bisection output:

$ ./bisect.sh
...
9bef8c46a699719f2616560fcdde7add2299d5af is the first bad commit
commit 9bef8c46a699719f2616560fcdde7add2299d5af
Author: Diogo Dutra <diogodutradamata@gmail.com>
Date:   Tue Dec 11 05:28:58 2018 -0200

    Removed duplicated calls of get_response method of the Api classes (#809)

    On Operation decorators lifecycle the api.get_response method were always called twice.
    Because the response validation, we need to cast the response to the ConnexionResponse type.
    But the response casting could be made on the response validation decorator, not always. So, changes were made to cast the response correctly.
    The BeginOfRequestLifecycleDecorator class was removed because it only do the second call of api.get_response method. This second call only occurs if the response validation is needed.
    For a more logical naming, the EndOfRequestLifecycleDecorator class was renamed to RequestResponseDecorator.
    Fixes #664

:040000 040000 e68b6742cb39d7c4bb0a0349ef8cf63e16303ef3 0b0e738c93803db751213a1b946347665998dd79 M      connexion
bisect run success

Additional info:

The same behavior is observed for both Python 2.7 and Python 3.5.

gasmith-nutanix added a commit to gasmith-nutanix/connexion that referenced this issue Oct 29, 2019
This patch addresses the issue using the same approach as the aiohttp
implementation, ensuring that the response body is properly encoded as
part of get_connexion_response().

Fixes spec-first#964
gasmith-nutanix added a commit to gasmith-nutanix/connexion that referenced this issue Oct 30, 2019
This patch addresses the issue using the same approach as the aiohttp
implementation, ensuring that the response body is properly encoded as
part of get_connexion_response().

Fixes spec-first#964
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant