Merge pull request #1110 from bbc/unsafe-large-copy

Fix AnsibleUnsafeText when copying files larger than SMALL_FILE_LIMIT
pull/1113/head
Alex Willmer 2 months ago committed by GitHub
commit 289a78040d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1129,6 +1129,6 @@ class Connection(ansible.plugins.connection.ConnectionBase):
self.get_chain().call( self.get_chain().call(
ansible_mitogen.target.transfer_file, ansible_mitogen.target.transfer_file,
context=self.binding.get_child_service_context(), context=self.binding.get_child_service_context(),
in_path=in_path, in_path=ansible_mitogen.utils.unsafe.cast(in_path),
out_path=out_path out_path=ansible_mitogen.utils.unsafe.cast(out_path)
) )

@ -23,6 +23,9 @@ Unreleased
* :gh:issue:`1087` Fix :exc:`mitogen.core.StreamError` when Ansible template * :gh:issue:`1087` Fix :exc:`mitogen.core.StreamError` when Ansible template
module is called with a ``dest:`` filename that has an extension module is called with a ``dest:`` filename that has an extension
* :gh:issue:`1110` Fix :exc:`mitogen.core.StreamError` when Ansible copy
module is called with a file larger than 124 kibibytes
(:data:`ansible_mitogen.connection.Connection.SMALL_FILE_LIMIT`)
v0.3.9 (2024-08-13) v0.3.9 (2024-08-13)

@ -1,92 +1,94 @@
# Verify copy module for small and large files, and inline content. # Verify copy module for small and large files, and inline content.
# To exercise https://github.com/mitogen-hq/mitogen/pull/1110 destination
# files must have extensions and loops must use `with_items:`.
- name: integration/action/copy.yml - name: integration/action/copy.yml
hosts: test-targets hosts: test-targets
tasks: vars:
- name: Create tiny file sourced_files:
copy: - src: /tmp/copy-tiny-file
dest: /tmp/copy-tiny-file dest: /tmp/copy-tiny-file.out
content: content: this is a tiny file.
this is a tiny file. expected_checksum: f29faa9a6f19a700a941bf2aa5b281643c4ec8a0
delegate_to: localhost - src: /tmp/copy-large-file
run_once: true dest: /tmp/copy-large-file.out
content: "{{ 'x' * 200000 }}"
expected_checksum: 62951f943c41cdd326e5ce2b53a779e7916a820d
inline_files:
- dest: /tmp/copy-tiny-inline-file.out
content: tiny inline content
expected_checksum: b26dd6444595e2bdb342aa0a91721b57478b5029
- dest: /tmp/copy-large-inline-file.out
content: |
{{ 'y' * 200000 }}
expected_checksum: d675f47e467eae19e49032a2cc39118e12a6ee72
- name: Create large file files: "{{ sourced_files + inline_files }}"
tasks:
- name: Create sourced files
copy: copy:
dest: /tmp/copy-large-file dest: "{{ item.src }}"
# Must be larger than Connection.SMALL_SIZE_LIMIT. content: "{{ item.content }}"
content: "{% for x in range(200000) %}x{% endfor %}" mode: u=rw,go=r
with_items: "{{ sourced_files }}"
loop_control:
label: "{{ item.src }}"
delegate_to: localhost delegate_to: localhost
run_once: true run_once: true
- name: Cleanup copied files - name: Cleanup lingering destination files
file: file:
path: "{{ item.dest }}"
state: absent state: absent
path: "{{item}}" with_items: "{{ files }}"
with_items: loop_control:
- /tmp/copy-tiny-file.out label: "{{ item.dest }}"
- /tmp/copy-large-file.out
- /tmp/copy-tiny-inline-file.out
- /tmp/copy-large-inline-file.out
- name: Copy large file - name: Copy sourced files
copy: copy:
dest: /tmp/copy-large-file.out src: "{{ item.src }}"
src: /tmp/copy-large-file dest: "{{ item.dest }}"
mode: u=rw,go=r
- name: Copy tiny file with_items: "{{ sourced_files }}"
copy: loop_control:
dest: /tmp/copy-tiny-file.out label: "{{ item.dest }}"
src: /tmp/copy-tiny-file
- name: Copy tiny inline file - name: Copy inline files
copy: copy:
dest: /tmp/copy-tiny-inline-file.out dest: "{{ item.dest }}"
content: "tiny inline content" content: "{{ item.content }}"
mode: u=rw,go=r
- name: Copy large inline file with_items: "{{ inline_files }}"
copy: loop_control:
dest: /tmp/copy-large-inline-file.out label: "{{ item.dest }}"
content: |
{% for x in range(200000) %}y{% endfor %}
# stat results # stat results
- name: Stat copied files - name: Stat copied files
stat: stat:
path: "{{item}}" path: "{{ item.dest }}"
with_items: with_items: "{{ files }}"
- /tmp/copy-tiny-file.out loop_control:
- /tmp/copy-large-file.out label: "{{ item.dest }}"
- /tmp/copy-tiny-inline-file.out
- /tmp/copy-large-inline-file.out
register: stat register: stat
- assert: - assert:
that: that:
- stat.results[0].stat.checksum == "f29faa9a6f19a700a941bf2aa5b281643c4ec8a0" - item.stat.checksum == item.item.expected_checksum
- stat.results[1].stat.checksum == "62951f943c41cdd326e5ce2b53a779e7916a820d" quiet: true # Avoid spamming stdout with 400 kB of item.item.content
- stat.results[2].stat.checksum == "b26dd6444595e2bdb342aa0a91721b57478b5029" fail_msg: item={{ item }}
- stat.results[3].stat.checksum == "d675f47e467eae19e49032a2cc39118e12a6ee72" with_items: "{{ stat.results }}"
fail_msg: stat={{stat}} loop_control:
label: "{{ item.stat.path }}"
- name: Cleanup files - name: Cleanup destination files
file: file:
path: "{{ item.dest }}"
state: absent state: absent
path: "{{item}}" with_items: "{{ files }}"
with_items: loop_control:
- /tmp/copy-tiny-file label: "{{ item.dest }}"
- /tmp/copy-tiny-file.out
- /tmp/copy-no-mode
- /tmp/copy-no-mode.out
- /tmp/copy-with-mode
- /tmp/copy-with-mode.out
- /tmp/copy-large-file
- /tmp/copy-large-file.out
- /tmp/copy-tiny-inline-file.out
- /tmp/copy-large-inline-file
- /tmp/copy-large-inline-file.out
# end of cleaning out files (again)
tags: tags:
- copy - copy
- issue_1110

Loading…
Cancel
Save