Commit Graph

31 Commits

Author SHA1 Message Date
Heinz-Alexander Fuetterer
8459c614fd chore: fix typos (#1740)
Changes proposed in this pull request:

 - fix some minor typos
2023-10-12 23:30:23 +02:00
Ruwann
e0550e6a90 Add test for security_map argument (#1691)
Follow-up of #1671 

Let me know if there is an easier way doing the test instead of the
current "custom" basic auth.
2023-04-22 21:42:55 +02:00
Ruwann
d9b699bf65 Add tests for strict validation in combination with api key in query (#1681)
Continues on the work of #1077 by moving the test fixtures into the
`secure_endpoint` fixture and adding a test for it in
`test_secure_api.py`.

The test will check whether an api key in the query will not lead to an
error when `strict_validation` is enabled.
2023-04-20 19:59:23 +02:00
Ruwann
5b4beeb2ea Make security pluggable (#1671)
Make security pluggable

- [x] Solution for standard security handlers: `security_deny`,
`security_passthrough`, `verify_none`
- [x] HTTP security handlers & overlap with basic from swagger 2
- [x] Do we need a separate handler for each `oauth2` flow?
2023-04-08 18:19:26 +02:00
Robbe Sneyders
ec5dd278d0 Re-add attributes to OAuthScopeProblem 2023-02-23 00:13:13 +01:00
Robbe Sneyders
65bc8b9138 Leverage Starlette TestClient for both FlaskApp and AsyncApp tests 2023-02-15 00:48:40 +01:00
Robbe Sneyders
515e324c80 Make tests framework agnostic 2023-02-13 20:01:25 +01:00
Robbe Sneyders
642a5f2dc3 Refactor tests (#1631)
This PR refactors our tests to prepare the activation of our tests for
our AsyncApp.

The separate commits are atomic, which can be useful for reviewing.

---------

Co-authored-by: Ruwann <ruwanlambrichts@gmail.com>
2023-02-12 22:25:08 +01:00
Robbe Sneyders
edb0381af3 Implement user facing interface for ConnexionMiddleware (#1621)
This PR adds an interface for the ConnexionMiddleware, similar to the
interface of the Connexion Apps.

The Connexion Apps are now a simple wrapper around the
ConnexionMiddleware and framework app, delegating the work to the
middleware. This enables a similar interface and behavior for users when
using either the middleware or apps.

The arguments are repeated everywhere there is a user interface, but are
parsed in a central place. Repeating the arguments is not DRY, but
needed to provide users with IDE autocomplete, typing, etc. They are
parsed in a single `_Options` class, which also provides a mechanism to
set default options on an App level, and override them on the more
granular API level.

This makes the long list of provided parameters a lot more manageable,
so I would like to use it for the `Jsonifier` as well, and re-add the
`debug` and `extra_files` arguments which I have dropped in previous
PRs. I'll submit a separate PR for this.

I renamed the `options` parameter to `swagger_ui_options` since it only
contains swagger UI options. This is a breaking change though, and we'll
need to highlight this upon release.

We still have quite a lot of `App`, `MiddlewareApp`, and abstract
classes. It would be great if we could find a way to reduce those
further, or at least find better naming to make it more clear what each
one does 🙂 .

Finally, I added examples on how the middleware can be used with third
party frameworks under `examples/frameworks`. Currently there's an
example for Starlette and Quart, but this should be easy to extend. They
also show how the `ASGIDecorator` and `StarletteDecorator` from my
previous PR can be used.
2023-01-26 14:40:29 +01:00
Robbe Sneyders
600ed4ed94 Format files with black 2022-06-25 23:50:52 +02:00
Robbe Sneyders
156bf79ee6 Merge V2 to main (#1518)
* Fix uri parsing for query parameter with empty brackets (#1501)

* Update tests for changed werkzeug behavior in 2.1 (#1506)

https://github.com/pallets/werkzeug/issues/2352

* Bugfix/async security check (#1512)

* Add failing tests

* Use for else construct

* openapi: remove JSON body second validation and type casting (#1170)

* openapi: remove body preprocessing

Body is already validated using jsonschema. There was also some type
casting but it was wrong: e.g. not recurring deeply into dicts and lists,
relying on existence of "type" in schema (which is not there e.g. if
oneOf is used). Anyway, the only reason why types should be casted is
converting integer values to float if the type is number. But this is in
most cases irrelevant.

Added an example, which did not work before this commit (echoed `{}`)
e.g. for
```
curl localhost:8080/api/foo -H 'content-type: application/json' -d
'{"foo": 1}'
```
but now the example works (echoes `{"foo": 1}`).

* test with oneOf in the requestBody

* remove oneof examples: superseded by tests

Co-authored-by: Pavol Vargovcik <pavol.vargovcik@kiwi.com>

Co-authored-by: Ruwann <ruwanlambrichts@gmail.com>
Co-authored-by: Pavol Vargovčík <pavol.vargovcik@gmail.com>
Co-authored-by: Pavol Vargovcik <pavol.vargovcik@kiwi.com>
2022-05-04 17:31:04 +02:00
Robbe Sneyders
4603e0679d Extract security to middleware (#1514)
* Extract security to middleware

* Add MissingMiddleware exception

* Extract add_auth_on_not_found in security middleware

* Add detail kwarg to exceptions

* Return JSONResponse in ExceptionMiddleware

* Type dicts in SecurityMiddleware

* Add trailing comma in setup.py

* Rework connexion context

* Improve error handling for missing security operation

* Refactor default security operation

* Revert "Return JSONResponse in ExceptionMiddleware"

This reverts commit c1004c7500d1be7e0938eea8672325cf15355359.

* Move routing context name into constant
2022-04-27 22:20:38 +02:00
Ruwann
85058ed3f1 Rework required_scopes checking (#1474)
* WIP: rework required_scopes checking

* Update tests for security scopes

* Add test for oauth security scheme with multiple possible scopes

* Update security tests

* Change optional auth test to correct behaviour

* Update security documentation

* Remove TODOs

* Catch possible exceptions from failed checks in async security factory

* Add .venv/ to gitignore

* Try to raise most specific exception

* Add test for raising most specific error

* Update async security handler factory

* Fix security handler error catching

* Fix imports order
2022-03-21 21:31:26 +01:00
Jyhess
8830d56841 Async security check (#869)
Co-authored-by: Jacob Floyd <cognifloyd@gmail.com>

Fixes #868

Allow to use coroutines with Aiohttp in security handlers.

- Move all function from connexion.operations.security to a class in connexion.security.SecurityHandlerFactory
- Specialize this class for AioHttp and Flask, and instantiate them in dedicated APIs
- AioHttp specialization now support coroutines
- pass_context_arg_name option is supported for security handlers
2020-07-22 06:52:16 +00:00
Michael Blättler
b14e235108 enable empty security definition
This allows to use optional authentication and provide different
responses to authenticated users via the same API-Endpoint.

Co-Authored-By: Jacob Floyd <cognifloyd@gmail.com>
2019-12-18 08:15:09 +01:00
krise3k
6ec11825b8 Add support for JWT authentication (#732)
* Add support for JWT

* Add example for JWT

* Add minimal JWT documentation
2018-11-12 08:53:50 +01:00
João Santos
44ea9336fe Connexion 2.0 (#619)
- App and Api options must be provided through the "options" argument (``old_style_options`` have been removed).
- You must specify a form content-type in 'consumes' in order to consume form data.
- The `Operation` interface has been formalized in the `AbstractOperation` class.
- The `Operation` class has been renamed to `Swagger2Operation`.
- Array parameter deserialization now follows the Swagger 2.0 spec more closely.
  In situations when a query parameter is passed multiple times, and the collectionFormat is either csv or pipes, the right-most value will be used.
  For example, `?q=1,2,3&q=4,5,6` will result in `q = [4, 5, 6]`.
  The old behavior is available by setting the collectionFormat to `multi`, or by importing `decorators.uri_parsing.AlwaysMultiURIParser` and passing `parser_class=AlwaysMultiURIParser` to your Api.
- The spec validator library has changed from `swagger-spec-validator` to `openapi-spec-validator`.
- Errors that previously raised `SwaggerValidationError` now raise the `InvalidSpecification` exception.
  All spec validation errors should be wrapped with `InvalidSpecification`.
- Support for nullable/x-nullable, readOnly and writeOnly/x-writeOnly has been added to the standard json schema validator.
- Custom validators can now be specified on api level (instead of app level).
- Added support for basic authentication and apikey authentication
- If unsupported security requirements are defined or ``x-tokenInfoFunc``/``x-tokenInfoUrl`` is missing, connexion now denies requests instead of allowing access without security-check.
- Accessing ``connexion.request.user`` / ``flask.request.user`` is no longer supported, use ``connexion.context['user']`` instead
2018-11-05 14:50:42 +01:00
Shaun Kaasten
a4cabb23ae Allow token_info response to use 'scopes' key (#565) 2018-02-08 16:30:00 +01:00
Rafael Carício
93c06711ed New style of passing options to Connexion (#436)
* Order classes by relevance in module

* Order definitions by relevance within module

* Swagger UI options extracted

* New style options

* Use new-style options

* Reuse code

* Sort imports

* Ignore typing imports

* Warn users about parameter name change

* Add back isort check

* Fix isort check
2017-04-11 16:47:21 +02:00
Rafael Carício
63abcad512 Connexion request user (#435)
* Add back connexion.request

* Refactor code to lifecycle module

* Test user from connexion.request instance
2017-04-07 16:15:09 +02:00
Rafael Carício
067ad1b55a Flask request user support (#432)
* ConnexionRequest.context proxied to flask.request instance

* Add type annotations for FlaskRequestContextProxy

* Sort imports

* Sort imports

* Remove unnecessary code
2017-04-05 19:04:48 +02:00
Henning Jacobs
d9edc36647 Ignore context args (#429)
* #428 add unit test

* #428 ignore context param if not in function args

* #428 update OAuth2 example app

* #428 update security docs
2017-04-05 14:32:40 +02:00
Rafael Carício
1858c9d4a0 Flask required only if necessary (#424)
* Example with Flask support

* Only show import error when trying to use Flask

* Re-organize imports

* Move flask_utils next to related module

* Code style

* Change back to incentivizes

* Includes Flask by default

* Project clean up

* Update Rafael Caricio's e-mail address

* Fix conflicts
2017-04-04 20:48:08 +02:00
Diogo Dutra
3952ea2771 did changes requested by isort and flake8 2017-04-04 08:20:25 -03:00
Diogo
5857dd237f Uncouple all flask functions from base code.
removed test_decorators and test_parameter (this test is useless now);
removed the request/response containers and add new request response classes;
created a abstract api class and a api flask class;
derived classes will implements the get_response/get_request methods that will convert framework req/resp types to connexion req/resp types;
moved the jsonifier from produces to flask api;
created a abstract app class and a app flask class;
changed all validators to use the ConnexionRequest instead flask request;
changed the problem function to generate a ConnexionRequest;
created a new user variables container called context (this is a property of ConnexionRequest). this will be passed as kwargs to all operations functions;
this context is used on authentication;
fixed all tests to new API;
some changes that I did may not be documented in this commit.
2017-04-04 08:20:24 -03:00
Diogo Dutra
a7af62fbf0 Uncouple flask from App and Api. Created Abstract classes for theses modules. Fixed the tests 2017-04-04 08:20:23 -03:00
Leena Bhegade
f7b3d9a0bb add parameter to decode 2017-02-08 23:48:04 +00:00
Leena Bhegade
c1020bf0f6 Fix tests 2017-02-08 21:31:35 +00:00
Rafael Caricio
654df09838 #256 🎯 identify the bug 2016-07-27 22:57:23 +02:00
Rafael Caricio
d6aac92eee Increase coverage 2016-02-25 15:41:11 +01:00
Rafael Caricio
a7aec5d53c Split tests in isolated modules 2016-02-25 14:49:19 +01:00