Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix error in sign_bytes #905

Merged
merged 2 commits into from Nov 1, 2021
Merged

fix: fix error in sign_bytes #905

merged 2 commits into from Nov 1, 2021

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 silvolu and a team 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Errors in sign_bytes are not clear
2 participants