def test_tricky_debug_option_true(app):
    (sanic_app, sanic_jwt) = app

    @sanic_app.route('/another_protected')
    @sanic_jwt.protected(debug=(lambda : True))
    def another_protected(request):
        return json({'protected': True, 'is_debug': request.app.auth.config.debug()})
    (_, response) = sanic_app.test_client.post('/auth', json={'username': 'user1', 'password': 'abcxyz'})
    access_token = response.json.get(sanic_jwt.config.access_token_name(), None)
    assert (response.status == 200)
    assert (access_token is not None)
    (_, response) = sanic_app.test_client.get('/protected', headers={'Authorization': 'Bearer {}'.format(access_token)})
    assert (response.status == 200)
    (_, response) = sanic_app.test_client.get('/another_protected')
    assert (response.json.get('exception') == 'Unauthorized')
    assert (response.status == 400)
    assert ('Authorization header not present.' in response.json.get('reasons'))
    (_, response) = sanic_app.test_client.get('/another_protected', headers={'Authorization': 'Foobar {}'.format(access_token)})
    assert (response.json.get('exception') == 'Unauthorized')
    assert (response.status == 400)
    assert ('Authorization header is invalid.' in response.json.get('reasons'))
def test_tricky_debug_option_true(app):
    (sanic_app, sanic_jwt) = app

    @sanic_app.route('/another_protected')
    @sanic_jwt.protected(debug=(lambda : True))
    def another_protected(request):
        return json({'protected': True, 'is_debug': request.app.auth.config.debug()})
    (_, response) = sanic_app.test_client.post('/auth', json={'username': 'user1', 'password': 'abcxyz'})
    access_token = response.json.get(sanic_jwt.config.access_token_name(), None)
    assert (response.status == 200)
    assert (access_token is not None)
    (_, response) = sanic_app.test_client.get('/protected', headers={'Authorization': 'Bearer {}'.format(access_token)})
    assert (response.status == 200)
    (_, response) = sanic_app.test_client.get('/another_protected')
    assert (response.json.get('exception') == 'Unauthorized')
    assert (response.status == 400)
    assert ('Authorization header not present.' in response.json.get('reasons'))
    (_, response) = sanic_app.test_client.get('/another_protected', headers={'Authorization': 'Foobar {}'.format(access_token)})
    assert (response.json.get('exception') == 'Unauthorized')
    assert (response.status == 400)
    assert ('Authorization header is invalid.' in response.json.get('reasons'))