Skip to content

Commit 4785d98

Browse files
committed
Adding explicit check for binary_type in gcloud.storage.connection.api_request
1 parent 68fa37f commit 4785d98

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

gcloud/storage/connection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import json
1818

19+
import six
1920
from six.moves.urllib.parse import urlencode # pylint: disable=F0401
2021

2122
from gcloud import connection as base_connection
@@ -231,6 +232,9 @@ def api_request(self, method, path, query_params=None,
231232
if not 200 <= response.status < 300:
232233
raise make_exception(response, content)
233234

235+
if not isinstance(content, six.binary_type):
236+
raise TypeError('Expected binary type, got %s' % type(content))
237+
234238
if content and expect_json:
235239
content_type = response.get('content-type', '')
236240
if not content_type.startswith('application/json'):

gcloud/storage/test_connection.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,15 @@ def test_api_request_w_500(self):
281281
)
282282
self.assertRaises(InternalServerError, conn.api_request, 'GET', '/')
283283

284+
def test_api_request_non_binary_response(self):
285+
PROJECT = 'project'
286+
conn = self._makeOne(PROJECT)
287+
conn._http = Http(
288+
{'status': '200', 'content-type': 'application/json'},
289+
u'CONTENT',
290+
)
291+
self.assertRaises(TypeError, conn.api_request, 'GET', '/')
292+
284293

285294
class Http(object):
286295

0 commit comments

Comments
 (0)