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')
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"
def test_google_oauth_backend_generates_nonce_key(app: Flask): with app.app_context(): with app.test_request_context(): nonce = generate_nonce_key("google") assert len(nonce) == 20 assert session['_google:nonce'] == nonce
def test_gitlab_oauth_backend_does_not_generate_nonce_key(app: Flask): nonce = generate_nonce_key("gitlab") assert nonce is None