Debian Codegraph @

test/integration/targets/ansible-galaxy-collection/tasks/verify.yml

raw
1 - name: create an empty collection skeleton
2 command: ansible-galaxy collection init ansible_test.verify
3 args:
4 chdir: '{{ galaxy_dir }}/scratch'
5
6 - name: created required runtime.yml
7 copy:
8 content: 'requires_ansible: ">=1.0.0"'
9 dest: '{{ galaxy_dir }}/scratch/ansible_test/verify/meta/runtime.yml'
10
11 - name: build the collection
12 command: ansible-galaxy collection build scratch/ansible_test/verify
13 args:
14 chdir: '{{ galaxy_dir }}'
15
16 - name: publish to fallback server {{ test_api_fallback }}
17 command: ansible-galaxy collection publish ansible_test-verify-1.0.0.tar.gz -s {{ test_api_fallback }} {{ galaxy_verbosity }}
18 args:
19 chdir: '{{ galaxy_dir }}'
20
21 - name: test verifying a tarfile
22 command: ansible-galaxy collection verify {{ galaxy_dir }}/ansible_test-verify-1.0.0.tar.gz
23 register: verify
24 failed_when: verify.rc == 0
25
26 - assert:
27 that:
28 - verify.rc != 0
29 - verify.stderr is contains "'file' type is not supported. The format namespace.name is expected."
30
31 - name: install the collection from the secondary server
32 command: ansible-galaxy collection install ansible_test.verify:1.0.0 {{ galaxy_verbosity }}
33
34 # This command is hardcoded with -vvvv purposefully to evaluate extra verbosity messages
35 - name: verify the collection against the first valid server
36 command: ansible-galaxy collection verify ansible_test.verify:1.0.0 -vvvv {{ galaxy_verbosity }}
37 register: verify
38
39 - assert:
40 that:
41 - verify is success
42 - verify.stdout is search(msg)
43 vars:
44 msg: "Found API version '{{ test_api_fallback_versions }}' with Galaxy server {{ test_api_fallback }}"
45
46 - name: verify the installed collection against the server
47 command: ansible-galaxy collection verify ansible_test.verify:1.0.0 {{ galaxy_verbosity }}
48 register: verify
49
50 - assert:
51 that:
52 - verify is success
53 - "'Collection ansible_test.verify contains modified content' not in verify.stdout"
54
55 - name: verify the installed collection against the server, with unspecified version in CLI
56 command: ansible-galaxy collection verify ansible_test.verify {{ galaxy_verbosity }}
57
58 - name: verify a collection that doesn't appear to be installed
59 command: ansible-galaxy collection verify ansible_test.verify:1.0.0 {{ galaxy_verbosity }}
60 environment:
61 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/nonexistent_dir'
62 register: verify
63 failed_when: verify.rc == 0
64
65 - assert:
66 that:
67 - verify.rc != 0
68 - "'Collection ansible_test.verify is not installed in any of the collection paths.' in verify.stderr"
69
70 - name: create a modules directory
71 file:
72 state: directory
73 path: '{{ galaxy_dir }}/scratch/ansible_test/verify/plugins/modules'
74
75 - name: add a module to the collection
76 copy:
77 src: test_module.py
78 dest: '{{ galaxy_dir }}/scratch/ansible_test/verify/plugins/modules/test_module.py'
79
80 - name: update the collection version
81 lineinfile:
82 regexp: "version: .*"
83 line: "version: '2.0.0'"
84 path: '{{ galaxy_dir }}/scratch/ansible_test/verify/galaxy.yml'
85
86 - name: build the new version
87 command: ansible-galaxy collection build scratch/ansible_test/verify
88 args:
89 chdir: '{{ galaxy_dir }}'
90
91 - name: publish to primary server {{ test_name }}
92 command: ansible-galaxy collection publish ansible_test-verify-2.0.0.tar.gz -s {{ test_name }} {{ galaxy_verbosity }}
93 args:
94 chdir: '{{ galaxy_dir }}'
95
96 - name: verify a version of a collection that isn't installed
97 command: ansible-galaxy collection verify ansible_test.verify:2.0.0 {{ galaxy_verbosity }}
98 register: verify
99 failed_when: verify.rc == 0
100
101 - assert:
102 that:
103 - verify.rc != 0
104 - '"ansible_test.verify has the version ''1.0.0'' but is being compared to ''2.0.0''" in verify.stdout'
105
106 - name: install the new version from the server
107 command: ansible-galaxy collection install ansible_test.verify:2.0.0 --force {{ galaxy_verbosity }}
108
109 - name: verify the installed collection against the server
110 command: ansible-galaxy collection verify ansible_test.verify:2.0.0 {{ galaxy_verbosity }}
111 register: verify
112
113 - assert:
114 that:
115 - "'Collection ansible_test.verify contains modified content' not in verify.stdout"
116
117 # Test a modified collection
118
119 - set_fact:
120 manifest_path: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/MANIFEST.json'
121 file_manifest_path: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/FILES.json'
122 module_path: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/plugins/modules/test_module.py'
123
124 - name: load the FILES.json
125 set_fact:
126 files_manifest: "{{ lookup('file', file_manifest_path) | from_json }}"
127
128 - name: get the real checksum of a particular module
129 stat:
130 path: "{{ module_path }}"
131 checksum_algorithm: sha256
132 register: file
133
134 - assert:
135 that:
136 - "file.stat.checksum == item.chksum_sha256"
137 loop: "{{ files_manifest.files }}"
138 when: "item.name == 'plugins/modules/aws_s3.py'"
139
140 - name: append a newline to the module to modify the checksum
141 shell: "echo '' >> {{ module_path }}"
142
143 - name: get the new checksum
144 stat:
145 path: "{{ module_path }}"
146 checksum_algorithm: sha256
147 register: updated_file
148
149 - assert:
150 that:
151 - "updated_file.stat.checksum != file.stat.checksum"
152
153 - name: test verifying checksums of the modified collection
154 command: ansible-galaxy collection verify ansible_test.verify:2.0.0 {{ galaxy_verbosity }}
155 register: verify
156 failed_when: verify.rc == 0
157
158 - assert:
159 that:
160 - verify.rc != 0
161 - "'Collection ansible_test.verify contains modified content in the following files:\n plugins/modules/test_module.py' in verify.stdout"
162
163 - name: modify the FILES.json to match the new checksum
164 lineinfile:
165 path: "{{ file_manifest_path }}"
166 regexp: ' "chksum_sha256": "{{ file.stat.checksum }}",'
167 line: ' "chksum_sha256": "{{ updated_file.stat.checksum }}",'
168 state: present
169 diff: true
170
171 - name: ensure a modified FILES.json is validated
172 command: ansible-galaxy collection verify ansible_test.verify:2.0.0 {{ galaxy_verbosity }}
173 register: verify
174 failed_when: verify.rc == 0
175
176 - assert:
177 that:
178 - verify.rc != 0
179 - "'Collection ansible_test.verify contains modified content in the following files:\n FILES.json' in verify.stdout"
180
181 - name: get the checksum of the FILES.json
182 stat:
183 path: "{{ file_manifest_path }}"
184 checksum_algorithm: sha256
185 register: manifest_info
186
187 - name: modify the MANIFEST.json to contain a different checksum for FILES.json
188 lineinfile:
189 regexp: ' "chksum_sha256": *'
190 path: "{{ manifest_path }}"
191 line: ' "chksum_sha256": "{{ manifest_info.stat.checksum }}",'
192
193 - name: ensure the MANIFEST.json is validated against the uncorrupted file from the server
194 command: ansible-galaxy collection verify ansible_test.verify:2.0.0 {{ galaxy_verbosity }}
195 register: verify
196 failed_when: verify.rc == 0
197
198 - assert:
199 that:
200 - verify.rc != 0
201 - "'Collection ansible_test.verify contains modified content in the following files:\n MANIFEST.json' in verify.stdout"
202
203 - name: remove the artifact metadata to test verifying a collection without it
204 file:
205 path: "{{ item }}"
206 state: absent
207 loop:
208 - "{{ manifest_path }}"
209 - "{{ file_manifest_path }}"
210
211 - name: add some development metadata
212 copy:
213 content: |
214 namespace: 'ansible_test'
215 name: 'verify'
216 version: '2.0.0'
217 readme: 'README.md'
218 authors: ['Ansible']
219 dest: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/galaxy.yml'
220
221 - name: test we only verify collections containing a MANIFEST.json with the version on the server
222 command: ansible-galaxy collection verify ansible_test.verify:2.0.0 {{ galaxy_verbosity }}
223 register: verify
224 failed_when: verify.rc == 0
225
226 - assert:
227 that:
228 - verify.rc != 0
229 - "'Collection ansible_test.verify does not have a MANIFEST.json' in verify.stderr"
230
231 - name: update the collection version to something not present on the server
232 lineinfile:
233 regexp: "version: .*"
234 line: "version: '3.0.0'"
235 path: '{{ galaxy_dir }}/scratch/ansible_test/verify/galaxy.yml'
236
237 - name: build the new version
238 command: ansible-galaxy collection build scratch/ansible_test/verify
239 args:
240 chdir: '{{ galaxy_dir }}'
241
242 - name: force-install from local artifact
243 command: ansible-galaxy collection install '{{ galaxy_dir }}/ansible_test-verify-3.0.0.tar.gz' --force
244
245 - name: verify locally only, no download or server manifest hash check
246 command: ansible-galaxy collection verify --offline ansible_test.verify
247 register: verify
248
249 - assert:
250 that:
251 - >-
252 "Verifying 'ansible_test.verify:3.0.0'." in verify.stdout
253 - '"MANIFEST.json hash: " in verify.stdout'
254 - >-
255 "Successfully verified that checksums for 'ansible_test.verify:3.0.0' are internally consistent with its manifest." in verify.stdout
256
257 - name: append a newline to a module to modify the checksum
258 shell: "echo '' >> {{ module_path }}"
259
260 - name: create a new module file
261 file:
262 path: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/plugins/modules/test_new_file.py'
263 state: touch
264
265 - name: create a new directory
266 file:
267 path: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/plugins/modules/test_new_dir'
268 state: directory
269
270 - name: create a new ignore directory
271 file:
272 path: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/plugins/modules/__pycache__'
273 state: directory
274
275 - name: create a new ignore file
276 file:
277 path: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/plugins/modules/__pycache__/test.cpython-311.pyc'
278 state: touch
279
280 - name: verify modified collection locally-only (should fail)
281 command: ansible-galaxy collection verify --offline ansible_test.verify
282 register: verify
283 failed_when: verify.rc == 0
284
285 - assert:
286 that:
287 - verify.rc != 0
288 - "'Collection ansible_test.verify contains modified content in the following files:' in verify.stdout"
289 - "'plugins/modules/test_module.py' in verify.stdout"
290 - "'plugins/modules/test_new_file.py' in verify.stdout"
291 - "'plugins/modules/test_new_dir' in verify.stdout"
292 - "'plugins/modules/__pycache__/test.cpython-311.pyc' not in verify.stdout"
293
294 # TODO: add a test for offline Galaxy signature metadata
295
296 # These steps use secondary (amanda) as it has no signatures provided
297 - name: install a collection that was signed by setup_collections
298 command: ansible-galaxy collection install -s secondary namespace1.name1:1.0.0
299
300 - name: verify the installed collection with a detached signature
301 command: ansible-galaxy collection verify namespace1.name1:1.0.0 {{ galaxy_verbosity }} {{ signature_options }}
302 vars:
303 signature_options: "--signature {{ signature }} --keyring {{ keyring }}"
304 signature: "file://{{ gpg_homedir }}/namespace1-name1-1.0.0-MANIFEST.json.asc"
305 keyring: "{{ gpg_homedir }}/pubring.kbx"
306 register: verify
307
308 - assert:
309 that:
310 - verify.rc == 0
311
312 # This command is hardcoded with -vvvv purposefully to evaluate extra verbosity messages
313 - name: verify the installed collection with invalid detached signature
314 command: ansible-galaxy collection verify namespace1.name1:1.0.0 -vvvv {{ signature_options }}
315 vars:
316 signature_options: "--signature {{ signature }} --keyring {{ keyring }}"
317 signature: "file://{{ gpg_homedir }}/namespace1-name1-1.0.9-MANIFEST.json.asc"
318 keyring: "{{ gpg_homedir }}/pubring.kbx"
319 register: verify
320 ignore_errors: yes
321 environment:
322 ANSIBLE_NOCOLOR: True
323 ANSIBLE_FORCE_COLOR: False
324 ANSIBLE_GALAXY_REQUIRED_VALID_SIGNATURE_COUNT: all
325
326 - assert:
327 that:
328 - verify.rc != 0
329 - '"Signature verification failed for ''namespace1.name1'' (return code 1)" in verify.stdout'
330 - expected_errors[0] in verify_stdout
331 - expected_errors[1] in verify_stdout
332 vars:
333 expected_errors:
334 - "* This is the counterpart to SUCCESS and used to indicate a program failure."
335 - "* The signature with the keyid has not been verified okay."
336 # Remove formatting from the reason so it's one line
337 verify_stdout: "{{ verify.stdout | regex_replace('\"') | regex_replace('\\n') | regex_replace(' ', ' ') }}"
338
339 # This command is hardcoded with -vvvv purposefully to evaluate extra verbosity messages
340 - name: verify the installed collection with invalid detached signature offline
341 command: ansible-galaxy collection verify namespace1.name1:1.0.0 -vvvv {{ signature_options }} --offline
342 vars:
343 signature_options: "--signature {{ signature }} --keyring {{ keyring }}"
344 signature: "file://{{ gpg_homedir }}/namespace1-name1-1.0.9-MANIFEST.json.asc"
345 keyring: "{{ gpg_homedir }}/pubring.kbx"
346 register: verify
347 ignore_errors: yes
348 environment:
349 ANSIBLE_NOCOLOR: True
350 ANSIBLE_FORCE_COLOR: False
351 ANSIBLE_GALAXY_REQUIRED_VALID_SIGNATURE_COUNT: all
352
353 - assert:
354 that:
355 - verify.rc != 0
356 - '"Signature verification failed for ''namespace1.name1'' (return code 1)" in verify.stdout'
357 - expected_errors[0] in verify_stdout
358 - expected_errors[1] in verify_stdout
359 vars:
360 expected_errors:
361 - "* This is the counterpart to SUCCESS and used to indicate a program failure."
362 - "* The signature with the keyid has not been verified okay."
363 # Remove formatting from the reason so it's one line
364 verify_stdout: "{{ verify.stdout | regex_replace('\"') | regex_replace('\\n') | regex_replace(' ', ' ') }}"
365
366 - include_tasks: revoke_gpg_key.yml
367
368 # This command is hardcoded with -vvvv purposefully to evaluate extra verbosity messages
369 - name: verify the installed collection with a revoked detached signature
370 command: ansible-galaxy collection verify namespace1.name1:1.0.0 -vvvv {{ signature_options }}
371 vars:
372 signature_options: "--signature {{ signature }} --keyring {{ keyring }}"
373 signature: "file://{{ gpg_homedir }}/namespace1-name1-1.0.0-MANIFEST.json.asc"
374 keyring: "{{ gpg_homedir }}/pubring.kbx"
375 register: verify
376 ignore_errors: yes
377 environment:
378 ANSIBLE_NOCOLOR: True
379 ANSIBLE_FORCE_COLOR: False
380
381 - assert:
382 that:
383 - verify.rc != 0
384 - '"Signature verification failed for ''namespace1.name1'' (return code 0)" in verify.stdout'
385 - expected_errors[0] in verify_stdout
386 - expected_errors[1] in verify_stdout
387 vars:
388 expected_errors:
389 - "* The used key has been revoked by its owner."
390 - "* The signature with the keyid is good, but the signature was made by a revoked key."
391 # Remove formatting from the reason so it's one line
392 verify_stdout: "{{ verify.stdout | regex_replace('\"') | regex_replace('\\n') | regex_replace(' ', ' ') }}"
393
394 # This command is hardcoded with no verbosity purposefully to evaluate overall gpg failure
395 - name: verify that ignoring the signature error and no successful signatures is not successful verification
396 command: ansible-galaxy collection verify namespace1.name1:1.0.0 {{ signature_options }}
397 vars:
398 signature_options: "--signature {{ signature }} --keyring {{ keyring }}"
399 signature: "file://{{ gpg_homedir }}/namespace1-name1-1.0.0-MANIFEST.json.asc"
400 keyring: "{{ gpg_homedir }}/pubring.kbx"
401 register: verify
402 ignore_errors: yes
403 environment:
404 ANSIBLE_GALAXY_IGNORE_SIGNATURE_STATUS_CODES: REVKEYSIG,KEYREVOKED
405 ANSIBLE_NOCOLOR: True
406 ANSIBLE_FORCE_COLOR: False
407
408 - assert:
409 that:
410 - verify.rc != 0
411 - '"Signature verification failed for ''namespace1.name1'': fewer successful signatures than required" in verify.stdout'
412 - ignored_errors[0] not in verify_stdout
413 - ignored_errors[1] not in verify_stdout
414 vars:
415 ignored_errors:
416 - "* The used key has been revoked by its owner."
417 - "* The signature with the keyid is good, but the signature was made by a revoked key."
418 # Remove formatting from the reason so it's one line
419 verify_stdout: "{{ verify.stdout | regex_replace('\"') | regex_replace('\\n') | regex_replace(' ', ' ') }}"
420
421 # This command is hardcoded with -vvvv purposefully to evaluate extra verbosity messages
422 - name: verify that ignoring the signature error and no successful signatures and required signature count all is successful verification
423 command: ansible-galaxy collection verify namespace1.name1:1.0.0 -vvvv {{ signature_options }}
424 vars:
425 signature_options: "--signature {{ signature }} --keyring {{ keyring }}"
426 signature: "file://{{ gpg_homedir }}/namespace1-name1-1.0.0-MANIFEST.json.asc"
427 keyring: "{{ gpg_homedir }}/pubring.kbx"
428 register: verify
429 ignore_errors: yes
430 environment:
431 ANSIBLE_GALAXY_IGNORE_SIGNATURE_STATUS_CODES: REVKEYSIG,KEYREVOKED
432 ANSIBLE_GALAXY_REQUIRED_VALID_SIGNATURE_COUNT: all
433 ANSIBLE_NOCOLOR: True
434 ANSIBLE_FORCE_COLOR: False
435
436 - assert:
437 that:
438 - verify is success
439 - verify.rc == 0
440 - '"Signature verification failed for ''namespace1.name1'': fewer successful signatures than required" not in verify.stdout'
441 - success_messages[0] in verify_stdout
442 - success_messages[1] in verify_stdout
443 - ignored_errors[0] not in verify_stdout
444 - ignored_errors[1] not in verify_stdout
445 vars:
446 success_messages:
447 - "GnuPG signature verification succeeded, verifying contents of namespace1.name1:1.0.0"
448 - "Successfully verified that checksums for 'namespace1.name1:1.0.0' match the remote collection."
449 ignored_errors:
450 - "* The used key has been revoked by its owner."
451 - "* The signature with the keyid is good, but the signature was made by a revoked key."
452 # Remove formatting from the reason so it's one line
453 verify_stdout: "{{ verify.stdout | regex_replace('\"') | regex_replace('\\n') | regex_replace(' ', ' ') }}"
454
455 - name: use lenient signature verification (default) without providing signatures
456 command: ansible-galaxy collection verify namespace1.name1:1.0.0 -s secondary -vvvv --keyring {{ gpg_homedir }}/pubring.kbx
457 environment:
458 ANSIBLE_GALAXY_REQUIRED_VALID_SIGNATURE_COUNT: "1"
459 register: verify
460 ignore_errors: yes
461
462 - assert:
463 that:
464 - verify is success
465 - verify.rc == 0
466 - error_message not in verify.stdout
467 - success_messages[0] in verify.stdout
468 - success_messages[1] in verify.stdout
469 vars:
470 error_message: "Signature verification failed for 'namespace1.name1': fewer successful signatures than required"
471 success_messages:
472 - "GnuPG signature verification succeeded, verifying contents of namespace1.name1:1.0.0"
473 - "Successfully verified that checksums for 'namespace1.name1:1.0.0' match the remote collection."
474
475 - name: use strict signature verification without providing signatures
476 command: ansible-galaxy collection verify namespace1.name1:1.0.0 -vvvv --keyring {{ gpg_homedir }}/pubring.kbx
477 environment:
478 ANSIBLE_GALAXY_REQUIRED_VALID_SIGNATURE_COUNT: "+1"
479 register: verify
480 ignore_errors: yes
481
482 - assert:
483 that:
484 - verify is failed
485 - verify.rc == 1
486 - '"Signature verification failed for ''namespace1.name1'': no successful signatures" in verify.stdout'
487
488 - name: check ansible-galaxy verify is using folder names not collection names
489 vars:
490 wrong_namespace: notmynamespace
491 wrong_name: notmyname
492 block:
493 - name: Give namespace1.name1 an incorrect namespace dir
494 command: mv {{ galaxy_dir }}/ansible_collections/namespace1 {{ galaxy_dir }}/ansible_collections/{{ wrong_namespace }}
495
496 - name: Give namespace1.name1 an incorrect collection name dir
497 command: mv {{ galaxy_dir }}/ansible_collections/{{ wrong_namespace }}/name1 {{ galaxy_dir }}/ansible_collections/{{ wrong_namespace }}/{{ wrong_name }}
498
499 - name: Verify namespace1.name after moving the incorrect collection name
500 command: ansible-galaxy collection verify namespace1.name1 --offline
501 register: verify_metadata_name
502 ignore_errors: true
503
504 - assert:
505 that:
506 - verify_metadata_name is failed
507 - verify_metadata_name.rc != 0
508 - error_message in verify_metadata_name.stderr
509 vars:
510 error_message: Collection namespace1.name1 is not installed in any of the collection paths
511
512 - name: Verify {{ wrong_namespace }}.{{ wrong_name }} after moving the incorrect collection name
513 command: ansible-galaxy collection verify {{ wrong_namespace }}.{{ wrong_name }} --offline
514 register: verify_folder_name
515 ignore_errors: true
516
517 - assert:
518 that:
519 - verify_metadata_name is failed
520 - verify_metadata_name.rc != 0
521 - error_message in verify_folder_name.stderr
522 vars:
523 error_message: Collection at '{{ galaxy_dir }}/ansible_collections/{{ wrong_namespace }}/{{ wrong_name }}' documents incorrect FQCN 'namespace1.name1'
524
525 - name: empty installed collections
526 file:
527 path: "{{ galaxy_dir }}/ansible_collections"
528 state: "{{ item }}"
529 loop:
530 - absent
531 - directory