Skip to content

Commit

Permalink
fix: print out reauth plugin error and raise if challenge output is N…
Browse files Browse the repository at this point in the history
…one (#1265)

* fix: print out reauth plugin error and raise if challenge output is None

* chore: add test

* chore: update sys test cred
  • Loading branch information
arithmetic1728 authored Mar 30, 2023
1 parent f07e441 commit 08d22fe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion google/oauth2/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def obtain_challenge_input(self, metadata):
)
else:
raise e
except pyu2f.errors.PluginError:
except pyu2f.errors.PluginError as e:
sys.stderr.write("Plugin error: {}.\n".format(e))
continue
except pyu2f.errors.NoDeviceFoundError:
sys.stderr.write("No security key found.\n")
Expand Down
2 changes: 2 additions & 0 deletions google/oauth2/reauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ def _obtain_rapt(request, access_token, requested_scopes):

msg = _run_next_challenge(msg, request, access_token)

if not msg:
raise exceptions.ReauthFailError("Failed to obtain rapt token.")
if msg["status"] == _AUTHENTICATED:
return msg["encodedProofOfReauthToken"]

Expand Down
Binary file modified system_tests/secrets.tar.enc
Binary file not shown.
14 changes: 14 additions & 0 deletions tests/oauth2/test_reauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,20 @@ def test__obtain_rapt_unsupported_status():
assert excinfo.match(r"API error: STATUS_UNSPECIFIED")


def test__obtain_rapt_no_challenge_output():
challenges_response = copy.deepcopy(CHALLENGES_RESPONSE_TEMPLATE)
with mock.patch(
"google.oauth2.reauth._get_challenges", return_value=challenges_response
):
with mock.patch("google.oauth2.reauth.is_interactive", return_value=True):
with mock.patch(
"google.oauth2.reauth._run_next_challenge", return_value=None
):
with pytest.raises(exceptions.ReauthFailError) as excinfo:
reauth._obtain_rapt(MOCK_REQUEST, "token", None)
assert excinfo.match(r"Failed to obtain rapt token")


def test__obtain_rapt_not_interactive():
with mock.patch(
"google.oauth2.reauth._get_challenges",
Expand Down

0 comments on commit 08d22fe

Please sign in to comment.