diff --git a/test/integration/targets/prepare_http_tests/tasks/main.yml b/test/integration/targets/prepare_http_tests/tasks/main.yml index 398c7b29f2c..3a270d40010 100644 --- a/test/integration/targets/prepare_http_tests/tasks/main.yml +++ b/test/integration/targets/prepare_http_tests/tasks/main.yml @@ -46,7 +46,7 @@ - name: Windows - Get client cert/key win_get_url: url: http://ansible.http.tests/{{ item }} - dest: '{{ win_output_dir }}\{{ item }}' + dest: '{{ remote_tmp_dir }}\{{ item }}' register: win_download # Server 2008 R2 is slightly slower, we attempt 5 retries retries: 5 @@ -71,7 +71,7 @@ - name: Windows - Retrieve test cacert win_get_url: url: http://ansible.http.tests/cacert.pem - dest: '{{ win_output_dir }}\cacert.pem' + dest: '{{ remote_tmp_dir }}\cacert.pem' when: ansible_os_family == 'Windows' - name: Redhat - Update ca trust @@ -84,7 +84,7 @@ - name: Windows - Update ca trust win_certificate_store: - path: '{{ win_output_dir }}\cacert.pem' + path: '{{ remote_tmp_dir }}\cacert.pem' state: present store_location: LocalMachine store_name: Root diff --git a/test/integration/targets/win_uri/defaults/main.yml b/test/integration/targets/win_uri/defaults/main.yml deleted file mode 100644 index e5ca7935c1d..00000000000 --- a/test/integration/targets/win_uri/defaults/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -test_uri_path: '{{ win_output_dir }}\win_uri' diff --git a/test/integration/targets/win_uri/meta/main.yml b/test/integration/targets/win_uri/meta/main.yml index e0a6795056e..8b53e81a078 100644 --- a/test/integration/targets/win_uri/meta/main.yml +++ b/test/integration/targets/win_uri/meta/main.yml @@ -1,3 +1,2 @@ dependencies: -- prepare_win_tests - prepare_http_tests diff --git a/test/integration/targets/win_uri/tasks/main.yml b/test/integration/targets/win_uri/tasks/main.yml index 7105f5aa477..ca6e4a41b4d 100644 --- a/test/integration/targets/win_uri/tasks/main.yml +++ b/test/integration/targets/win_uri/tasks/main.yml @@ -1,14 +1,431 @@ --- -- name: create test directory - win_file: - path: '{{test_uri_path}}' - state: directory - -- block: - - include_tasks: test.yml - - always: - - name: cleanup test directory - win_file: - path: '{{test_uri_path}}' - state: absent +# get with mismatch https +# get with mismatch https and ignore validation + +- name: get request without return_content + win_uri: + url: https://{{httpbin_host}}/get + return_content: no + register: get_request_without_content + +- name: assert get request without return_content + assert: + that: + - not get_request_without_content.changed + - get_request_without_content.content is not defined + - get_request_without_content.json is not defined + - get_request_without_content.status_code == 200 + +- name: get request with xml content + win_uri: + url: https://{{httpbin_host}}/xml + return_content: yes + register: get_request_with_xml_content + +- name: assert get request with xml content + assert: + that: + - not get_request_with_xml_content.changed + - get_request_with_xml_content.content is defined + - get_request_with_xml_content.json is not defined + - get_request_with_xml_content.status_code == 200 + +- name: get request with binary content + win_uri: + url: https://{{httpbin_host}}/image/png + return_content: yes + register: get_request_with_binary_content + +- name: assert get request with binary content + assert: + that: + - not get_request_with_binary_content.changed + - get_request_with_binary_content.content is defined + - get_request_with_binary_content.json is not defined + - get_request_with_xml_content.status_code == 200 + +- name: get request with return_content and dest (check mode) + win_uri: + url: https://{{httpbin_host}}/get + return_content: yes + dest: '{{ remote_tmp_dir }}\get.json' + register: get_request_with_dest_check + check_mode: yes + +- name: get stat of downloaded file (check mode) + win_stat: + path: '{{ remote_tmp_dir }}\get.json' + register: get_request_with_dest_actual_check + +- name: assert get request with return_content and dest (check mode) + assert: + that: + - get_request_with_dest_check.changed + - get_request_with_dest_check.content is defined + - get_request_with_dest_check.json is defined + - get_request_with_dest_actual_check.stat.exists == False + +- name: get request with return_content and dest + win_uri: + url: https://{{httpbin_host}}/get + return_content: yes + dest: '{{ remote_tmp_dir }}\get.json' + register: get_request_with_dest + +- name: get stat of downloaded file + win_stat: + path: '{{ remote_tmp_dir }}\get.json' + checksum_algorithm: sha1 + get_checksum: yes + register: get_request_with_dest_actual + +- name: assert get request with return_content and dest + assert: + that: + - get_request_with_dest.changed + - get_request_with_dest.content is defined + - get_request_with_dest.json is defined + - get_request_with_dest_actual.stat.exists == True + - get_request_with_dest_actual.stat.checksum == get_request_with_dest.content|hash('sha1') + +- name: get request with return_content and dest (idempotent) + win_uri: + url: https://{{httpbin_host}}/get + return_content: yes + dest: '{{ remote_tmp_dir }}\get.json' + register: get_request_with_dest_again + +- name: assert get request with return_content and dest (idempotent) + assert: + that: + - not get_request_with_dest_again.changed + +- name: test request with creates option should skip + win_uri: + url: https://{{httpbin_host}}/get + creates: '{{ remote_tmp_dir }}\get.json' + register: request_with_creates_skipped + +- name: assert test request with creates option should skip + assert: + that: + - not request_with_creates_skipped.changed + - request_with_creates_skipped.skipped + +- name: test request with creates option should not skip + win_uri: + url: https://{{httpbin_host}}/get + creates: '{{ remote_tmp_dir }}\fake.json' + register: request_with_creates_not_skipped + +- name: assert test request with creates option should not skip + assert: + that: + - not request_with_creates_not_skipped.changed + - request_with_creates_not_skipped.skipped is not defined + +- name: post request with return_content, dest and different content + win_uri: + url: https://{{httpbin_host}}/post + method: POST + content_type: application/json + body: '{"foo": "bar"}' + return_content: yes + dest: '{{ remote_tmp_dir }}\get.json' + register: post_request_with_different_content + +- name: get stat of downloaded file + win_stat: + path: '{{ remote_tmp_dir }}\get.json' + checksum_algorithm: sha1 + get_checksum: yes + register: post_request_with_different_content_actual + +- name: assert post request with return_content, dest and different content + assert: + that: + - post_request_with_different_content.changed + - post_request_with_different_content_actual.stat.exists == True + - post_request_with_different_content_actual.stat.checksum == post_request_with_different_content.content|hash('sha1') + +- name: test redirect without follow_redirects + win_uri: + url: https://{{httpbin_host}}/redirect/2 + follow_redirects: none + status_code: 302 + register: redirect_without_follow + +- name: assert redirect without follow_redirects + assert: + that: + - not redirect_without_follow.changed + - redirect_without_follow.location|default("") == '/relative-redirect/1' + - redirect_without_follow.status_code == 302 + +- name: test redirect with follow_redirects + win_uri: + url: https://{{httpbin_host}}/redirect/2 + follow_redirects: all + register: redirect_with_follow + +- name: assert redirect with follow_redirects + assert: + that: + - not redirect_with_follow.changed + - redirect_with_follow.location is not defined + - redirect_with_follow.status_code == 200 + - redirect_with_follow.response_uri == 'https://{{httpbin_host}}/get' + +- name: get request with redirect of TLS + win_uri: + url: https://{{httpbin_host}}/redirect/2 + follow_redirects: all + register: redirect_with_follow_tls + +- name: assert redirect with redirect of TLS + assert: + that: + - not redirect_with_follow_tls.changed + - redirect_with_follow_tls.location is not defined + - redirect_with_follow_tls.status_code == 200 + - redirect_with_follow_tls.response_uri == 'https://{{httpbin_host}}/get' + +- name: test basic auth + win_uri: + url: https://{{httpbin_host}}/basic-auth/user/passwd + user: user + password: passwd + register: basic_auth + +- name: assert test basic auth + assert: + that: + - not basic_auth.changed + - basic_auth.status_code == 200 + +- name: test basic auth with force auth + win_uri: + url: https://{{httpbin_host}}/hidden-basic-auth/user/passwd + user: user + password: passwd + force_basic_auth: yes + register: basic_auth_forced + +- name: assert test basic auth with forced auth + assert: + that: + - not basic_auth_forced.changed + - basic_auth_forced.status_code == 200 + +- name: test PUT + win_uri: + url: https://{{httpbin_host}}/put + method: PUT + body: foo=bar + return_content: yes + register: put_request + +- name: assert test PUT + assert: + that: + - not put_request.changed + - put_request.status_code == 200 + - put_request.json.data == 'foo=bar' + +- name: test OPTIONS + win_uri: + url: https://{{httpbin_host}}/ + method: OPTIONS + register: option_request + +- name: assert test OPTIONS + assert: + that: + - not option_request.changed + - option_request.status_code == 200 + - 'option_request.allow.split(", ")|sort == ["GET", "HEAD", "OPTIONS"]' + +# SNI Tests + +- name: validate status_codes are correct + win_uri: + url: https://{{httpbin_host}}/status/202 + status_code: + - 202 + - 418 + method: POST + body: foo + register: status_code_check + +- name: assert validate status_codes are correct + assert: + that: + - not status_code_check.changed + - status_code_check.status_code == 202 + +- name: send JSON body with dict type + win_uri: + url: https://{{httpbin_host}}/post + method: POST + body: + foo: bar + list: + - 1 + - 2 + dict: + foo: bar + headers: + 'Content-Type': 'text/json' + return_content: yes + register: json_as_dict + +- name: set fact of expected json dict + set_fact: + json_as_dict_value: + foo: bar + list: + - 1 + - 2 + dict: + foo: bar + +- name: assert send JSON body with dict type + assert: + that: + - not json_as_dict.changed + - json_as_dict.json.json == json_as_dict_value + - json_as_dict.status_code == 200 + +- name: send JSON body with 1 item in list + win_uri: + url: https://{{httpbin_host}}/post + method: POST + body: + - foo: bar + headers: + 'Content-Type': 'text/json' + return_content: yes + register: json_as_oneitemlist + +- name: set fact of expected json 1 item list + set_fact: + json_as_oneitemlist_value: + - foo: bar + +- name: assert send JSON body with 1 item in list + assert: + that: + - not json_as_oneitemlist.changed + - json_as_oneitemlist.json.json == json_as_oneitemlist_value + - json_as_oneitemlist.status_code == 200 + +- name: get request with custom headers + win_uri: + url: https://{{httpbin_host}}/get + headers: + Test-Header: hello + Another-Header: world + return_content: yes + register: get_custom_header + +- name: assert request with custom headers + assert: + that: + - not get_custom_header.changed + - get_custom_header.status_code == 200 + - get_custom_header.json.headers['Test-Header'] == 'hello' + - get_custom_header.json.headers['Another-Header'] == 'world' + +- name: Validate invalid method + win_uri: + url: https://{{ httpbin_host }}/anything + method: UNKNOWN + register: invalid_method + ignore_errors: yes + +- name: Assert invalid method fails + assert: + that: + - invalid_method is failure + - invalid_method.status_code == 405 + - invalid_method.status_description == 'METHOD NOT ALLOWED' + +# client cert auth tests + +- name: get request with timeout + win_uri: + url: https://{{httpbin_host}}/delay/10 + timeout: 5 + register: get_with_timeout_fail + failed_when: '"The operation has timed out" not in get_with_timeout_fail.msg' + +- name: connect to fakepath that does not exist + win_uri: + url: https://{{httpbin_host}}/fakepath + status_code: 404 + return_content: yes + register: invalid_path + +# verifies the return values are still set on a non 200 response +- name: assert connect to fakepath that does not exist + assert: + that: + - not invalid_path.changed + - invalid_path.status_code == 404 + - invalid_path.status_description == 'NOT FOUND' + - invalid_path.content is defined + - invalid_path.method == 'GET' + - invalid_path.connection is defined + +- name: post request with custom headers + win_uri: + url: https://{{httpbin_host}}/post + method: POST + headers: + Test-Header: hello + Another-Header: world + content_type: application/json + body: '{"foo": "bar"}' + return_content: yes + register: post_request_with_custom_headers + +- name: assert post with custom headers + assert: + that: + - not post_request_with_custom_headers.changed + - post_request_with_custom_headers.status_code == 200 + - post_request_with_custom_headers.json.headers['Content-Type'] == "application/json" + - post_request_with_custom_headers.json.headers['Test-Header'] == 'hello' + - post_request_with_custom_headers.json.headers['Another-Header'] == 'world' + +- name: validate status codes as list of strings + win_uri: + url: https://{{httpbin_host}}/status/202 + status_code: + - '202' + - '418' + method: POST + body: foo + return_content: yes + register: request_status_code_string + +- name: assert status codes as list of strings + assert: + that: + - not request_status_code_string.changed + - request_status_code_string.status_code == 202 + +- name: validate status codes as comma separated list + win_uri: + url: https://{{httpbin_host}}/status/202 + status_code: 202, 418 + method: POST + body: foo + return_content: yes + register: request_status_code_comma + +- name: assert status codes as comma separated list + assert: + that: + - not request_status_code_comma.changed + - request_status_code_comma.status_code == 202 diff --git a/test/integration/targets/win_uri/tasks/test.yml b/test/integration/targets/win_uri/tasks/test.yml deleted file mode 100644 index a23220b0f44..00000000000 --- a/test/integration/targets/win_uri/tasks/test.yml +++ /dev/null @@ -1,431 +0,0 @@ ---- -# get with mismatch https -# get with mismatch https and ignore validation - -- name: get request without return_content - win_uri: - url: https://{{httpbin_host}}/get - return_content: no - register: get_request_without_content - -- name: assert get request without return_content - assert: - that: - - not get_request_without_content.changed - - get_request_without_content.content is not defined - - get_request_without_content.json is not defined - - get_request_without_content.status_code == 200 - -- name: get request with xml content - win_uri: - url: https://{{httpbin_host}}/xml - return_content: yes - register: get_request_with_xml_content - -- name: assert get request with xml content - assert: - that: - - not get_request_with_xml_content.changed - - get_request_with_xml_content.content is defined - - get_request_with_xml_content.json is not defined - - get_request_with_xml_content.status_code == 200 - -- name: get request with binary content - win_uri: - url: https://{{httpbin_host}}/image/png - return_content: yes - register: get_request_with_binary_content - -- name: assert get request with binary content - assert: - that: - - not get_request_with_binary_content.changed - - get_request_with_binary_content.content is defined - - get_request_with_binary_content.json is not defined - - get_request_with_xml_content.status_code == 200 - -- name: get request with return_content and dest (check mode) - win_uri: - url: https://{{httpbin_host}}/get - return_content: yes - dest: '{{test_uri_path}}\get.json' - register: get_request_with_dest_check - check_mode: yes - -- name: get stat of downloaded file (check mode) - win_stat: - path: '{{test_uri_path}}\get.json' - register: get_request_with_dest_actual_check - -- name: assert get request with return_content and dest (check mode) - assert: - that: - - get_request_with_dest_check.changed - - get_request_with_dest_check.content is defined - - get_request_with_dest_check.json is defined - - get_request_with_dest_actual_check.stat.exists == False - -- name: get request with return_content and dest - win_uri: - url: https://{{httpbin_host}}/get - return_content: yes - dest: '{{test_uri_path}}\get.json' - register: get_request_with_dest - -- name: get stat of downloaded file - win_stat: - path: '{{test_uri_path}}\get.json' - checksum_algorithm: sha1 - get_checksum: yes - register: get_request_with_dest_actual - -- name: assert get request with return_content and dest - assert: - that: - - get_request_with_dest.changed - - get_request_with_dest.content is defined - - get_request_with_dest.json is defined - - get_request_with_dest_actual.stat.exists == True - - get_request_with_dest_actual.stat.checksum == get_request_with_dest.content|hash('sha1') - -- name: get request with return_content and dest (idempotent) - win_uri: - url: https://{{httpbin_host}}/get - return_content: yes - dest: '{{test_uri_path}}\get.json' - register: get_request_with_dest_again - -- name: assert get request with return_content and dest (idempotent) - assert: - that: - - not get_request_with_dest_again.changed - -- name: test request with creates option should skip - win_uri: - url: https://{{httpbin_host}}/get - creates: '{{test_uri_path}}\get.json' - register: request_with_creates_skipped - -- name: assert test request with creates option should skip - assert: - that: - - not request_with_creates_skipped.changed - - request_with_creates_skipped.skipped - -- name: test request with creates option should not skip - win_uri: - url: https://{{httpbin_host}}/get - creates: '{{test_uri_path}}\fake.json' - register: request_with_creates_not_skipped - -- name: assert test request with creates option should not skip - assert: - that: - - not request_with_creates_not_skipped.changed - - request_with_creates_not_skipped.skipped is not defined - -- name: post request with return_content, dest and different content - win_uri: - url: https://{{httpbin_host}}/post - method: POST - content_type: application/json - body: '{"foo": "bar"}' - return_content: yes - dest: '{{test_uri_path}}\get.json' - register: post_request_with_different_content - -- name: get stat of downloaded file - win_stat: - path: '{{test_uri_path}}\get.json' - checksum_algorithm: sha1 - get_checksum: yes - register: post_request_with_different_content_actual - -- name: assert post request with return_content, dest and different content - assert: - that: - - post_request_with_different_content.changed - - post_request_with_different_content_actual.stat.exists == True - - post_request_with_different_content_actual.stat.checksum == post_request_with_different_content.content|hash('sha1') - -- name: test redirect without follow_redirects - win_uri: - url: https://{{httpbin_host}}/redirect/2 - follow_redirects: none - status_code: 302 - register: redirect_without_follow - -- name: assert redirect without follow_redirects - assert: - that: - - not redirect_without_follow.changed - - redirect_without_follow.location|default("") == '/relative-redirect/1' - - redirect_without_follow.status_code == 302 - -- name: test redirect with follow_redirects - win_uri: - url: https://{{httpbin_host}}/redirect/2 - follow_redirects: all - register: redirect_with_follow - -- name: assert redirect with follow_redirects - assert: - that: - - not redirect_with_follow.changed - - redirect_with_follow.location is not defined - - redirect_with_follow.status_code == 200 - - redirect_with_follow.response_uri == 'https://{{httpbin_host}}/get' - -- name: get request with redirect of TLS - win_uri: - url: https://{{httpbin_host}}/redirect/2 - follow_redirects: all - register: redirect_with_follow_tls - -- name: assert redirect with redirect of TLS - assert: - that: - - not redirect_with_follow_tls.changed - - redirect_with_follow_tls.location is not defined - - redirect_with_follow_tls.status_code == 200 - - redirect_with_follow_tls.response_uri == 'https://{{httpbin_host}}/get' - -- name: test basic auth - win_uri: - url: https://{{httpbin_host}}/basic-auth/user/passwd - user: user - password: passwd - register: basic_auth - -- name: assert test basic auth - assert: - that: - - not basic_auth.changed - - basic_auth.status_code == 200 - -- name: test basic auth with force auth - win_uri: - url: https://{{httpbin_host}}/hidden-basic-auth/user/passwd - user: user - password: passwd - force_basic_auth: yes - register: basic_auth_forced - -- name: assert test basic auth with forced auth - assert: - that: - - not basic_auth_forced.changed - - basic_auth_forced.status_code == 200 - -- name: test PUT - win_uri: - url: https://{{httpbin_host}}/put - method: PUT - body: foo=bar - return_content: yes - register: put_request - -- name: assert test PUT - assert: - that: - - not put_request.changed - - put_request.status_code == 200 - - put_request.json.data == 'foo=bar' - -- name: test OPTIONS - win_uri: - url: https://{{httpbin_host}}/ - method: OPTIONS - register: option_request - -- name: assert test OPTIONS - assert: - that: - - not option_request.changed - - option_request.status_code == 200 - - 'option_request.allow.split(", ")|sort == ["GET", "HEAD", "OPTIONS"]' - -# SNI Tests - -- name: validate status_codes are correct - win_uri: - url: https://{{httpbin_host}}/status/202 - status_code: - - 202 - - 418 - method: POST - body: foo - register: status_code_check - -- name: assert validate status_codes are correct - assert: - that: - - not status_code_check.changed - - status_code_check.status_code == 202 - -- name: send JSON body with dict type - win_uri: - url: https://{{httpbin_host}}/post - method: POST - body: - foo: bar - list: - - 1 - - 2 - dict: - foo: bar - headers: - 'Content-Type': 'text/json' - return_content: yes - register: json_as_dict - -- name: set fact of expected json dict - set_fact: - json_as_dict_value: - foo: bar - list: - - 1 - - 2 - dict: - foo: bar - -- name: assert send JSON body with dict type - assert: - that: - - not json_as_dict.changed - - json_as_dict.json.json == json_as_dict_value - - json_as_dict.status_code == 200 - -- name: send JSON body with 1 item in list - win_uri: - url: https://{{httpbin_host}}/post - method: POST - body: - - foo: bar - headers: - 'Content-Type': 'text/json' - return_content: yes - register: json_as_oneitemlist - -- name: set fact of expected json 1 item list - set_fact: - json_as_oneitemlist_value: - - foo: bar - -- name: assert send JSON body with 1 item in list - assert: - that: - - not json_as_oneitemlist.changed - - json_as_oneitemlist.json.json == json_as_oneitemlist_value - - json_as_oneitemlist.status_code == 200 - -- name: get request with custom headers - win_uri: - url: https://{{httpbin_host}}/get - headers: - Test-Header: hello - Another-Header: world - return_content: yes - register: get_custom_header - -- name: assert request with custom headers - assert: - that: - - not get_custom_header.changed - - get_custom_header.status_code == 200 - - get_custom_header.json.headers['Test-Header'] == 'hello' - - get_custom_header.json.headers['Another-Header'] == 'world' - -- name: Validate invalid method - win_uri: - url: https://{{ httpbin_host }}/anything - method: UNKNOWN - register: invalid_method - ignore_errors: yes - -- name: Assert invalid method fails - assert: - that: - - invalid_method is failure - - invalid_method.status_code == 405 - - invalid_method.status_description == 'METHOD NOT ALLOWED' - -# client cert auth tests - -- name: get request with timeout - win_uri: - url: https://{{httpbin_host}}/delay/10 - timeout: 5 - register: get_with_timeout_fail - failed_when: '"The operation has timed out" not in get_with_timeout_fail.msg' - -- name: connect to fakepath that does not exist - win_uri: - url: https://{{httpbin_host}}/fakepath - status_code: 404 - return_content: yes - register: invalid_path - -# verifies the return values are still set on a non 200 response -- name: assert connect to fakepath that does not exist - assert: - that: - - not invalid_path.changed - - invalid_path.status_code == 404 - - invalid_path.status_description == 'NOT FOUND' - - invalid_path.content is defined - - invalid_path.method == 'GET' - - invalid_path.connection is defined - -- name: post request with custom headers - win_uri: - url: https://{{httpbin_host}}/post - method: POST - headers: - Test-Header: hello - Another-Header: world - content_type: application/json - body: '{"foo": "bar"}' - return_content: yes - register: post_request_with_custom_headers - -- name: assert post with custom headers - assert: - that: - - not post_request_with_custom_headers.changed - - post_request_with_custom_headers.status_code == 200 - - post_request_with_custom_headers.json.headers['Content-Type'] == "application/json" - - post_request_with_custom_headers.json.headers['Test-Header'] == 'hello' - - post_request_with_custom_headers.json.headers['Another-Header'] == 'world' - -- name: validate status codes as list of strings - win_uri: - url: https://{{httpbin_host}}/status/202 - status_code: - - '202' - - '418' - method: POST - body: foo - return_content: yes - register: request_status_code_string - -- name: assert status codes as list of strings - assert: - that: - - not request_status_code_string.changed - - request_status_code_string.status_code == 202 - -- name: validate status codes as comma separated list - win_uri: - url: https://{{httpbin_host}}/status/202 - status_code: 202, 418 - method: POST - body: foo - return_content: yes - register: request_status_code_comma - -- name: assert status codes as comma separated list - assert: - that: - - not request_status_code_comma.changed - - request_status_code_comma.status_code == 202