Skip to content

Conversation

@arithmetic1728
Copy link
Contributor

fix #851

If AuthorizedSession.post failed, we should throw an exception instead of calling the return base64.b64decode(response.json()["signedBlob"]) line.

@arithmetic1728 arithmetic1728 requested review from a team and silvolu as code owners October 29, 2021 23:56
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 29, 2021
@busunkim96
Copy link
Contributor

self = <tests.test_impersonated_credentials.TestImpersonatedCredentials object at 0x7f3ac1d41710> def test_sign_bytes_failure(self): credentials = self.make_credentials(lifetime=None) with mock.patch( "google.auth.transport.requests.AuthorizedSession.request", autospec=True ) as auth_session: data = {"error": {"code": 403, "message": "unauthorized"}} auth_session.return_value = MockResponse(data, http_client.FORBIDDEN) with pytest.raises(exceptions.TransportError) as excinfo: credentials.sign_bytes(b"foo") > assert excinfo.match("{'error': {'code': 403, 'message': 'unauthorized'}") E AssertionError: Pattern "{'error': {'code': 403, 'message': 'unauthorized'}" not found in "Error calling sign_bytes: {'error': {'message': 'unauthorized', 'code': 403}}" 

The order seems to change sometimes - I think loading the JSON into a dict would make the comparision stable.

@arithmetic1728
Copy link
Contributor Author

self = <tests.test_impersonated_credentials.TestImpersonatedCredentials object at 0x7f3ac1d41710> def test_sign_bytes_failure(self): credentials = self.make_credentials(lifetime=None) with mock.patch( "google.auth.transport.requests.AuthorizedSession.request", autospec=True ) as auth_session: data = {"error": {"code": 403, "message": "unauthorized"}} auth_session.return_value = MockResponse(data, http_client.FORBIDDEN) with pytest.raises(exceptions.TransportError) as excinfo: credentials.sign_bytes(b"foo") > assert excinfo.match("{'error': {'code': 403, 'message': 'unauthorized'}") E AssertionError: Pattern "{'error': {'code': 403, 'message': 'unauthorized'}" not found in "Error calling sign_bytes: {'error': {'message': 'unauthorized', 'code': 403}}" 

The order seems to change sometimes - I think loading the JSON into a dict would make the comparision stable.

I updated the test to just match 'code': 403 instead of the whole "{'error': {'code': 403, 'message': 'unauthorized'}") string so I don't need to do the JSON convertion.

I also noticed that python nox cover session always includes the google-auth bundled in /google-cloud-sdk/lib/third_party/ so I also updated the coveragerc to ignore that as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

3 participants