summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/win_exec_wrapper/library
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/win_exec_wrapper/library')
-rw-r--r--test/integration/targets/win_exec_wrapper/library/test_all_options.ps112
-rw-r--r--test/integration/targets/win_exec_wrapper/library/test_common_functions.ps143
-rw-r--r--test/integration/targets/win_exec_wrapper/library/test_fail.ps166
-rw-r--r--test/integration/targets/win_exec_wrapper/library/test_invalid_requires.ps19
-rw-r--r--test/integration/targets/win_exec_wrapper/library/test_min_os_version.ps18
-rw-r--r--test/integration/targets/win_exec_wrapper/library/test_min_ps_version.ps18
6 files changed, 146 insertions, 0 deletions
diff --git a/test/integration/targets/win_exec_wrapper/library/test_all_options.ps1 b/test/integration/targets/win_exec_wrapper/library/test_all_options.ps1
new file mode 100644
index 0000000..7c2c9c7
--- /dev/null
+++ b/test/integration/targets/win_exec_wrapper/library/test_all_options.ps1
@@ -0,0 +1,12 @@
+#!powershell
+
+#Requires -Module Ansible.ModuleUtils.Legacy
+#Requires -Module Ansible.ModuleUtils.SID
+#Requires -Version 3.0
+#AnsibleRequires -OSVersion 6
+#AnsibleRequires -Become
+
+$output = &whoami.exe
+$sid = Convert-ToSID -account_name $output.Trim()
+
+Exit-Json -obj @{ output = $sid; changed = $false }
diff --git a/test/integration/targets/win_exec_wrapper/library/test_common_functions.ps1 b/test/integration/targets/win_exec_wrapper/library/test_common_functions.ps1
new file mode 100644
index 0000000..dde1ebc
--- /dev/null
+++ b/test/integration/targets/win_exec_wrapper/library/test_common_functions.ps1
@@ -0,0 +1,43 @@
+#!powershell
+
+#Requires -Module Ansible.ModuleUtils.Legacy
+
+$ErrorActionPreference = "Stop"
+
+Function Assert-Equal($actual, $expected) {
+ if ($actual -cne $expected) {
+ $call_stack = (Get-PSCallStack)[1]
+ $error_msg = -join @(
+ "AssertionError:`r`nActual: `"$actual`" != Expected: `"$expected`"`r`nLine: "
+ "$($call_stack.ScriptLineNumber), Method: $($call_stack.Position.Text)"
+ )
+ Fail-Json -obj $result -message $error_msg
+ }
+}
+
+$result = @{
+ changed = $false
+}
+
+#ConvertFrom-AnsibleJso
+$input_json = '{"string":"string","float":3.1415926,"dict":{"string":"string","int":1},"list":["entry 1","entry 2"],"null":null,"int":1}'
+$actual = ConvertFrom-AnsibleJson -InputObject $input_json
+Assert-Equal -actual $actual.GetType() -expected ([Hashtable])
+Assert-Equal -actual $actual.string.GetType() -expected ([String])
+Assert-Equal -actual $actual.string -expected "string"
+Assert-Equal -actual $actual.int.GetType() -expected ([Int32])
+Assert-Equal -actual $actual.int -expected 1
+Assert-Equal -actual $actual.null -expected $null
+Assert-Equal -actual $actual.float.GetType() -expected ([Decimal])
+Assert-Equal -actual $actual.float -expected 3.1415926
+Assert-Equal -actual $actual.list.GetType() -expected ([Object[]])
+Assert-Equal -actual $actual.list.Count -expected 2
+Assert-Equal -actual $actual.list[0] -expected "entry 1"
+Assert-Equal -actual $actual.list[1] -expected "entry 2"
+Assert-Equal -actual $actual.GetType() -expected ([Hashtable])
+Assert-Equal -actual $actual.dict.string -expected "string"
+Assert-Equal -actual $actual.dict.int -expected 1
+
+$result.msg = "good"
+Exit-Json -obj $result
+
diff --git a/test/integration/targets/win_exec_wrapper/library/test_fail.ps1 b/test/integration/targets/win_exec_wrapper/library/test_fail.ps1
new file mode 100644
index 0000000..72b89c6
--- /dev/null
+++ b/test/integration/targets/win_exec_wrapper/library/test_fail.ps1
@@ -0,0 +1,66 @@
+#!powershell
+
+#Requires -Module Ansible.ModuleUtils.Legacy
+
+$params = Parse-Args $args -supports_check_mode $true
+
+$data = Get-AnsibleParam -obj $params -name "data" -type "str" -default "normal"
+$result = @{
+ changed = $false
+}
+
+<#
+This module tests various error events in PowerShell to verify our hidden trap
+catches them all and outputs a pretty error message with a traceback to help
+users debug the actual issue
+
+normal - normal execution, no errors
+fail - Calls Fail-Json like normal
+throw - throws an exception
+error - Write-Error with ErrorActionPreferenceStop
+cmdlet_error - Calls a Cmdlet with an invalid error
+dotnet_exception - Calls a .NET function that will throw an error
+function_throw - Throws an exception in a function
+proc_exit_fine - calls an executable with a non-zero exit code with Exit-Json
+proc_exit_fail - calls an executable with a non-zero exit code with Fail-Json
+#>
+
+Function Test-ThrowException {
+ throw "exception in function"
+}
+
+if ($data -eq "normal") {
+ Exit-Json -obj $result
+}
+elseif ($data -eq "fail") {
+ Fail-Json -obj $result -message "fail message"
+}
+elseif ($data -eq "throw") {
+ throw [ArgumentException]"module is thrown"
+}
+elseif ($data -eq "error") {
+ Write-Error -Message $data
+}
+elseif ($data -eq "cmdlet_error") {
+ Get-Item -Path "fake:\path"
+}
+elseif ($data -eq "dotnet_exception") {
+ [System.IO.Path]::GetFullPath($null)
+}
+elseif ($data -eq "function_throw") {
+ Test-ThrowException
+}
+elseif ($data -eq "proc_exit_fine") {
+ # verifies that if no error was actually fired and we have an output, we
+ # don't use the RC to validate if the module failed
+ &cmd.exe /c exit 2
+ Exit-Json -obj $result
+}
+elseif ($data -eq "proc_exit_fail") {
+ &cmd.exe /c exit 2
+ Fail-Json -obj $result -message "proc_exit_fail"
+}
+
+# verify no exception were silently caught during our tests
+Fail-Json -obj $result -message "end of module"
+
diff --git a/test/integration/targets/win_exec_wrapper/library/test_invalid_requires.ps1 b/test/integration/targets/win_exec_wrapper/library/test_invalid_requires.ps1
new file mode 100644
index 0000000..89727ef
--- /dev/null
+++ b/test/integration/targets/win_exec_wrapper/library/test_invalid_requires.ps1
@@ -0,0 +1,9 @@
+#!powershell
+
+#Requires -Module Ansible.ModuleUtils.Legacy
+# Requires -Version 20
+# AnsibleRequires -OSVersion 20
+
+# requires statement must be straight after the original # with now space, this module won't fail
+
+Exit-Json -obj @{ output = "output"; changed = $false }
diff --git a/test/integration/targets/win_exec_wrapper/library/test_min_os_version.ps1 b/test/integration/targets/win_exec_wrapper/library/test_min_os_version.ps1
new file mode 100644
index 0000000..39b1ded
--- /dev/null
+++ b/test/integration/targets/win_exec_wrapper/library/test_min_os_version.ps1
@@ -0,0 +1,8 @@
+#!powershell
+
+#Requires -Module Ansible.ModuleUtils.Legacy
+#AnsibleRequires -OSVersion 20.0
+
+# this shouldn't run as no Windows OS will meet the version of 20.0
+
+Exit-Json -obj @{ output = "output"; changed = $false }
diff --git a/test/integration/targets/win_exec_wrapper/library/test_min_ps_version.ps1 b/test/integration/targets/win_exec_wrapper/library/test_min_ps_version.ps1
new file mode 100644
index 0000000..bb5fd0f
--- /dev/null
+++ b/test/integration/targets/win_exec_wrapper/library/test_min_ps_version.ps1
@@ -0,0 +1,8 @@
+#!powershell
+
+#Requires -Module Ansible.ModuleUtils.Legacy
+#Requires -Version 20.0.0.0
+
+# this shouldn't run as no PS Version will be at 20 in the near future
+
+Exit-Json -obj @{ output = "output"; changed = $false }