コード例 #1
0
def test_scopes_type_error():
    class Uncastable():
        def __str__(self):
            raise Exception()

    with pytest.raises(TypeError) as err:
        decs.scopes('foo', Uncastable())
        assert 'castable' in err
コード例 #2
0
def test_no_scopes_in_context():
    event = {'requestContext': {'authorizer': {}}}
    handler = decs.scopes()(identity_handler)

    with pytest.raises(HTTPResponseException) as excInfo:
        handler(event, None)

    assert excInfo.value.statusCode == 500
    assert 'missing' in excInfo.value.body
コード例 #3
0
def test_no_scopes():
    event = {
        'requestContext': {
            'authorizer': {
                'scopes': 'read write',
            }
        }
    }
    handler = decs.scopes()(identity_handler)

    response = handler(event, None)
    assert response['body']['event'] == event
コード例 #4
0
def test_insufficient_scopes():
    event = {
        'requestContext': {
            'authorizer': {
                'scopes': 'read write',
            }
        }
    }
    handler = decs.scopes('read', 'write', 'admin')(identity_handler)

    with pytest.raises(HTTPResponseException) as excInfo:
        handler(event, None)

    assert excInfo.value.statusCode == 403
    assert 'insufficient' in excInfo.value.body
コード例 #5
0
def test_scopes_type_casting():
    class Castable():
        def __str__(self):
            return 'castable'

    event = {
        'requestContext': {
            'authorizer': {
                'scopes': 'castable',
            }
        }
    }
    handler = decs.scopes(Castable())(identity_handler)

    response = handler(event, None)
    assert response['body']['event'] == event