diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
commit | 8a754e0858d922e955e71b253c139e071ecec432 (patch) | |
tree | 527d16e74bfd1840c85efd675fdecad056c54107 /test/integration/targets/get_url/tasks/use_netrc.yml | |
parent | Initial commit. (diff) | |
download | ansible-core-8a754e0858d922e955e71b253c139e071ecec432.tar.xz ansible-core-8a754e0858d922e955e71b253c139e071ecec432.zip |
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | test/integration/targets/get_url/tasks/use_netrc.yml | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/integration/targets/get_url/tasks/use_netrc.yml b/test/integration/targets/get_url/tasks/use_netrc.yml new file mode 100644 index 0000000..e1852a8 --- /dev/null +++ b/test/integration/targets/get_url/tasks/use_netrc.yml @@ -0,0 +1,67 @@ +- name: Write out netrc + copy: + dest: "{{ remote_tmp_dir }}/netrc" + content: | + machine {{ httpbin_host }} + login foo + password bar + +- name: Test Bearer authorization is failed with netrc + get_url: + url: https://{{ httpbin_host }}/bearer + headers: + Authorization: Bearer foobar + dest: "{{ remote_tmp_dir }}/msg.txt" + ignore_errors: yes + environment: + NETRC: "{{ remote_tmp_dir }}/netrc" + +- name: Read msg.txt file + ansible.builtin.slurp: + src: "{{ remote_tmp_dir }}/msg.txt" + register: response_failed + +- name: Parse token from msg.txt + set_fact: + token: "{{ (response_failed['content'] | b64decode | from_json).token }}" + +- name: assert Test Bearer authorization is failed with netrc + assert: + that: + - "token.find('v=' ~ 'Zm9vOmJhcg') == -1" + fail_msg: "Was expecting 'foo:bar' in base64, but received: {{ response_failed['content'] | b64decode | from_json }}" + success_msg: "Expected Basic authentication even Bearer headers were sent" + +- name: Test Bearer authorization is successfull with use_netrc=False + get_url: + url: https://{{ httpbin_host }}/bearer + use_netrc: false + headers: + Authorization: Bearer foobar + dest: "{{ remote_tmp_dir }}/msg.txt" + environment: + NETRC: "{{ remote_tmp_dir }}/netrc" + +- name: Read msg.txt file + ansible.builtin.slurp: + src: "{{ remote_tmp_dir }}/msg.txt" + register: response + +- name: Parse token from msg.txt + set_fact: + token: "{{ (response['content'] | b64decode | from_json).token }}" + +- name: assert Test Bearer authorization is successfull with use_netrc=False + assert: + that: + - "token.find('v=' ~ 'foobar') == -1" + fail_msg: "Was expecting Bearer token 'foobar', but received: {{ response['content'] | b64decode | from_json }}" + success_msg: "Bearer authentication successfull without netrc" + +- name: Clean up + file: + path: "{{ item }}" + state: absent + with_items: + - "{{ remote_tmp_dir }}/netrc" + - "{{ remote_tmp_dir }}/msg.txt"
\ No newline at end of file |