Example #1
0
def test_failing_to_auth_if_with_unknown_provider(app: Flask):
    with app.app_context():
        signed_value = sign_value(app, {'via': 'signin'})
        path = '/auth/allowed/via/whatever?state={}'.format(signed_value)
        with app.test_request_context(path):
            with pytest.raises(exceptions.NotFound):
                authed('whatever')
Example #2
0
def test_failing_if_via_source_not_expected(app: Flask):
    with app.app_context():
        signed_value = sign_value(app, {'via': 'wherever'})
        path = '/auth/allowed/via/gitlab?state={}'.format(signed_value)
        with app.test_request_context('/auth/allowed/via/gitlab'):
            with pytest.raises(exceptions.BadRequest):
                authed('gitlab')
Example #3
0
def test_auth_redirect_to_home_on_signin(app: Flask):
    func = "chaoshubdashboard.auth.views.get_user_profile_info_from_oauth"
    with patch(func) as gp:
        profile = ProfileInfo(sub="12345", name="Jane Doe")
        gp.return_value = profile
        with patch("chaoshubdashboard.auth.views.get_account_by_subject"
                   ) as get_acc:
            account = Account.query.filter(
                Account.id == "c1337e77-ccaf-41cf-a68c-d6e2026aef21").first()
            get_acc.return_value = account
            with patch("chaoshubdashboard.auth.views.handle_signin") as hs:
                with patch("chaoshubdashboard.auth.session") as sess:
                    with app.app_context():
                        signed_value = sign_value(app, {'via': 'signin'})
                        path = '/auth/allowed/via/google?state={}&id_token={}'\
                            .format(signed_value, 'myidtoken')
                        with app.test_request_context(path):
                            nonce = generate_nonce_key("google")
                            resp = authed('google')

                            assert resp.status_code == 303
                            assert resp.location == "/"

                            hs.assert_called_with(account,
                                                  {'id_token': 'myidtoken'},
                                                  'google')
Example #4
0
def test_auth_redirect_when_missing_code_and_token(app: Flask):
    with app.app_context():
        signed_value = sign_value(app, {'via': 'signin'})
        path = '/auth/allowed/via/gitlab?state={}'.format(signed_value)
        with app.test_request_context(path):
            resp = authed('gitlab')
            assert resp.status_code == 302
            assert resp.location == "/"
Example #5
0
def test_auth_redirect_to_signup_when_account_does_not_exist(app: Flask):
    func = "chaoshubdashboard.auth.views.get_user_profile_info_from_oauth"
    with patch(func) as gp:
        profile = ProfileInfo(sub="12345", name="Jane Doe")
        gp.return_value = profile
        with patch("chaoshubdashboard.auth.views.get_account_by_subject"
                   ) as get_acc:
            get_acc.return_value = None
            with patch("chaoshubdashboard.auth.session") as sess:
                with app.app_context():
                    signed_value = sign_value(app, {'via': 'signin'})
                    path = '/auth/allowed/via/google?state={}&id_token={}'\
                        .format(signed_value, 'myidtoken')
                    with app.test_request_context(path):
                        nonce = generate_nonce_key("google")
                        resp = authed('google')

                        assert resp.status_code == 302
                        assert resp.location == "/signup"