Debian Codegraph @

test/integration/targets/connection_psrp/tests.yml

raw
1 ---
2 # these are extra tests for psrp that aren't covered under test/integration/targets/connection/*
3 - name: test out psrp specific tests
4 hosts: windows
5 serial: 1
6 gather_facts: no
7
8 tasks:
9 - name: reboot the host
10 ansible.windows.win_reboot:
11
12 - name: test complex objects in raw output
13 # until PyYAML is upgraded to 4.x we need to use the \U escape for a unicode codepoint
14 # and enclose in a quote to it translates the \U
15 raw: "
16 [PSCustomObject]@{string = 'string'};
17 [PSCustomObject]@{unicode = 'poo - \U0001F4A9'};
18 [PSCustomObject]@{integer = 1};
19 [PSCustomObject]@{list = @(1, 2)};
20 Get-Service -Name winrm;
21 Write-Output -InputObject 'string - \U0001F4A9';"
22 register: raw_out
23
24 - name: assert complex objects in raw output
25 assert:
26 that:
27 - raw_out.stdout_lines|count == 6
28 - "raw_out.stdout_lines[0] == 'string: string'"
29 - "raw_out.stdout_lines[1] == 'unicode: poo - \U0001F4A9'"
30 - "raw_out.stdout_lines[2] == 'integer: 1'"
31 - "raw_out.stdout_lines[3] == \"list: [1, 2]\""
32 - raw_out.stdout_lines[4] == "winrm"
33 - raw_out.stdout_lines[5] == "string - \U0001F4A9"
34
35 - name: test error record stderr
36 raw: |
37 Write-Error -Message error1 -ErrorId MyId1
38
39 $exp = [ArgumentException]::new("error exception")
40 Write-Error -Exception $exp -Message 'error details' -ErrorId MyId2
41 register: raw_err
42
43 - name: assert error record stderr
44 assert:
45 that:
46 - raw_err.stdout == ""
47 - >-
48 "error1\r\n + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException\r\n + FullyQualifiedErrorId : MyId1" in raw_err.stderr
49 - >-
50 "error details\r\n + CategoryInfo : NotSpecified: (:) [Write-Error], ArgumentException\r\n + FullyQualifiedErrorId : MyId2" in raw_err.stderr
51
52 - name: test subprocess stderr and rc
53 raw: powershell.exe -command '$host.UI.WriteErrorLine(''stderr 1''); $host.UI.WriteErrorLine(''stderr 2''); $host.UI.WriteErrorLine(''stderr 3''); exit 2'
54 register: raw_stderr
55 failed_when: raw_stderr.rc != 2
56
57 - name: assert test subprocess stderr and rc
58 assert:
59 that:
60 - raw_stderr.stdout == ""
61 - raw_stderr.stderr == "stderr 1\r\nstderr 2\r\nstderr 3\r\n"
62
63 - name: test out become with psrp
64 win_whoami:
65 register: whoami_out
66 become: yes
67 become_method: runas
68 become_user: SYSTEM
69
70 - name: assert test out become with psrp
71 assert:
72 that:
73 - whoami_out.account.sid == "S-1-5-18"
74
75 - name: test out async with psrp
76 win_shell: Start-Sleep -Seconds 2; Write-Output abc
77 async: 10
78 poll: 1
79 register: async_out
80
81 - name: assert est out async with psrp
82 assert:
83 that:
84 - async_out.stdout_lines == ["abc"]
85
86 - name: Output unicode characters from Powershell using PSRP
87 win_command: "powershell.exe -ExecutionPolicy ByPass -Command \"Write-Host '\U0001F4A9'\""
88 register: command_unicode_output
89
90 - name: Assert unicode output
91 assert:
92 that:
93 - command_unicode_output is changed
94 - command_unicode_output.rc == 0
95 - "command_unicode_output.stdout == '\U0001F4A9\n'"
96 - command_unicode_output.stderr == ''
97
98 - name: Output unicode characters from Powershell using PSRP
99 win_shell: "Write-Host '\U0001F4A9'"
100 register: shell_unicode_output
101
102 - name: Assert unicode output
103 assert:
104 that:
105 - shell_unicode_output is changed
106 - shell_unicode_output.rc == 0
107 - "shell_unicode_output.stdout == '\U0001F4A9\n'"
108 - shell_unicode_output.stderr == ''
109
110 - name: copy empty file
111 win_copy:
112 src: empty.txt
113 dest: C:\Windows\TEMP\empty.txt
114 register: copy_empty
115
116 - name: get result of copy empty file
117 win_stat:
118 path: C:\Windows\TEMP\empty.txt
119 get_checksum: yes
120 register: copy_empty_actual
121
122 - name: assert copy empty file
123 assert:
124 that:
125 - copy_empty.checksum == 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
126 - copy_empty_actual.stat.checksum == 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
127 - copy_empty_actual.stat.size == 0
128
129 - block:
130 - name: fetch empty file
131 fetch:
132 src: C:\Windows\TEMP\empty.txt
133 dest: /tmp/empty.txt
134 flat: yes
135 register: fetch_empty
136
137 - name: get result of fetch empty file
138 stat:
139 path: /tmp/empty.txt
140 get_checksum: yes
141 register: fetch_empty_actual
142 delegate_to: localhost
143
144 - name: assert fetch empty file
145 assert:
146 that:
147 - fetch_empty.checksum == 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
148 - fetch_empty_actual.stat.checksum == 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
149 - fetch_empty_actual.stat.size == 0
150
151 always:
152 - name: remove tmp file
153 file:
154 path: /tmp/empty.txt
155 state: absent
156 delegate_to: localhost
157
158 - name: Test PSRP HTTP connection
159 win_ping:
160 vars:
161 ansible_port: 5985
162 ansible_psrp_protocol: http
163
164 - name: Test PSRP HTTPS connection
165 win_ping:
166 vars:
167 ansible_port: 5986
168 ansible_psrp_protocol: https
169 ansible_psrp_cert_validation: ignore