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

unicode type check #3211

Merged
merged 7 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion azurelinuxagent/ga/exthandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2305,9 +2305,11 @@ def _parse_boolean_value(value, default_val):
"""
Expects boolean value but
for backward compatibility, 'true' (case-insensitive) is accepted, and other values default to False
Note: Json module returns unicode on py2. In py3, unicode removed
ustr is a unicode object for Py2 and a str object for Py3.
"""
if not isinstance(value, bool):
return True if isinstance(value, str) and value.lower() == "true" else default_val
return True if isinstance(value, ustr) and value.lower() == "true" else default_val
return value


Expand Down
19 changes: 18 additions & 1 deletion tests/ga/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -3477,7 +3477,7 @@ def test_handler_manifest_defaults(self):
self.assertFalse(manifest.is_report_heartbeat())
self.assertFalse(manifest.supports_multiple_extensions())

def test_handler_manifest_boolen_fields(self):
def test_handler_manifest_boolean_fields(self):
# Set the boolean fields to strings
handler_json = {
"installCommand": "install_cmd",
Expand Down Expand Up @@ -3527,6 +3527,23 @@ def test_handler_manifest_boolen_fields(self):
self.assertFalse(manifest.is_report_heartbeat())
self.assertFalse(manifest.supports_multiple_extensions())

def test_unicode_values_for_boolean_fields_in_handler_manifest(self):
handler_json = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do this test loading the json from a file, which is what exposed the problem

Other similar tests should probably also be modified

"installCommand": "install_cmd",
"uninstallCommand": "uninstall_cmd",
"updateCommand": "update_cmd",
"enableCommand": "enable_cmd",
"disableCommand": "disable_cmd",
"reportHeartbeat": u"true",
"continueOnUpdateFailure": u"true",
"supportsMultipleExtensions": u"true"
}

manifest = HandlerManifest({'handlerManifest': handler_json})
self.assertTrue(manifest.is_continue_on_update_failure())
self.assertTrue(manifest.is_report_heartbeat())
self.assertTrue(manifest.supports_multiple_extensions())

def test_report_msg_if_handler_manifest_contains_invalid_values(self):
# Set the boolean fields to invalid values
handler_json = {
Expand Down
Loading