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

[core] fix isinstace str check in core rest #21341

Merged
merged 3 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Bugs Fixed

- respect text encoding specified in argument (thanks to @ryohji for the contribution) #20796
- fix type check for `data` input to `azure.core.rest` for python 2.7 users #21341

### Other Changes

Expand Down
4 changes: 2 additions & 2 deletions sdk/core/azure-core/azure/core/rest/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@
########################### HELPER SECTION #################################

def _verify_data_object(name, value):
if not isinstance(name, str):
if not isinstance(name, six.string_types):
raise TypeError(
"Invalid type for data name. Expected str, got {}: {}".format(
type(name), name
)
)
if value is not None and not isinstance(value, (str, bytes, int, float)):
if value is not None and not isinstance(value, (six.string_types, bytes, int, float)):
raise TypeError(
"Invalid type for data value. Expected primitive type, got {}: {}".format(
type(name), name
Expand Down
16 changes: 16 additions & 0 deletions sdk/core/azure-core/tests/test_rest_http_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,22 @@ def test_multipart_invalid_key_binary_string():
assert "Invalid type for data name" in str(e.value)
assert repr(b"abc") in str(e.value)

def test_data_str_input():
data = {
'scope': 'fake_scope',
u'grant_type': 'refresh_token',
'refresh_token': u'REDACTED',
'service': 'fake_url.azurecr.io'
}
request = HttpRequest("POST", "http://localhost:3000/", data=data)
assert len(request.content) == 4
assert request.content["scope"] == "fake_scope"
assert request.content["grant_type"] == "refresh_token"
assert request.content["refresh_token"] == u"REDACTED"
assert request.content["service"] == "fake_url.azurecr.io"
assert len(request.headers) == 1
assert request.headers['Content-Type'] == 'application/x-www-form-urlencoded'

@pytest.mark.parametrize(("value"), (object(), {"key": "value"}))
def test_multipart_invalid_value(value):

Expand Down