diff options
Diffstat (limited to 'test/integration/targets/lookup_url')
4 files changed, 97 insertions, 0 deletions
diff --git a/test/integration/targets/lookup_url/aliases b/test/integration/targets/lookup_url/aliases new file mode 100644 index 0000000..ef37fce --- /dev/null +++ b/test/integration/targets/lookup_url/aliases @@ -0,0 +1,4 @@ +destructive +shippable/posix/group3 +needs/httptester +skip/macos/12.0 # This test crashes Python due to https://wefearchange.org/2018/11/forkmacos.rst.html diff --git a/test/integration/targets/lookup_url/meta/main.yml b/test/integration/targets/lookup_url/meta/main.yml new file mode 100644 index 0000000..374b5fd --- /dev/null +++ b/test/integration/targets/lookup_url/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_http_tests diff --git a/test/integration/targets/lookup_url/tasks/main.yml b/test/integration/targets/lookup_url/tasks/main.yml new file mode 100644 index 0000000..a7de506 --- /dev/null +++ b/test/integration/targets/lookup_url/tasks/main.yml @@ -0,0 +1,54 @@ +- name: Test that retrieving a url works + set_fact: + web_data: "{{ lookup('url', 'https://gist.githubusercontent.com/abadger/9858c22712f62a8effff/raw/43dd47ea691c90a5fa7827892c70241913351963/test') }}" + +- name: Assert that the url was retrieved + assert: + that: + - "'one' in web_data" + +- name: Test that retrieving a url with invalid cert fails + set_fact: + web_data: "{{ lookup('url', 'https://{{ badssl_host }}/') }}" + ignore_errors: True + register: url_invalid_cert + +- assert: + that: + - "url_invalid_cert.failed" + - "'Error validating the server' in url_invalid_cert.msg or 'Hostname mismatch' in url_invalid_cert.msg or ( url_invalid_cert.msg is search('hostname .* doesn.t match .*'))" + +- name: Test that retrieving a url with invalid cert with validate_certs=False works + set_fact: + web_data: "{{ lookup('url', 'https://{{ badssl_host }}/', validate_certs=False) }}" + register: url_no_validate_cert + +- assert: + that: + - "'{{ badssl_host_substring }}' in web_data" + +- vars: + url: https://{{ httpbin_host }}/get + block: + - name: test good cipher + debug: + msg: '{{ lookup("url", url) }}' + vars: + ansible_lookup_url_ciphers: ECDHE-RSA-AES128-SHA256 + register: good_ciphers + + - name: test bad cipher + debug: + msg: '{{ lookup("url", url) }}' + vars: + ansible_lookup_url_ciphers: ECDHE-ECDSA-AES128-SHA + ignore_errors: true + register: bad_ciphers + + - assert: + that: + - good_ciphers is successful + - bad_ciphers is failed + +- name: Test use_netrc=False + import_tasks: use_netrc.yml 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 0000000..68dc893 --- /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 |