示例#1
0
def test_auth(app, cognito_service_test_factory, token_service_test_factory,
              client, test_view):
    plugin = AWSCognitoAuthentication(
        app,
        _token_service_factory=token_service_test_factory,
        _cognito_service_factory=cognito_service_test_factory,
    )
    app.route("/")(plugin.authentication_required(test_view))
    res = client.get("/", headers={"Authorization": "Bearer good_token"})
    assert res.status_code == 200
    assert res.json == {"data": 123}
示例#2
0
def test_no_auth_bad_token(app, cognito_service_test_factory,
                           token_service_test_factory, client, test_view):
    plugin = AWSCognitoAuthentication(
        app,
        _token_service_factory=token_service_test_factory,
        _cognito_service_factory=cognito_service_test_factory,
    )
    app.route("/")(plugin.authentication_required(test_view))
    res = client.get("/", headers={"Authorization": "Bearer bad_token"})
    assert res.status_code == 401
    assert res.json == {"message": "test"}