Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
Making regression3 pass#756
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
6cec5de11904c3fdb1d2373bb5bbFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -161,12 +161,12 @@ def test__make_request_no_data_no_content_type_no_headers(self): | ||
| URI = 'http://example.com/test' | ||
| http = conn._http = _Http( | ||
| {'status': '200', 'content-type': 'text/plain'}, | ||
| '', | ||
| b'', | ||
| ) | ||
| headers, content = conn._make_request('GET', URI) | ||
| self.assertEqual(headers['status'], '200') | ||
| self.assertEqual(headers['content-type'], 'text/plain') | ||
| self.assertEqual(content, '') | ||
| self.assertEqual(content, b'') | ||
| self.assertEqual(http._called_with['method'], 'GET') | ||
| self.assertEqual(http._called_with['uri'], URI) | ||
| self.assertEqual(http._called_with['body'], None) | ||
| @@ -182,7 +182,7 @@ def test__make_request_w_data_no_extra_headers(self): | ||
| URI = 'http://example.com/test' | ||
| http = conn._http = _Http( | ||
| {'status': '200', 'content-type': 'text/plain'}, | ||
| '', | ||
| b'', | ||
| ) | ||
| conn._make_request('GET', URI, {}, 'application/json') | ||
| self.assertEqual(http._called_with['method'], 'GET') | ||
| @@ -201,7 +201,7 @@ def test__make_request_w_extra_headers(self): | ||
| URI = 'http://example.com/test' | ||
| http = conn._http = _Http( | ||
| {'status': '200', 'content-type': 'text/plain'}, | ||
| '', | ||
| b'', | ||
| ) | ||
| conn._make_request('GET', URI, headers={'X-Foo': 'foo'}) | ||
| self.assertEqual(http._called_with['method'], 'GET') | ||
| @@ -226,7 +226,7 @@ def test_api_request_defaults(self): | ||
| ]) | ||
| http = conn._http = _Http( | ||
| {'status': '200', 'content-type': 'application/json'}, | ||
| '{}', | ||
| b'{}', | ||
| ) | ||
| self.assertEqual(conn.api_request('GET', PATH), {}) | ||
| self.assertEqual(http._called_with['method'], 'GET') | ||
| @@ -243,7 +243,7 @@ def test_api_request_w_non_json_response(self): | ||
| conn = self._makeMockOne() | ||
| conn._http = _Http( | ||
| {'status': '200', 'content-type': 'text/plain'}, | ||
| 'CONTENT', | ||
| b'CONTENT', | ||
| ) | ||
| self.assertRaises(TypeError, conn.api_request, 'GET', '/') | ||
| @@ -252,18 +252,18 @@ def test_api_request_wo_json_expected(self): | ||
| conn = self._makeMockOne() | ||
| conn._http = _Http( | ||
| {'status': '200', 'content-type': 'text/plain'}, | ||
| 'CONTENT', | ||
| b'CONTENT', | ||
| ) | ||
| self.assertEqual(conn.api_request('GET', '/', expect_json=False), | ||
| 'CONTENT') | ||
| b'CONTENT') | ||
| def test_api_request_w_query_params(self): | ||
| from six.moves.urllib.parse import parse_qsl | ||
| from six.moves.urllib.parse import urlsplit | ||
| conn = self._makeMockOne() | ||
| http = conn._http = _Http( | ||
| {'status': '200', 'content-type': 'application/json'}, | ||
| '{}', | ||
| b'{}', | ||
| ) | ||
| self.assertEqual(conn.api_request('GET', '/', {'foo': 'bar'}), {}) | ||
| self.assertEqual(http._called_with['method'], 'GET') | ||
| @@ -302,7 +302,7 @@ def test_api_request_w_data(self): | ||
| ]) | ||
| http = conn._http = _Http( | ||
| {'status': '200', 'content-type': 'application/json'}, | ||
| '{}', | ||
| b'{}', | ||
| ) | ||
| self.assertEqual(conn.api_request('POST', '/', data=DATA), {}) | ||
| self.assertEqual(http._called_with['method'], 'POST') | ||
| @@ -321,7 +321,7 @@ def test_api_request_w_404(self): | ||
| conn = self._makeMockOne() | ||
| conn._http = _Http( | ||
| {'status': '404', 'content-type': 'text/plain'}, | ||
| '{}' | ||
| b'{}' | ||
| ) | ||
| self.assertRaises(NotFound, conn.api_request, 'GET', '/') | ||
| @@ -330,10 +330,35 @@ def test_api_request_w_500(self): | ||
| conn = self._makeMockOne() | ||
| conn._http = _Http( | ||
| {'status': '500', 'content-type': 'text/plain'}, | ||
| '{}', | ||
| b'{}', | ||
| ) | ||
| self.assertRaises(InternalServerError, conn.api_request, 'GET', '/') | ||
| def test_api_request_non_binary_response(self): | ||
| conn = self._makeMockOne() | ||
| http = conn._http = _Http( | ||
| {'status': '200', 'content-type': 'application/json'}, | ||
| u'{}', | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| ) | ||
| result = conn.api_request('GET', '/') | ||
| # Intended to emulate self.mock_template | ||
| URI = '/'.join([ | ||
| conn.API_BASE_URL, | ||
| 'mock', | ||
| conn.API_VERSION, | ||
| '', | ||
| ]) | ||
| self.assertEqual(result, {}) | ||
| self.assertEqual(http._called_with['method'], 'GET') | ||
| self.assertEqual(http._called_with['uri'], URI) | ||
| self.assertEqual(http._called_with['body'], None) | ||
| expected_headers = { | ||
| 'Accept-Encoding': 'gzip', | ||
| 'Content-Length': 0, | ||
| 'User-Agent': conn.USER_AGENT, | ||
| } | ||
| self.assertEqual(http._called_with['headers'], expected_headers) | ||
| class _Http(object): | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -176,11 +176,13 @@ def _get_pem_key(credentials): | ||
| SIGNATURE_STRING = 'dummy_signature' | ||
| with _Monkey(MUT, RSA=rsa, PKCS1_v1_5=pkcs_v1_5, | ||
| SHA256=sha256, _get_pem_key=_get_pem_key): | ||
| self.assertRaises(NameError, self._callFUT, | ||
| self.assertRaises(UnboundLocalError, self._callFUT, | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| BAD_CREDENTIALS, EXPIRATION, SIGNATURE_STRING) | ||
| def _run_test_with_credentials(self, credentials, account_name): | ||
| def _run_test_with_credentials(self, credentials, account_name, | ||
| signature_string=None): | ||
| import base64 | ||
| import six | ||
| from gcloud._testing import _Monkey | ||
| from gcloud import credentials as MUT | ||
| @@ -190,7 +192,7 @@ def _run_test_with_credentials(self, credentials, account_name): | ||
| sha256 = _SHA256() | ||
| EXPIRATION = '100' | ||
| SIGNATURE_STRING = b'dummy_signature' | ||
| SIGNATURE_STRING = signature_string or b'dummy_signature' | ||
| with _Monkey(MUT, crypt=crypt, RSA=rsa, PKCS1_v1_5=pkcs_v1_5, | ||
| SHA256=sha256): | ||
| result = self._callFUT(credentials, EXPIRATION, SIGNATURE_STRING) | ||
| @@ -199,7 +201,12 @@ def _run_test_with_credentials(self, credentials, account_name): | ||
| self.assertEqual(crypt._private_key_text, | ||
| base64.b64encode(b'dummy_private_key_text')) | ||
| self.assertEqual(crypt._private_key_password, 'notasecret') | ||
| self.assertEqual(sha256._signature_string, SIGNATURE_STRING) | ||
| # sha256._signature_string is always bytes. | ||
| if isinstance(SIGNATURE_STRING, six.binary_type): | ||
| self.assertEqual(sha256._signature_string, SIGNATURE_STRING) | ||
| else: | ||
| self.assertEqual(sha256._signature_string, | ||
| SIGNATURE_STRING.encode('utf-8')) | ||
| SIGNED = base64.b64encode(b'DEADBEEF') | ||
| expected_query = { | ||
| 'Expires': EXPIRATION, | ||
| @@ -217,6 +224,17 @@ def test_signed_jwt_for_p12(self): | ||
| ACCOUNT_NAME, b'dummy_private_key_text', scopes) | ||
| self._run_test_with_credentials(credentials, ACCOUNT_NAME) | ||
| def test_signature_non_bytes(self): | ||
| from oauth2client import client | ||
| scopes = [] | ||
| ACCOUNT_NAME = 'dummy_service_account_name' | ||
| SIGNATURE_STRING = u'dummy_signature' | ||
| credentials = client.SignedJwtAssertionCredentials( | ||
| ACCOUNT_NAME, b'dummy_private_key_text', scopes) | ||
| self._run_test_with_credentials(credentials, ACCOUNT_NAME, | ||
| signature_string=SIGNATURE_STRING) | ||
| def test_service_account_via_json_key(self): | ||
| from oauth2client import service_account | ||
| from gcloud._testing import _Monkey | ||
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.