summaryrefslogtreecommitdiff
path: root/test/integration/targets/win_get_url/tasks/tests_ftp.yml
blob: d7ae4ae8bf47760bb3754c726eb6a74ecf49e8f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
---
- name: download file from FTP source (check)
  win_get_url:
    url: ftp://localhost/anon/file.txt
    dest: '{{test_win_get_url_path}}\ftp-anon.txt'
  check_mode: yes
  register: ftp_anon_check

- name: get results of download file from FTP source (check)
  win_stat:
    path: '{{test_win_get_url_path}}\ftp-anon.txt'
  register: ftp_anon_result_check

- name: assert download file from FTP source (check)
  assert:
    that:
    - ftp_anon_check is changed
    - not ftp_anon_result_check.stat.exists

- name: download file from FTP source
  win_get_url:
    url: ftp://localhost/anon/file.txt
    dest: '{{test_win_get_url_path}}\ftp-anon.txt'
  register: ftp_anon

- name: get results of download file from FTP source
  win_stat:
    path: '{{test_win_get_url_path}}\ftp-anon.txt'
  register: ftp_anon_result

- name: assert download file from FTP source
  assert:
    that:
    - ftp_anon is changed
    - ftp_anon_result.stat.exists
    - ftp_anon_result.stat.checksum == '67e0de92f29645cc30d8d147b767cceb81756651'

# TODO: Add check for idempotent with force: yes once tmp download and checksum verify are in

- name: download file from FTP source with force no (check)
  win_get_url:
    url: ftp://localhost/anon/file.txt
    dest: '{{test_win_get_url_path}}\ftp-anon.txt'
    force: no
  check_mode: yes
  register: ftp_anon_force_no_check

- name: assert download file from FTP source with force no
  assert:
    that:
    - ftp_anon_force_no_check is not changed

- name: download file from FTP source with force no
  win_get_url:
    url: ftp://localhost/anon/file.txt
    dest: '{{test_win_get_url_path}}\ftp-anon.txt'
    force: no
  register: ftp_anon_force_no

- name: assert download file from FTP source with force no
  assert:
    that:
    - ftp_anon_force_no is not changed

- name: set last modified time on FTP source to newer datetime
  win_shell: (Get-Item -Path '{{test_win_get_url_path}}\ftp\anon\file2.txt').LastWriteTime = (Get-Date).AddHours(24)

- name: download newer file from FTP source to same dest (check)
  win_get_url:
    url: ftp://localhost/anon/file2.txt
    dest: '{{test_win_get_url_path}}\ftp-anon.txt'
    force: no
  check_mode: yes
  register: ftp_anon_force_no_different_check

- name: get result of download newer file from FTP source to same dest (check)
  win_stat:
    path: '{{test_win_get_url_path}}\ftp-anon.txt'
  register: ftp_anon_force_no_different_result_check

- name: assert download newer file from FTP source to same dest (check)
  assert:
    that:
    - ftp_anon_force_no_different_check is changed
    - ftp_anon_force_no_different_result_check.stat.checksum == '67e0de92f29645cc30d8d147b767cceb81756651'

- name: download newer file from FTP source to same dest
  win_get_url:
    url: ftp://localhost/anon/file2.txt
    dest: '{{test_win_get_url_path}}\ftp-anon.txt'
    force: no
  register: ftp_anon_force_no_different

- name: get result of download newer file from FTP source to same dest
  win_stat:
    path: '{{test_win_get_url_path}}\ftp-anon.txt'
  register: ftp_anon_force_no_different_result

- name: assert download newer file from FTP source to same dest (check)
  assert:
    that:
    - ftp_anon_force_no_different is changed
    - ftp_anon_force_no_different_result.stat.checksum == 'eac3baccd817f7137c00138559e2e62aca64aab0'

- name: fail to download file from ftp protected by username
  win_get_url:
    url: ftp://localhost/user/file.txt
    dest: '{{test_win_get_url_path}}\ftp-user.txt'
  register: fail_ftp_no_user
  ignore_errors: yes

- name: assert fail to download file from ftp protected by username
  assert:
    that:
    - fail_ftp_no_user is failed
    - fail_ftp_no_user is not changed
    - fail_ftp_no_user.status_code == 550
    - '"File unavailable (e.g., file not found, no access)." in fail_ftp_no_user.msg'

- name: download FTP file protected by username
  win_get_url:
    url: ftp://localhost/user/file.txt
    dest: '{{test_win_get_url_path}}\ftp-user.txt'
    url_username: username
  register: ftp_user_file

- name: get result of download FTP file protected by username
  win_stat:
    path: '{{test_win_get_url_path}}\ftp-user.txt'
  register: ftp_user_file_result

- name: assert download FTP file protected by username
  assert:
    that:
    - ftp_user_file is changed
    - ftp_user_file_result.stat.exists
    - ftp_user_file_result.stat.checksum == '0efc2e97611cf74e25ec17a00d4b2cf65d0c28ba'

- name: download FTP file protected by username and password
  win_get_url:
    url: ftp://localhost/user-pass/file.txt
    dest: '{{test_win_get_url_path}}\ftp-user-pass.txt'
    url_username: userpass
    url_password: password
  register: ftp_user_pass_file

- name: get result of download FTP file protected by username and password
  win_stat:
    path: '{{test_win_get_url_path}}\ftp-user-pass.txt'
  register: ftp_user_pass_file_result

- name: assert download FTP file protected by username and password
  assert:
    that:
    - ftp_user_pass_file is changed
    - ftp_user_pass_file_result.stat.exists
    - ftp_user_pass_file_result.stat.checksum == '7da5f1124d4a986cba2b4658d38d95eb55afe086'