diff options
author | Artur <40683252+Artur-at-work@users.noreply.github.com> | 2022-09-12 22:38:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-12 09:38:22 -0500 |
commit | a26c325bd8f6e2822d9d7e62f77a424c1db4fbf6 (patch) | |
tree | bba7ec2d162392670bbc3739e76781f245f3df3f /test/integration/targets/lookup_url/tasks/use_netrc.yml | |
parent | 79f67ed56116be11b1c992fade04acf06d9208d1 (diff) | |
download | ansible-a26c325bd8f6e2822d9d7e62f77a424c1db4fbf6.tar.gz |
uri: added use_netrc argument to allow ignoring netrc (#74397) (#78569)
Diffstat (limited to 'test/integration/targets/lookup_url/tasks/use_netrc.yml')
-rw-r--r-- | test/integration/targets/lookup_url/tasks/use_netrc.yml | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/integration/targets/lookup_url/tasks/use_netrc.yml b/test/integration/targets/lookup_url/tasks/use_netrc.yml new file mode 100644 index 0000000000..68dc8934ea --- /dev/null +++ b/test/integration/targets/lookup_url/tasks/use_netrc.yml @@ -0,0 +1,37 @@ +- name: Write out ~/.netrc + copy: + dest: "~/.netrc" + # writing directly to ~/.netrc because plug-in doesn't support NETRC environment overwrite + content: | + machine {{ httpbin_host }} + login foo + password bar + mode: "0600" + +- name: test Url lookup with ~/.netrc forced Basic auth + set_fact: + web_data: "{{ lookup('ansible.builtin.url', 'https://{{ httpbin_host }}/bearer', headers={'Authorization':'Bearer foobar'}) }}" + ignore_errors: yes + +- name: assert test Url lookup with ~/.netrc forced Basic auth + assert: + that: + - "web_data.token.find('v=' ~ 'Zm9vOmJhcg==') == -1" + fail_msg: "Was expecting 'foo:bar' in base64, but received: {{ web_data }}" + success_msg: "Expected Basic authentication even Bearer headers were sent" + +- name: test Url lookup with use_netrc=False + set_fact: + web_data: "{{ lookup('ansible.builtin.url', 'https://{{ httpbin_host }}/bearer', headers={'Authorization':'Bearer foobar'}, use_netrc='False') }}" + +- name: assert test Url lookup with netrc=False used Bearer authentication + assert: + that: + - "web_data.token.find('v=' ~ 'foobar') == -1" + fail_msg: "Was expecting 'foobar' Bearer token, but received: {{ web_data }}" + success_msg: "Expected to ignore ~/.netrc and authorize with Bearer token" + +- name: Clean up. Removing ~/.netrc + file: + path: ~/.netrc + state: absent
\ No newline at end of file |