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
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
def test_no_scopes(): event = { 'requestContext': { 'authorizer': { 'scopes': 'read write', } } } handler = decs.scopes()(identity_handler) response = handler(event, None) assert response['body']['event'] == event
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
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