summaryrefslogtreecommitdiff
path: root/test/integration/targets
diff options
context:
space:
mode:
authorJordan Borean <jborean93@gmail.com>2017-11-16 10:04:03 +1000
committeransibot <ansibot@users.noreply.github.com>2017-11-15 19:04:03 -0500
commite16e6313c712825789a421bc0bd6779cab3ae0ba (patch)
treefce937fba994e51a59ea046c2b7720ba83ccc2f2 /test/integration/targets
parent5e20fd0943421739b40db5a7ac9bf1e5ff463b19 (diff)
downloadansible-e16e6313c712825789a421bc0bd6779cab3ae0ba.tar.gz
windows: fix for checking locked system files (#30665)
* fix for checking locked system files * moved functions to share module util and created tests * fixed windows-paths test based on win_stat changes
Diffstat (limited to 'test/integration/targets')
-rw-r--r--test/integration/targets/win_command/tasks/main.yml12
-rw-r--r--test/integration/targets/win_module_utils/library/file_util_test.ps159
-rw-r--r--test/integration/targets/win_module_utils/tasks/main.yml8
-rw-r--r--test/integration/targets/win_shell/tasks/main.yml12
-rw-r--r--test/integration/targets/win_stat/tasks/main.yml13
-rw-r--r--test/integration/targets/windows-paths/tasks/main.yml4
6 files changed, 106 insertions, 2 deletions
diff --git a/test/integration/targets/win_command/tasks/main.yml b/test/integration/targets/win_command/tasks/main.yml
index aaa8ea3fb9..8a71a0a881 100644
--- a/test/integration/targets/win_command/tasks/main.yml
+++ b/test/integration/targets/win_command/tasks/main.yml
@@ -77,6 +77,18 @@
- cmdout|skipped
- cmdout.msg is search('exists')
+- name: test creates with hidden system file, should skip
+ win_command: echo no
+ args:
+ creates: C:\pagefile.sys
+ register: cmdout
+
+- name: validate result
+ assert:
+ that:
+ - cmdout|skipped
+ - cmdout.msg is search('exists')
+
- name: ensure testfile is still present
win_stat:
path: c:\testfile.txt
diff --git a/test/integration/targets/win_module_utils/library/file_util_test.ps1 b/test/integration/targets/win_module_utils/library/file_util_test.ps1
new file mode 100644
index 0000000000..3626c91bca
--- /dev/null
+++ b/test/integration/targets/win_module_utils/library/file_util_test.ps1
@@ -0,0 +1,59 @@
+#!powershell
+
+#Requires -Module Ansible.ModuleUtils.Legacy
+#Requires -Module Ansible.ModuleUtils.FileUtil
+
+Function Assert-Equals($actual, $expected) {
+ if ($actual -cne $expected) {
+ Fail-Json @{} "actual != expected`nActual: $actual`nExpected: $expected"
+ }
+}
+
+# Test-FilePath Hidden system file
+$actual = Test-FilePath -path C:\pagefile.sys
+Assert-Equals -actual $actual -expected $true
+
+# Test-FilePath File that doesn't exist
+$actual = Test-FilePath -path C:\fakefile
+Assert-Equals -actual $actual -expected $false
+
+# Test-FilePath Normal directory
+$actual = Test-FilePath -path C:\Windows
+Assert-Equals -actual $actual -expected $true
+
+# Test-FilePath Normal file
+$actual = Test-FilePath -path C:\Windows\System32\kernel32.dll
+
+# Test-FilePath fails with wildcard
+try {
+ Test-FilePath -Path C:\Windows\*.exe
+ Fail-Json @{} "exception was not thrown with wildcard search for Test-FilePath"
+} catch {
+ Assert-Equals -actual $_.Exception.Message -expected "found multiple files at path 'C:\Windows\*.exe', make sure no wildcards are set in the path"
+}
+
+# Get-FileItem file
+$actual = Get-FileItem -path C:\pagefile.sys
+Assert-Equals -actual $actual.FullName -expected C:\pagefile.sys
+Assert-Equals -actual $actual.PSIsContainer -expected $false
+Assert-Equals -actual $actual.Exists -expected $true
+
+# Get-FileItem directory
+$actual = Get-FileItem -path C:\Windows
+Assert-Equals -actual $actual.FullName -expected C:\Windows
+Assert-Equals -actual $actual.PSIsContainer -expected $true
+Assert-Equals -actual $actual.Exists -expected $true
+
+# Get-FileItem doesn't exists
+$actual = Get-FileItem -path C:\fakefile
+Assert-Equals -actual $actual -expected $null
+
+# Get-FileItem fails with wildcard
+try {
+ Get-FileItem -Path C:\Windows\*.exe
+ Fail-Json @{} "exception was not thrown with wildcard search for Get-FileItem"
+} catch {
+ Assert-Equals -actual $_.Exception.Message -expected "found multiple files at path 'C:\Windows\*.exe', make sure no wildcards are set in the path"
+}
+
+Exit-Json @{ data = 'success' }
diff --git a/test/integration/targets/win_module_utils/tasks/main.yml b/test/integration/targets/win_module_utils/tasks/main.yml
index f00f08e1e9..05ad17dd63 100644
--- a/test/integration/targets/win_module_utils/tasks/main.yml
+++ b/test/integration/targets/win_module_utils/tasks/main.yml
@@ -80,3 +80,11 @@
win_file:
path: C:\ansible testing
state: absent
+
+- name: call module with FileUtil tests
+ file_util_test:
+ register: file_util_test
+
+- assert:
+ that:
+ - file_util_test.data == 'success'
diff --git a/test/integration/targets/win_shell/tasks/main.yml b/test/integration/targets/win_shell/tasks/main.yml
index 2716b948e3..aeaf0eb373 100644
--- a/test/integration/targets/win_shell/tasks/main.yml
+++ b/test/integration/targets/win_shell/tasks/main.yml
@@ -105,6 +105,18 @@
- shellout|skipped
- shellout.msg is search('exists')
+- name: test creates with hidden system file, should skip
+ win_shell: echo test
+ args:
+ creates: C:\pagefile.sys
+ register: shellout
+
+- name: validate result
+ assert:
+ that:
+ - shellout|skipped
+ - shellout.msg is search('exists')
+
- name: ensure testfile is still present
win_stat:
path: c:\testfile.txt
diff --git a/test/integration/targets/win_stat/tasks/main.yml b/test/integration/targets/win_stat/tasks/main.yml
index bd1e3d53a9..89594be38d 100644
--- a/test/integration/targets/win_stat/tasks/main.yml
+++ b/test/integration/targets/win_stat/tasks/main.yml
@@ -295,6 +295,9 @@
- stat_readonly.stat.size == 3
# Requires more work once modular powershell utils are in
+- name: weird issue, need to access the file in anyway to get the correct date stats
+ win_command: powershell.exe Test-Path {{win_output_dir}}\win_stat\nested\hard-link.ps1
+
- name: test win_stat on hard link file
win_stat:
path: "{{win_output_dir}}\\win_stat\\nested\\hard-link.ps1"
@@ -541,3 +544,13 @@
win_file:
path: "{{win_output_dir}}\\win_stat"
state: absent
+
+- name: get stat of pagefile
+ win_stat:
+ path: C:\pagefile.sys
+ register: pagefile_stat
+
+- name: assert get stat of pagefile
+ assert:
+ that:
+ - pagefile_stat.stat.exists == True
diff --git a/test/integration/targets/windows-paths/tasks/main.yml b/test/integration/targets/windows-paths/tasks/main.yml
index 075428980c..9610f39339 100644
--- a/test/integration/targets/windows-paths/tasks/main.yml
+++ b/test/integration/targets/windows-paths/tasks/main.yml
@@ -82,7 +82,7 @@
- trailing_result|success
- trailing_result.stat.attributes == 'Directory'
- trailing_result.stat.exists == true
- - trailing_result.stat.path == trailing
+ - trailing_result.stat.path == no_quotes_single # path is without the trailing \
- name: Set variables in key=value syntax
set_fact:
@@ -178,7 +178,7 @@
- trailing_result|success
- trailing_result.stat.attributes == 'Directory'
- trailing_result.stat.exists == true
- - trailing_result.stat.path == trailing
+ - trailing_result.stat.path == no_quotes_single # path is without the trailing \
- name: Test tab path {{ tab }}
win_stat: