-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
psrp - fix unicode handling in Python 2 #47461
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bugfixes: | ||
- psrp - Fix issue when dealing with unicode values in the output for Python 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[windows:vars] | ||
ansible_connection=psrp | ||
ansible_psrp_cert_validation=ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
# these are extra tests for psrp that aren't covered under test/integration/targets/connection/* | ||
- name: test out psrp specific tests | ||
hosts: winrm | ||
serial: 1 | ||
gather_facts: no | ||
|
||
tasks: | ||
- name: test complex objects in raw output | ||
# until PyYAML is upgraded to 4.x we need to use the \U escape for a unicode codepoint | ||
# and enclose in a quote to it translates the \U | ||
raw: " | ||
[PSCustomObject]@{string = 'string'}; | ||
[PSCustomObject]@{unicode = 'poo - \U0001F4A9'}; | ||
[PSCustomObject]@{integer = 1}; | ||
[PSCustomObject]@{list = @(1, 2)}; | ||
Get-Service -Name winrm; | ||
Write-Output -InputObject 'string - \U0001F4A9';" | ||
register: raw_out | ||
|
||
- name: assert complex objects in raw output | ||
assert: | ||
that: | ||
- raw_out.stdout_lines|count == 6 | ||
- "raw_out.stdout_lines[0] == 'string: string'" | ||
- "raw_out.stdout_lines[1] == 'unicode: poo - \U0001F4A9'" | ||
- "raw_out.stdout_lines[2] == 'integer: 1'" | ||
- "raw_out.stdout_lines[3] == \"list: [1, 2]\"" | ||
- raw_out.stdout_lines[4] == "winrm" | ||
- raw_out.stdout_lines[5] == "string - \U0001F4A9" | ||
|
||
# Become only works on Server 2008 when running with basic auth, skip this host for now as it is too complicated to | ||
# override the auth protocol in the tests. | ||
- name: check if we running on Server 2008 | ||
win_shell: '[System.Environment]::OSVersion.Version -ge [Version]"6.1"' | ||
register: os_version | ||
|
||
- name: test out become with psrp | ||
win_whoami: | ||
when: os_version|bool | ||
register: whoami_out | ||
become: yes | ||
become_method: runas | ||
become_user: SYSTEM | ||
|
||
- name: assert test out become with psrp | ||
assert: | ||
that: | ||
- whoami_out.account.sid == "S-1-5-18" | ||
when: os_version|bool | ||
|
||
- name: test out async with psrp | ||
win_shell: Start-Sleep -Seconds 2; Write-Output abc | ||
async: 5 | ||
poll: 1 | ||
register: async_out | ||
|
||
- name: assert est out async with psrp | ||
assert: | ||
that: | ||
- async_out.stdout_lines == ["abc"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If .to_string() exists, do we have to call that explicitly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Also, is this the way to check for to_string? I don't know the API so I don't know if it really creates the attribute but sets it to None or if it omits the attribute altogether.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to_string
always exists, it's just set toNone
by default https://github.com/jborean93/pypsrp/blob/master/pypsrp/complex_objects.py#L109. It will get populated if the<ToString></ToString>
element is populated on the XML being deserialized from the server. In the first case,to_string
isNone
so we need to manually build the string representation from the properties otherwise we just callstr()
which works for aGenericComplexObject
as well as any other non genericComplexObjects
.