def test_can_use_authorizer_object_with_scopes(sample_app, swagger_gen): authorizer = CustomAuthorizer('MyAuth', authorizer_uri='auth-uri', header='Authorization', invoke_role_arn='role-arn') @sample_app.route('/auth', authorizer=authorizer.with_scopes( ["write:test", "read:test"])) def auth(): return {'foo': 'bar'} doc = swagger_gen.generate_swagger(sample_app) single_method = doc['paths']['/auth']['get'] assert single_method.get('security') == [{ 'MyAuth': ["write:test", "read:test"] }] security_definitions = doc['securityDefinitions'] assert 'MyAuth' in security_definitions assert security_definitions['MyAuth'] == { 'type': 'apiKey', 'name': 'Authorization', 'in': 'header', 'x-amazon-apigateway-authtype': 'custom', 'x-amazon-apigateway-authorizer': { 'authorizerUri': 'auth-uri', 'type': 'token', 'authorizerResultTtlInSeconds': 300, 'authorizerCredentials': 'role-arn' } }
def test_can_use_api_key_and_authorizers_with_scopes(sample_app, swagger_gen): authorizer = CustomAuthorizer( 'MyAuth', authorizer_uri='auth-uri', header='Authorization') @sample_app.route( '/auth', authorizer=authorizer.with_scopes(["write:test", "read:test"]), api_key_required=True ) def auth(): return {'foo': 'bar'} doc = swagger_gen.generate_swagger(sample_app) single_method = doc['paths']['/auth']['get'] assert single_method.get('security') == [ {'api_key': []}, {'MyAuth': ["write:test", "read:test"]}, ]