Skip to content

Commit 08d22fe

Browse files
fix: print out reauth plugin error and raise if challenge output is None (#1265)
* fix: print out reauth plugin error and raise if challenge output is None * chore: add test * chore: update sys test cred
1 parent f07e441 commit 08d22fe

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

google/oauth2/challenges.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ def obtain_challenge_input(self, metadata):
169169
)
170170
else:
171171
raise e
172-
except pyu2f.errors.PluginError:
172+
except pyu2f.errors.PluginError as e:
173+
sys.stderr.write("Plugin error: {}.\n".format(e))
173174
continue
174175
except pyu2f.errors.NoDeviceFoundError:
175176
sys.stderr.write("No security key found.\n")

google/oauth2/reauth.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ def _obtain_rapt(request, access_token, requested_scopes):
225225

226226
msg = _run_next_challenge(msg, request, access_token)
227227

228+
if not msg:
229+
raise exceptions.ReauthFailError("Failed to obtain rapt token.")
228230
if msg["status"] == _AUTHENTICATED:
229231
return msg["encodedProofOfReauthToken"]
230232

system_tests/secrets.tar.enc

0 Bytes
Binary file not shown.

tests/oauth2/test_reauth.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,20 @@ def test__obtain_rapt_unsupported_status():
204204
assert excinfo.match(r"API error: STATUS_UNSPECIFIED")
205205

206206

207+
def test__obtain_rapt_no_challenge_output():
208+
challenges_response = copy.deepcopy(CHALLENGES_RESPONSE_TEMPLATE)
209+
with mock.patch(
210+
"google.oauth2.reauth._get_challenges", return_value=challenges_response
211+
):
212+
with mock.patch("google.oauth2.reauth.is_interactive", return_value=True):
213+
with mock.patch(
214+
"google.oauth2.reauth._run_next_challenge", return_value=None
215+
):
216+
with pytest.raises(exceptions.ReauthFailError) as excinfo:
217+
reauth._obtain_rapt(MOCK_REQUEST, "token", None)
218+
assert excinfo.match(r"Failed to obtain rapt token")
219+
220+
207221
def test__obtain_rapt_not_interactive():
208222
with mock.patch(
209223
"google.oauth2.reauth._get_challenges",

0 commit comments

Comments
 (0)