Beispiel #1
0
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'
        }
    }
Beispiel #2
0
def test_can_use_authorizer_object(sample_app, swagger_gen):
    authorizer = CustomAuthorizer('MyAuth',
                                  authorizer_uri='auth-uri',
                                  header='Authorization')

    @sample_app.route('/auth', authorizer=authorizer)
    def auth():
        return {'foo': 'bar'}

    doc = swagger_gen.generate_swagger(sample_app)
    single_method = doc['paths']['/auth']['get']
    assert single_method.get('security') == [{'MyAuth': []}]
    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,
            'identityValidationExpression': '',
        }
    }
Beispiel #3
0
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"]},
    ]
Beispiel #4
0
def test_can_use_authorizer_object(sample_app, swagger_gen):
    authorizer = CustomAuthorizer(
        'MyAuth', authorizer_uri='auth-uri', header='Authorization'
    )

    @sample_app.route('/auth', authorizer=authorizer)
    def auth():
        return {'foo': 'bar'}

    doc = swagger_gen.generate_swagger(sample_app)
    single_method = doc['paths']['/auth']['get']
    assert single_method.get('security') == [{'MyAuth': []}]
    security_definitions = doc['securityDefinitions']
    assert 'MyAuth' in security_definitions
    my_auth = security_definitions['MyAuth']
    # authorizerCredentials should not be in this dict because it's None.
    assert my_auth['x-amazon-apigateway-authorizer'] == {
        'authorizerUri': 'auth-uri',
        'type': 'token',
        'authorizerResultTtlInSeconds': 300,
    }