diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-18 05:52:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-18 05:52:22 +0000 |
commit | 38b7c80217c4e72b1d8988eb1e60bb6e77334114 (patch) | |
tree | 356e9fd3762877d07cde52d21e77070aeff7e789 /ansible_collections/community/windows/tests | |
parent | Adding upstream version 7.7.0+dfsg. (diff) | |
download | ansible-38b7c80217c4e72b1d8988eb1e60bb6e77334114.tar.xz ansible-38b7c80217c4e72b1d8988eb1e60bb6e77334114.zip |
Adding upstream version 9.4.0+dfsg.upstream/9.4.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/community/windows/tests')
52 files changed, 211 insertions, 755 deletions
diff --git a/ansible_collections/community/windows/tests/integration/targets/setup_win_device/library/win_device.ps1 b/ansible_collections/community/windows/tests/integration/targets/setup_win_device/library/win_device.ps1 index 77fac9086..6674ddb26 100644 --- a/ansible_collections/community/windows/tests/integration/targets/setup_win_device/library/win_device.ps1 +++ b/ansible_collections/community/windows/tests/integration/targets/setup_win_device/library/win_device.ps1 @@ -30,7 +30,6 @@ Add-CSharpType -References @' using Microsoft.Win32.SafeHandles; using System; using System.ComponentModel; -using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Text; @@ -246,7 +245,6 @@ namespace Ansible.Device { public SafeDeviceInfoSet() : base(true) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { return NativeMethods.SetupDiDestroyDeviceInfoList(handle); @@ -271,7 +269,6 @@ namespace Ansible.Device base.SetHandle(Marshal.StringToHGlobalUni(sz)); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { Marshal.FreeHGlobal(handle); diff --git a/ansible_collections/community/windows/tests/integration/targets/win_audit_rule/library/test_get_audit_rule.ps1 b/ansible_collections/community/windows/tests/integration/targets/win_audit_rule/library/test_get_audit_rule.ps1 index 37096c21a..ab113356f 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_audit_rule/library/test_get_audit_rule.ps1 +++ b/ansible_collections/community/windows/tests/integration/targets/win_audit_rule/library/test_get_audit_rule.ps1 @@ -6,6 +6,10 @@ #Requires -Module Ansible.ModuleUtils.Legacy #Requires -Module Ansible.ModuleUtils.SID +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSCustomUseLiteralPath', '', + Justification = 'LiteralPath with Get-Acl is problematic')] +param() + $params = Parse-Args -arguments $args -supports_check_mode $true # these are your module parameters diff --git a/ansible_collections/community/windows/tests/integration/targets/win_auto_logon/library/test_autologon_info.ps1 b/ansible_collections/community/windows/tests/integration/targets/win_auto_logon/library/test_autologon_info.ps1 index 2819151ff..d352f2ff7 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_auto_logon/library/test_autologon_info.ps1 +++ b/ansible_collections/community/windows/tests/integration/targets/win_auto_logon/library/test_autologon_info.ps1 @@ -8,7 +8,6 @@ $module = [Ansible.Basic.AnsibleModule]::Create($args, @{}) Add-CSharpType -AnsibleModule $module -References @' using Microsoft.Win32.SafeHandles; using System; -using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Text; @@ -103,8 +102,6 @@ namespace Ansible.TestAutoLogonInfo { internal SafeLsaMemory() : base(true) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] - protected override bool ReleaseHandle() { return NativeMethods.LsaFreeMemory(handle) == 0; @@ -120,8 +117,6 @@ namespace Ansible.TestAutoLogonInfo base.SetHandle(ptr); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] - protected override bool ReleaseHandle() { if (handle != IntPtr.Zero) @@ -134,8 +129,6 @@ namespace Ansible.TestAutoLogonInfo { internal SafeLsaHandle() : base(true) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] - protected override bool ReleaseHandle() { return NativeMethods.LsaClose(handle) == 0; diff --git a/ansible_collections/community/windows/tests/integration/targets/win_credential/library/test_cred_facts.ps1 b/ansible_collections/community/windows/tests/integration/targets/win_credential/library/test_cred_facts.ps1 index 59206638f..fc2721f05 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_credential/library/test_cred_facts.ps1 +++ b/ansible_collections/community/windows/tests/integration/targets/win_credential/library/test_cred_facts.ps1 @@ -24,7 +24,6 @@ using Microsoft.Win32.SafeHandles; using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Text; @@ -187,7 +186,6 @@ namespace Ansible.CredentialManager { public SafeCredentialBuffer() : base(true) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { NativeMethods.CredFree(handle); @@ -206,7 +204,6 @@ namespace Ansible.CredentialManager { base.SetHandle(handle); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { Marshal.FreeHGlobal(handle); diff --git a/ansible_collections/community/windows/tests/integration/targets/win_data_deduplication/aliases b/ansible_collections/community/windows/tests/integration/targets/win_data_deduplication/aliases index 2a4f8cc66..3cf5b97e8 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_data_deduplication/aliases +++ b/ansible_collections/community/windows/tests/integration/targets/win_data_deduplication/aliases @@ -1,2 +1 @@ shippable/windows/group3 -skip/windows/2012 diff --git a/ansible_collections/community/windows/tests/integration/targets/win_data_deduplication/tasks/main.yml b/ansible_collections/community/windows/tests/integration/targets/win_data_deduplication/tasks/main.yml index ae6be90ec..83c7197c6 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_data_deduplication/tasks/main.yml +++ b/ansible_collections/community/windows/tests/integration/targets/win_data_deduplication/tasks/main.yml @@ -1,2 +1,2 @@ --- -- include: pre_test.yml +- import_tasks: pre_test.yml diff --git a/ansible_collections/community/windows/tests/integration/targets/win_data_deduplication/tasks/pre_test.yml b/ansible_collections/community/windows/tests/integration/targets/win_data_deduplication/tasks/pre_test.yml index d63468990..8028cb17b 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_data_deduplication/tasks/pre_test.yml +++ b/ansible_collections/community/windows/tests/integration/targets/win_data_deduplication/tasks/pre_test.yml @@ -34,7 +34,7 @@ - name: Run tests block: - - include: tests.yml + - import_tasks: tests.yml always: - name: Detach disk ansible.windows.win_command: diskpart.exe /s {{ remote_tmp_dir }}\partition_deletion_script.txt diff --git a/ansible_collections/community/windows/tests/integration/targets/win_disk_facts/tasks/main.yml b/ansible_collections/community/windows/tests/integration/targets/win_disk_facts/tasks/main.yml index f1873efa7..d55a7221c 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_disk_facts/tasks/main.yml +++ b/ansible_collections/community/windows/tests/integration/targets/win_disk_facts/tasks/main.yml @@ -10,4 +10,4 @@ block: - name: Test in normal mode - include: tests.yml + import_tasks: tests.yml diff --git a/ansible_collections/community/windows/tests/integration/targets/win_dns_record/tasks/main.yml b/ansible_collections/community/windows/tests/integration/targets/win_dns_record/tasks/main.yml index 9b06a65b0..32f754d08 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_dns_record/tasks/main.yml +++ b/ansible_collections/community/windows/tests/integration/targets/win_dns_record/tasks/main.yml @@ -8,5 +8,5 @@ register: os_supported - name: run tests on supported hosts - include: tests.yml + import_tasks: tests.yml when: os_supported.stdout | trim | bool diff --git a/ansible_collections/community/windows/tests/integration/targets/win_dns_zone/aliases b/ansible_collections/community/windows/tests/integration/targets/win_dns_zone/aliases index df7c2d121..4cd27b3cb 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_dns_zone/aliases +++ b/ansible_collections/community/windows/tests/integration/targets/win_dns_zone/aliases @@ -1,2 +1 @@ shippable/windows/group1 -skip/windows/2012
\ No newline at end of file diff --git a/ansible_collections/community/windows/tests/integration/targets/win_domain_ou/aliases b/ansible_collections/community/windows/tests/integration/targets/win_domain_ou/aliases index 22f581bfd..423ce3910 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_domain_ou/aliases +++ b/ansible_collections/community/windows/tests/integration/targets/win_domain_ou/aliases @@ -1,2 +1 @@ shippable/windows/group2 -skip/windows/2012 diff --git a/ansible_collections/community/windows/tests/integration/targets/win_domain_user/aliases b/ansible_collections/community/windows/tests/integration/targets/win_domain_user/aliases index 22f581bfd..423ce3910 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_domain_user/aliases +++ b/ansible_collections/community/windows/tests/integration/targets/win_domain_user/aliases @@ -1,2 +1 @@ shippable/windows/group2 -skip/windows/2012 diff --git a/ansible_collections/community/windows/tests/integration/targets/win_firewall/aliases b/ansible_collections/community/windows/tests/integration/targets/win_firewall/aliases index c8fd90a1f..4f4664b68 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_firewall/aliases +++ b/ansible_collections/community/windows/tests/integration/targets/win_firewall/aliases @@ -1,3 +1 @@ shippable/windows/group5 -skip/windows/2012 -skip/windows/2012-R2 diff --git a/ansible_collections/community/windows/tests/integration/targets/win_format/tasks/main.yml b/ansible_collections/community/windows/tests/integration/targets/win_format/tasks/main.yml index 5ea27a6f0..71b897aac 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_format/tasks/main.yml +++ b/ansible_collections/community/windows/tests/integration/targets/win_format/tasks/main.yml @@ -3,5 +3,5 @@ ansible.windows.win_shell: if (Get-Command -Name Format-Volume -ErrorAction SilentlyContinue) { $true } else { $false } register: module_present -- include: pre_test.yml +- include_tasks: pre_test.yml when: module_present.stdout | trim | bool diff --git a/ansible_collections/community/windows/tests/integration/targets/win_format/tasks/pre_test.yml b/ansible_collections/community/windows/tests/integration/targets/win_format/tasks/pre_test.yml index a29a47bbe..0fce957ef 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_format/tasks/pre_test.yml +++ b/ansible_collections/community/windows/tests/integration/targets/win_format/tasks/pre_test.yml @@ -15,7 +15,7 @@ - name: Run tests block: - - include: tests.yml + - import_tasks: tests.yml always: - name: Detach disk ansible.windows.win_command: diskpart.exe /s {{ remote_tmp_dir }}\partition_deletion_script.txt diff --git a/ansible_collections/community/windows/tests/integration/targets/win_inet_proxy/library/win_inet_proxy_info.ps1 b/ansible_collections/community/windows/tests/integration/targets/win_inet_proxy/library/win_inet_proxy_info.ps1 index 76bf03ec9..810c8ba97 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_inet_proxy/library/win_inet_proxy_info.ps1 +++ b/ansible_collections/community/windows/tests/integration/targets/win_inet_proxy/library/win_inet_proxy_info.ps1 @@ -22,7 +22,6 @@ using Microsoft.Win32.SafeHandles; using System; using System.Collections.Generic; using System.ComponentModel; -using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; namespace Ansible.WinINetProxyInfo @@ -138,7 +137,6 @@ namespace Ansible.WinINetProxyInfo base.SetHandle(handle); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { Marshal.FreeHGlobal(handle); diff --git a/ansible_collections/community/windows/tests/integration/targets/win_initialize_disk/tasks/main.yml b/ansible_collections/community/windows/tests/integration/targets/win_initialize_disk/tasks/main.yml index b752a7913..303723e9e 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_initialize_disk/tasks/main.yml +++ b/ansible_collections/community/windows/tests/integration/targets/win_initialize_disk/tasks/main.yml @@ -17,7 +17,7 @@ - name: Run tests block: - - include: tests.yml + - import_tasks: tests.yml always: - name: Detach disk ansible.windows.win_command: diskpart.exe /s C:\win_initialize_disk_tests\vhdx_deletion_script.txt diff --git a/ansible_collections/community/windows/tests/integration/targets/win_nssm/tasks/tests.yml b/ansible_collections/community/windows/tests/integration/targets/win_nssm/tasks/tests.yml index cf8f0cfbe..b4ed06efd 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_nssm/tasks/tests.yml +++ b/ansible_collections/community/windows/tests/integration/targets/win_nssm/tasks/tests.yml @@ -401,52 +401,6 @@ - install_service_reset_appenv.changed == true - install_service_reset_appenv_actual.stdout == '\r\n' -# deprecated in 2.12 -- name: install service with dict-as-string parameters - win_nssm: - name: '{{ test_service_name }}' - application: C:\Windows\System32\cmd.exe - app_parameters: foo=true; -file.out=output.bat; -path=C:\with space\; -str=test"quotes; _=bar - register: mixed_params - -# deprecated in 2.12 -- name: get result of install service with dict-as-string parameters - ansible.windows.win_shell: '$service = ''{{ test_service_name }}''; {{ test_service_cmd }}' - register: mixed_params_actual - -# deprecated in 2.12 -- name: assert results of install service with dict-as-string parameters - assert: - that: - - mixed_params.changed == true - - (mixed_params_actual.stdout|from_json).Exists == true - - (mixed_params_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe" - # Expected value: bar -file.out output.bat -str "test\"quotes" foo true -path "C:\with space\\" (backslashes doubled for jinja) - - (mixed_params_actual.stdout|from_json).Parameters.AppParameters == 'bar -file.out output.bat -str "test\\"quotes" foo true -path "C:\\with space\\\\"' - -# deprecated in 2.12 -- name: install service with dict-as-string parameters (idempotent) - win_nssm: - name: '{{ test_service_name }}' - application: C:\Windows\System32\cmd.exe - app_parameters: foo=true; -file.out=output.bat; -path=C:\with space\; -str=test"quotes; _=bar - register: mixed_params_again - -# deprecated in 2.12 -- name: get result of install service with dict-as-string parameters (idempotent) - ansible.windows.win_shell: '$service = ''{{ test_service_name }}''; {{ test_service_cmd }}' - register: mixed_params_again_actual - -# deprecated in 2.12 -- name: assert results of install service with dict-as-string parameters (idempotent) - assert: - that: - - mixed_params_again.changed == false - - (mixed_params_again_actual.stdout|from_json).Exists == true - - (mixed_params_again_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe" - # Expected value: bar -file.out output.bat -str "test\"quotes" foo true -path "C:\with space\\" (backslashes doubled for jinja) - - (mixed_params_again_actual.stdout|from_json).Parameters.AppParameters == 'bar -file.out output.bat -str "test\\"quotes" foo true -path "C:\\with space\\\\"' - - name: install service with list of parameters win_nssm: name: '{{ test_service_name }}' diff --git a/ansible_collections/community/windows/tests/integration/targets/win_partition/tasks/main.yml b/ansible_collections/community/windows/tests/integration/targets/win_partition/tasks/main.yml index 50d086ae1..54e7f8a9d 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_partition/tasks/main.yml +++ b/ansible_collections/community/windows/tests/integration/targets/win_partition/tasks/main.yml @@ -12,7 +12,7 @@ - name: Run tests block: - - include: tests.yml + - import_tasks: tests.yml always: - name: Detach disk ansible.windows.win_command: diskpart.exe /s "{{ remote_tmp_dir }}\vhdx_deletion_script.txt" diff --git a/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/module/template.psd1 b/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/module/template.psd1 index cd6709722..f4441fd87 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/module/template.psd1 +++ b/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/module/template.psd1 @@ -10,8 +10,6 @@ "--- FUNCTION ---" ) PrivateData = @{ - PSData = @{ ---- PS_DATA --- - } + PSData = @{} } } diff --git a/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/module/template.psm1 b/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/module/template.psm1 index ac38fb5ed..3f76721d3 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/module/template.psm1 +++ b/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/module/template.psm1 @@ -1,4 +1,17 @@ -Function --- FUNCTION --- { +Function Get-Function { + <# + .SYNOPSIS + Help for Get-Function + + .DESCRIPTION + Description for Get-Function + + .EXAMPLE + Get-Function + + .NOTES + Notes for Get-Function + #> return [PSCustomObject]@{ Name = "--- NAME ---" Version = "--- VERSION ---" @@ -6,5 +19,5 @@ Function --- FUNCTION --- { } } -Export-ModuleMember -Function --- FUNCTION --- +Export-ModuleMember -Function Get-Function diff --git a/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/setup_certs.sh b/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/setup_certs.sh index 258567316..fcae5f0e6 100644..100755 --- a/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/setup_certs.sh +++ b/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/setup_certs.sh @@ -16,4 +16,8 @@ openssl req -new -key sign.key -out sign.csr -subj "/CN=Ansible Sign" -config op openssl x509 -req -in sign.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out sign.pem -days 365 -extfile openssl.conf -extensions req_sign -passin pass:password # Create pfx that includes signing cert and cert with the pass 'password' -openssl pkcs12 -export -out sign.pfx -inkey sign.key -in sign.pem -passin pass:password -passout pass:password +pfx_args=() +if [ "${1}" == "-use-legacy" ]; then + pfx_args=("-certpbe" "PBE-SHA1-3DES" "-keypbe" "PBE-SHA1-3DES" "-macalg" "SHA1") +fi +openssl pkcs12 -export -out sign.pfx -inkey sign.key -in sign.pem -passin pass:password -passout pass:password "${pfx_args[@]}" diff --git a/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/setup_modules.ps1 b/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/setup_modules.ps1 index 48d55b574..b08aca8b2 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/setup_modules.ps1 +++ b/ansible_collections/community/windows/tests/integration/targets/win_psmodule/files/setup_modules.ps1 @@ -28,8 +28,8 @@ $packages = @( foreach ($package in $packages) { $tmp_dir = Join-Path -Path $template_path -ChildPath $package.name - if (Test-Path -Path $tmp_dir) { - Remove-Item -Path $tmp_dir -Force -Recurse + if (Test-Path -LiteralPath $tmp_dir) { + Remove-Item -LiteralPath $tmp_dir -Force -Recurse } New-Item -Path $tmp_dir -ItemType Directory > $null @@ -50,15 +50,15 @@ foreach ($package in $packages) { $manifest = $manifest.Replace('--- NAME ---', $package.name).Replace('--- VERSION ---', $package.version) $manifest = $manifest.Replace('--- GUID ---', [Guid]::NewGuid()).Replace('--- FUNCTION ---', $package.function) - $manifest = $manifest.Replace('--- PS_DATA ---', $ps_data -join "`n") + $manifest = $manifest.Replace('PSData = @{}', "PSData = @{`n$($ps_data -join "`n")`n}") $manifest_path = Join-Path -Path $tmp_dir -ChildPath "$($package.name).psd1" - Set-Content -Path $manifest_path -Value $manifest + Set-Content -LiteralPath $manifest_path -Value $manifest $script = [System.IO.File]::ReadAllText($template_script) $script = $script.Replace('--- NAME ---', $package.name).Replace('--- VERSION ---', $package.version) - $script = $script.Replace('--- REPO ---', $package.repo).Replace('--- FUNCTION ---', $package.function) + $script = $script.Replace('--- REPO ---', $package.repo).Replace('Get-Function', $package.function) $script_path = Join-Path -Path $tmp_dir -ChildPath "$($package.name).psm1" - Set-Content -Path $script_path -Value $script + Set-Content -LiteralPath $script_path -Value $script $signed = if ($package.ContainsKey("signed")) { $package.signed } else { $true } if ($signed) { @@ -74,16 +74,16 @@ foreach ($package in $packages) { $nuspec = $nuspec.Replace('--- NAME ---', $package.name).Replace('--- VERSION ---', $nuget_version) $nuspec = $nuspec.Replace('--- FUNCTION ---', $package.function) $nuspec = $nuspec.Replace('--- LICACC ---', ($package.require_license -as [bool]).ToString().ToLower()) - Set-Content -Path (Join-Path -Path $tmp_dir -ChildPath "$($package.name).nuspec") -Value $nuspec + Set-Content -LiteralPath (Join-Path -Path $tmp_dir -ChildPath "$($package.name).nuspec") -Value $nuspec &$nuget_exe pack "$tmp_dir\$($package.name).nuspec" -outputdirectory $tmp_dir $repo_path = Join-Path -Path $template_path -ChildPath $package.repo $nupkg_filename = "$($package.name).$($nuget_version).nupkg" - Copy-Item -Path (Join-Path -Path $tmp_dir -ChildPath $nupkg_filename) ` + Copy-Item -LiteralPath (Join-Path -Path $tmp_dir -ChildPath $nupkg_filename) ` -Destination (Join-Path -Path $repo_path -ChildPath $nupkg_filename) } finally { - Remove-Item -Path $tmp_dir -Force -Recurse + Remove-Item -LiteralPath $tmp_dir -Force -Recurse } } diff --git a/ansible_collections/community/windows/tests/integration/targets/win_psmodule/tasks/main.yml b/ansible_collections/community/windows/tests/integration/targets/win_psmodule/tasks/main.yml index ffe1a0978..fe264cc0e 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_psmodule/tasks/main.yml +++ b/ansible_collections/community/windows/tests/integration/targets/win_psmodule/tasks/main.yml @@ -6,25 +6,6 @@ - name: setup test repos and modules import_tasks: setup.yml -# Remove the below task in Ansible 2.12 -- name: ensure warning is fired when adding a repo - win_psmodule: - name: ansible-test1 - repository: some repo - url: '{{ remote_tmp_dir }}' - state: present - register: dep_repo_add - ignore_errors: yes # will fail because this repo doesn't actually have this module - check_mode: yes - -- name: assert warning is fired when adding a repo - assert: - that: - - dep_repo_add is changed - - dep_repo_add.deprecations|length == 1 - - dep_repo_add.deprecations[0].msg == 'Adding a repo with this module is deprecated, the repository parameter should only be used to select a repo. Use community.windows.win_psrepository to manage repos' - - dep_repo_add.deprecations[0].date == '2021-07-01' - ### licensed module checks # it is not known in check mode that a module requires # license acceptance, so we don't do check mode tests diff --git a/ansible_collections/community/windows/tests/integration/targets/win_psmodule/tasks/setup.yml b/ansible_collections/community/windows/tests/integration/targets/win_psmodule/tasks/setup.yml index 42049a3e3..14b591fcd 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_psmodule/tasks/setup.yml +++ b/ansible_collections/community/windows/tests/integration/targets/win_psmodule/tasks/setup.yml @@ -66,8 +66,16 @@ delegate_to: localhost register: output_dir_abs +- name: check if we can use the default AES encryption + ansible.windows.win_powershell: + script: | + $osVersion = [Version](Get-Item -LiteralPath "$env:SystemRoot\System32\kernel32.dll").VersionInfo.ProductVersion + $osVersion -ge [Version]"10.0.17763" + changed_when: false + register: aes256_support + - name: create certificates for code signing - script: setup_certs.sh + script: setup_certs.sh {{ '' if aes256_support.output[0] else '-use-legacy' }} args: chdir: '{{ output_dir_abs.stdout }}' delegate_to: localhost diff --git a/ansible_collections/community/windows/tests/integration/targets/win_regmerge/files/settings1c.reg b/ansible_collections/community/windows/tests/integration/targets/win_regmerge/files/settings1c.reg new file mode 100644 index 000000000..26208be0c --- /dev/null +++ b/ansible_collections/community/windows/tests/integration/targets/win_regmerge/files/settings1c.reg @@ -0,0 +1,4 @@ +Windows Registry Editor Version 5.00 + +[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cow Corp\Moosic\ILikeToMooveIt] +"WorkingDirectory"="C:\\Program Files (x86)\\Cow Corp\\MadeUpFolder\\" diff --git a/ansible_collections/community/windows/tests/integration/targets/win_regmerge/files/settings3c.reg b/ansible_collections/community/windows/tests/integration/targets/win_regmerge/files/settings3c.reg new file mode 100644 index 000000000..a3ae31ba2 --- /dev/null +++ b/ansible_collections/community/windows/tests/integration/targets/win_regmerge/files/settings3c.reg @@ -0,0 +1,30 @@ +Windows Registry Editor Version 5.00 + +[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cow Corp\Moo Monitor] +"BIGCAT_HOME"="C:\\Bigcat97" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cow Corp\Moo Monitor\Tasks] + +[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cow Corp\Moo Monitor\Tasks\FishTank] +"ComponentID"=dword:00000000 +"Name"="Bigcat7" +"Version"="" +"Archive"="" +"InstallDate"=hex:00,00,00,00,00,00,00,00 +"Product"="FishTank" +"IsBusStopOnly"=dword:00000000 +"MaxEggCount"=dword:00000005 +"MaxEggDuration"=dword:00000001 +"StopTimeout"=dword:00001388 +"IsService"=dword:00000001 +"IsDCOMService"=dword:00000000 +"Command"="" +"NumberOfMoos"=dword:00000000 +"StatusOnShutdown"=hex:02,00,00,00 + +[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cow Corp\Moo Monitor\Tasks\FishTank\Counters] + +[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cow Corp\Moo Monitor\Tasks\FishTank\Udders] + +[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cow Corp\Moo Monitor\Tasks\FishTank\Hooves] + diff --git a/ansible_collections/community/windows/tests/integration/targets/win_regmerge/tasks/main.yml b/ansible_collections/community/windows/tests/integration/targets/win_regmerge/tasks/main.yml index af640eb93..e3a171ed6 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_regmerge/tasks/main.yml +++ b/ansible_collections/community/windows/tests/integration/targets/win_regmerge/tasks/main.yml @@ -130,4 +130,103 @@ - settings2.reg - settings3.reg +# re-run all tests above using 'content' parameter instead of 'path' using similar reg files but without the BOM + +# clear the area of the registry we are using for tests +- name: remove setting + ansible.windows.win_regedit: + key: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp' + state: absent + +# test 1 - basic test of changed behaviour +# merge in REG_SZ +- name: test 1 merge in a setting using 'content' + win_regmerge: + content: "{{ lookup('file', 'settings1c.reg') }}" + register: merge11_result + +- assert: + that: + - "merge11_result.changed == true" + +# re run the merge +- name: test 1 merge in the setting again using 'content' + win_regmerge: + content: "{{ lookup('file', 'settings1c.reg') }}" + register: merge12_result + +# without a compare to key, should always report changed +- assert: + that: + - "merge12_result.changed == true" +# assert changed false + +# prune reg key +- name: test 1 remove setting + ansible.windows.win_regedit: + key: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp' + state: absent + +# +# test 2, observe behaviour when compare_to param is set +# +- name: test 2 merge in a setting using 'content' + win_regmerge: + content: "{{ lookup('file', 'settings1c.reg') }}" + compare_to: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp\Moosic\ILikeToMooveIt' + register: merge21_result + +- assert: + that: + - "merge21_result.changed == true" + +# re run the merge +- name: test 2 merge in the setting again but with compare_key using 'content' + win_regmerge: + content: "{{ lookup('file', 'settings1c.reg') }}" + compare_to: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp\Moosic\ILikeToMooveIt' + register: merge22_result + +# with a compare to key, should now report not changed +- assert: + that: + - "merge22_result.changed == false" +# assert changed false + +# prune the contents of the registry from the parent of the compare key downwards +- name: test 2 clean up remove setting + ansible.windows.win_regedit: + key: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp' + state: absent + +# test 3 merge in more complex settings +- name: test 3 merge in a setting using 'content' + win_regmerge: + content: "{{ lookup('file', 'settings3c.reg') }}" + compare_to: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp\Moo Monitor' + register: merge31_result + +- assert: + that: + - "merge31_result.changed == true" + +# re run the merge +- name: test 3 merge in the setting again but with compare_key check using 'content' + win_regmerge: + content: "{{ lookup('file', 'settings3c.reg') }}" + compare_to: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp\Moo Monitor' + register: merge32_result + +# with a compare to key, should now report not changed +- assert: + that: + - "merge32_result.changed == false" +# assert changed false + +# prune the contents of the registry from the compare key downwards +- name: test 3 clean up remove setting + ansible.windows.win_regedit: + key: 'HKLM:\SOFTWARE\Wow6432Node\Cow Corp' + state: absent + # END OF win_regmerge tests diff --git a/ansible_collections/community/windows/tests/integration/targets/win_route/tasks/main.yml b/ansible_collections/community/windows/tests/integration/targets/win_route/tasks/main.yml index 4bbdee5b5..5e5a01adc 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_route/tasks/main.yml +++ b/ansible_collections/community/windows/tests/integration/targets/win_route/tasks/main.yml @@ -22,8 +22,6 @@ ansible.windows.win_shell: '[Environment]::OSVersion.Version -ge [Version]"6.3"' register: os -- name: Perform with os Windows 2012R2 or newer +- name: run all tasks + include_tasks: tests.yml when: os.stdout_lines[0] == "True" - block: - - name: run all tasks - include: tests.yml diff --git a/ansible_collections/community/windows/tests/integration/targets/win_scheduled_task/tasks/triggers.yml b/ansible_collections/community/windows/tests/integration/targets/win_scheduled_task/tasks/triggers.yml index eae42c98a..5055e107a 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_scheduled_task/tasks/triggers.yml +++ b/ansible_collections/community/windows/tests/integration/targets/win_scheduled_task/tasks/triggers.yml @@ -305,8 +305,7 @@ triggers: - type: registration repetition: - # TODO: change to dict in 2.12 as a list format is deprecated - - interval: PT1M + interval: PT1M duration: PT5M stop_at_duration_end: yes register: create_trigger_repetition_check @@ -322,9 +321,6 @@ assert: that: - create_trigger_repetition_check is changed - - create_trigger_repetition_check.deprecations|count == 1 - - create_trigger_repetition_check.deprecations[0].date == "2021-07-01" - - create_trigger_repetition_check.deprecations[0].msg == "repetition is a list, should be defined as a dict" - create_trigger_repetition_result_check.task_exists == True - create_trigger_repetition_result_check.triggers|count == 1 - create_trigger_repetition_result_check.triggers[0].type == "TASK_TRIGGER_MONTHLYDOW" diff --git a/ansible_collections/community/windows/tests/integration/targets/win_scoop/aliases b/ansible_collections/community/windows/tests/integration/targets/win_scoop/aliases index e2eacc2b6..3cf5b97e8 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_scoop/aliases +++ b/ansible_collections/community/windows/tests/integration/targets/win_scoop/aliases @@ -1,3 +1 @@ shippable/windows/group3 -skip/windows/2012 # Need pwsh 5+ -skip/windows/2012-R2 # Need pwsh 5+ diff --git a/ansible_collections/community/windows/tests/integration/targets/win_scoop_bucket/aliases b/ansible_collections/community/windows/tests/integration/targets/win_scoop_bucket/aliases index 9a9d0737d..423ce3910 100644 --- a/ansible_collections/community/windows/tests/integration/targets/win_scoop_bucket/aliases +++ b/ansible_collections/community/windows/tests/integration/targets/win_scoop_bucket/aliases @@ -1,3 +1 @@ shippable/windows/group2 -skip/windows/2012 # Need pwsh 5+ -skip/windows/2012-R2 # Need pwsh 5+ diff --git a/ansible_collections/community/windows/tests/requirements.yml b/ansible_collections/community/windows/tests/requirements.yml index 4f4960ebd..d3c5aea88 100644 --- a/ansible_collections/community/windows/tests/requirements.yml +++ b/ansible_collections/community/windows/tests/requirements.yml @@ -1,6 +1,6 @@ collections: -- name: ansible.windows -- name: chocolatey.chocolatey - # Chocolatey 1.3.0 broke compatibiltiy wtih WinPS 3 and 4 so we are stuck with 1.2.0 - # https://github.com/chocolatey/chocolatey-ansible/issues/96 - version: <1.3.0
\ No newline at end of file + - name: ansible.windows + - name: chocolatey.chocolatey + # Chocolatey 1.3.0 broke compatibiltiy wtih WinPS 3 and 4 so we are stuck with 1.2.0 + # https://github.com/chocolatey/chocolatey-ansible/issues/96 + version: <1.3.0 diff --git a/ansible_collections/community/windows/tests/sanity/ignore-2.12.txt b/ansible_collections/community/windows/tests/sanity/ignore-2.12.txt deleted file mode 100644 index 84d7bb121..000000000 --- a/ansible_collections/community/windows/tests/sanity/ignore-2.12.txt +++ /dev/null @@ -1,13 +0,0 @@ -plugins/modules/win_audit_rule.ps1 pslint:PSCustomUseLiteralPath -plugins/modules/win_rabbitmq_plugin.ps1 pslint:PSAvoidUsingInvokeExpression -plugins/modules/win_region.ps1 pslint:PSAvoidUsingEmptyCatchBlock # Keep -plugins/modules/win_regmerge.ps1 pslint:PSCustomUseLiteralPath -plugins/modules/win_robocopy.ps1 pslint:PSCustomUseLiteralPath -tests/integration/targets/win_audit_rule/library/test_get_audit_rule.ps1 pslint:PSCustomUseLiteralPath -tests/integration/targets/win_lineinfile/files/expectations/23_utf8_bom.txt shebang -tests/integration/targets/win_lineinfile/files/expectations/24_utf8_bom_line_added.txt shebang -tests/integration/targets/win_lineinfile/files/expectations/30_linebreaks_checksum_bad.txt line-endings -tests/integration/targets/win_psmodule/files/module/template.psd1 pslint!skip -tests/integration/targets/win_psmodule/files/module/template.psm1 pslint!skip -tests/integration/targets/win_psmodule/files/setup_modules.ps1 pslint:PSCustomUseLiteralPath -tests/integration/targets/win_regmerge/templates/win_line_ending.j2 line-endings diff --git a/ansible_collections/community/windows/tests/sanity/ignore-2.13.txt b/ansible_collections/community/windows/tests/sanity/ignore-2.13.txt deleted file mode 100644 index 84d7bb121..000000000 --- a/ansible_collections/community/windows/tests/sanity/ignore-2.13.txt +++ /dev/null @@ -1,13 +0,0 @@ -plugins/modules/win_audit_rule.ps1 pslint:PSCustomUseLiteralPath -plugins/modules/win_rabbitmq_plugin.ps1 pslint:PSAvoidUsingInvokeExpression -plugins/modules/win_region.ps1 pslint:PSAvoidUsingEmptyCatchBlock # Keep -plugins/modules/win_regmerge.ps1 pslint:PSCustomUseLiteralPath -plugins/modules/win_robocopy.ps1 pslint:PSCustomUseLiteralPath -tests/integration/targets/win_audit_rule/library/test_get_audit_rule.ps1 pslint:PSCustomUseLiteralPath -tests/integration/targets/win_lineinfile/files/expectations/23_utf8_bom.txt shebang -tests/integration/targets/win_lineinfile/files/expectations/24_utf8_bom_line_added.txt shebang -tests/integration/targets/win_lineinfile/files/expectations/30_linebreaks_checksum_bad.txt line-endings -tests/integration/targets/win_psmodule/files/module/template.psd1 pslint!skip -tests/integration/targets/win_psmodule/files/module/template.psm1 pslint!skip -tests/integration/targets/win_psmodule/files/setup_modules.ps1 pslint:PSCustomUseLiteralPath -tests/integration/targets/win_regmerge/templates/win_line_ending.j2 line-endings diff --git a/ansible_collections/community/windows/tests/sanity/ignore-2.14.txt b/ansible_collections/community/windows/tests/sanity/ignore-2.14.txt index 84d7bb121..82f6c2fac 100644 --- a/ansible_collections/community/windows/tests/sanity/ignore-2.14.txt +++ b/ansible_collections/community/windows/tests/sanity/ignore-2.14.txt @@ -1,13 +1,5 @@ -plugins/modules/win_audit_rule.ps1 pslint:PSCustomUseLiteralPath -plugins/modules/win_rabbitmq_plugin.ps1 pslint:PSAvoidUsingInvokeExpression -plugins/modules/win_region.ps1 pslint:PSAvoidUsingEmptyCatchBlock # Keep -plugins/modules/win_regmerge.ps1 pslint:PSCustomUseLiteralPath -plugins/modules/win_robocopy.ps1 pslint:PSCustomUseLiteralPath -tests/integration/targets/win_audit_rule/library/test_get_audit_rule.ps1 pslint:PSCustomUseLiteralPath +plugins/modules/win_audit_rule.ps1 pslint:PSCustomUseLiteralPath # Unsure if we can fix this or not so keep ignoring for now tests/integration/targets/win_lineinfile/files/expectations/23_utf8_bom.txt shebang tests/integration/targets/win_lineinfile/files/expectations/24_utf8_bom_line_added.txt shebang tests/integration/targets/win_lineinfile/files/expectations/30_linebreaks_checksum_bad.txt line-endings -tests/integration/targets/win_psmodule/files/module/template.psd1 pslint!skip -tests/integration/targets/win_psmodule/files/module/template.psm1 pslint!skip -tests/integration/targets/win_psmodule/files/setup_modules.ps1 pslint:PSCustomUseLiteralPath tests/integration/targets/win_regmerge/templates/win_line_ending.j2 line-endings diff --git a/ansible_collections/community/windows/tests/sanity/ignore-2.15.txt b/ansible_collections/community/windows/tests/sanity/ignore-2.15.txt index 84d7bb121..82f6c2fac 100644 --- a/ansible_collections/community/windows/tests/sanity/ignore-2.15.txt +++ b/ansible_collections/community/windows/tests/sanity/ignore-2.15.txt @@ -1,13 +1,5 @@ -plugins/modules/win_audit_rule.ps1 pslint:PSCustomUseLiteralPath -plugins/modules/win_rabbitmq_plugin.ps1 pslint:PSAvoidUsingInvokeExpression -plugins/modules/win_region.ps1 pslint:PSAvoidUsingEmptyCatchBlock # Keep -plugins/modules/win_regmerge.ps1 pslint:PSCustomUseLiteralPath -plugins/modules/win_robocopy.ps1 pslint:PSCustomUseLiteralPath -tests/integration/targets/win_audit_rule/library/test_get_audit_rule.ps1 pslint:PSCustomUseLiteralPath +plugins/modules/win_audit_rule.ps1 pslint:PSCustomUseLiteralPath # Unsure if we can fix this or not so keep ignoring for now tests/integration/targets/win_lineinfile/files/expectations/23_utf8_bom.txt shebang tests/integration/targets/win_lineinfile/files/expectations/24_utf8_bom_line_added.txt shebang tests/integration/targets/win_lineinfile/files/expectations/30_linebreaks_checksum_bad.txt line-endings -tests/integration/targets/win_psmodule/files/module/template.psd1 pslint!skip -tests/integration/targets/win_psmodule/files/module/template.psm1 pslint!skip -tests/integration/targets/win_psmodule/files/setup_modules.ps1 pslint:PSCustomUseLiteralPath tests/integration/targets/win_regmerge/templates/win_line_ending.j2 line-endings diff --git a/ansible_collections/community/windows/tests/sanity/ignore-2.16.txt b/ansible_collections/community/windows/tests/sanity/ignore-2.16.txt index 84d7bb121..82f6c2fac 100644 --- a/ansible_collections/community/windows/tests/sanity/ignore-2.16.txt +++ b/ansible_collections/community/windows/tests/sanity/ignore-2.16.txt @@ -1,13 +1,5 @@ -plugins/modules/win_audit_rule.ps1 pslint:PSCustomUseLiteralPath -plugins/modules/win_rabbitmq_plugin.ps1 pslint:PSAvoidUsingInvokeExpression -plugins/modules/win_region.ps1 pslint:PSAvoidUsingEmptyCatchBlock # Keep -plugins/modules/win_regmerge.ps1 pslint:PSCustomUseLiteralPath -plugins/modules/win_robocopy.ps1 pslint:PSCustomUseLiteralPath -tests/integration/targets/win_audit_rule/library/test_get_audit_rule.ps1 pslint:PSCustomUseLiteralPath +plugins/modules/win_audit_rule.ps1 pslint:PSCustomUseLiteralPath # Unsure if we can fix this or not so keep ignoring for now tests/integration/targets/win_lineinfile/files/expectations/23_utf8_bom.txt shebang tests/integration/targets/win_lineinfile/files/expectations/24_utf8_bom_line_added.txt shebang tests/integration/targets/win_lineinfile/files/expectations/30_linebreaks_checksum_bad.txt line-endings -tests/integration/targets/win_psmodule/files/module/template.psd1 pslint!skip -tests/integration/targets/win_psmodule/files/module/template.psm1 pslint!skip -tests/integration/targets/win_psmodule/files/setup_modules.ps1 pslint:PSCustomUseLiteralPath tests/integration/targets/win_regmerge/templates/win_line_ending.j2 line-endings diff --git a/ansible_collections/community/windows/tests/sanity/ignore-2.17.txt b/ansible_collections/community/windows/tests/sanity/ignore-2.17.txt new file mode 100644 index 000000000..82f6c2fac --- /dev/null +++ b/ansible_collections/community/windows/tests/sanity/ignore-2.17.txt @@ -0,0 +1,5 @@ +plugins/modules/win_audit_rule.ps1 pslint:PSCustomUseLiteralPath # Unsure if we can fix this or not so keep ignoring for now +tests/integration/targets/win_lineinfile/files/expectations/23_utf8_bom.txt shebang +tests/integration/targets/win_lineinfile/files/expectations/24_utf8_bom_line_added.txt shebang +tests/integration/targets/win_lineinfile/files/expectations/30_linebreaks_checksum_bad.txt line-endings +tests/integration/targets/win_regmerge/templates/win_line_ending.j2 line-endings diff --git a/ansible_collections/community/windows/tests/unit/compat/__init__.py b/ansible_collections/community/windows/tests/unit/compat/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/ansible_collections/community/windows/tests/unit/compat/__init__.py +++ /dev/null diff --git a/ansible_collections/community/windows/tests/unit/compat/mock.py b/ansible_collections/community/windows/tests/unit/compat/mock.py deleted file mode 100644 index 3dcd2687f..000000000 --- a/ansible_collections/community/windows/tests/unit/compat/mock.py +++ /dev/null @@ -1,42 +0,0 @@ -# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com> -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -''' -Compat module for Python3.x's unittest.mock module -''' - -# Python 2.7 - -# Note: Could use the pypi mock library on python3.x as well as python2.x. It -# is the same as the python3 stdlib mock library - -try: - # Allow wildcard import because we really do want to import all of mock's - # symbols into this compat shim - # pylint: disable=wildcard-import,unused-wildcard-import - from unittest.mock import * -except ImportError: - # Python 2 - # pylint: disable=wildcard-import,unused-wildcard-import - try: - from mock import * - except ImportError: - print('You need the mock library installed on python2.x to run tests') diff --git a/ansible_collections/community/windows/tests/unit/mock/__init__.py b/ansible_collections/community/windows/tests/unit/mock/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/ansible_collections/community/windows/tests/unit/mock/__init__.py +++ /dev/null diff --git a/ansible_collections/community/windows/tests/unit/mock/loader.py b/ansible_collections/community/windows/tests/unit/mock/loader.py deleted file mode 100644 index e5dff78c1..000000000 --- a/ansible_collections/community/windows/tests/unit/mock/loader.py +++ /dev/null @@ -1,116 +0,0 @@ -# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com> -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -import os - -from ansible.errors import AnsibleParserError -from ansible.parsing.dataloader import DataLoader -from ansible.module_utils._text import to_bytes, to_text - - -class DictDataLoader(DataLoader): - - def __init__(self, file_mapping=None): - file_mapping = {} if file_mapping is None else file_mapping - assert type(file_mapping) == dict - - super(DictDataLoader, self).__init__() - - self._file_mapping = file_mapping - self._build_known_directories() - self._vault_secrets = None - - def load_from_file(self, path, cache=True, unsafe=False): - path = to_text(path) - if path in self._file_mapping: - return self.load(self._file_mapping[path], path) - return None - - # TODO: the real _get_file_contents returns a bytestring, so we actually convert the - # unicode/text it's created with to utf-8 - def _get_file_contents(self, file_name): - path = to_text(file_name) - if path in self._file_mapping: - return (to_bytes(self._file_mapping[path]), False) - else: - raise AnsibleParserError("file not found: %s" % path) - - def path_exists(self, path): - path = to_text(path) - return path in self._file_mapping or path in self._known_directories - - def is_file(self, path): - path = to_text(path) - return path in self._file_mapping - - def is_directory(self, path): - path = to_text(path) - return path in self._known_directories - - def list_directory(self, path): - ret = [] - path = to_text(path) - for x in (list(self._file_mapping.keys()) + self._known_directories): - if x.startswith(path): - if os.path.dirname(x) == path: - ret.append(os.path.basename(x)) - return ret - - def is_executable(self, path): - # FIXME: figure out a way to make paths return true for this - return False - - def _add_known_directory(self, directory): - if directory not in self._known_directories: - self._known_directories.append(directory) - - def _build_known_directories(self): - self._known_directories = [] - for path in self._file_mapping: - dirname = os.path.dirname(path) - while dirname not in ('/', ''): - self._add_known_directory(dirname) - dirname = os.path.dirname(dirname) - - def push(self, path, content): - rebuild_dirs = False - if path not in self._file_mapping: - rebuild_dirs = True - - self._file_mapping[path] = content - - if rebuild_dirs: - self._build_known_directories() - - def pop(self, path): - if path in self._file_mapping: - del self._file_mapping[path] - self._build_known_directories() - - def clear(self): - self._file_mapping = dict() - self._known_directories = [] - - def get_basedir(self): - return os.getcwd() - - def set_vault_secrets(self, vault_secrets): - self._vault_secrets = vault_secrets diff --git a/ansible_collections/community/windows/tests/unit/mock/path.py b/ansible_collections/community/windows/tests/unit/mock/path.py deleted file mode 100644 index 54858b13d..000000000 --- a/ansible_collections/community/windows/tests/unit/mock/path.py +++ /dev/null @@ -1,8 +0,0 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from ansible_collections.ansible.windows.tests.unit.compat.mock import MagicMock -from ansible.utils.path import unfrackpath - - -mock_unfrackpath_noop = MagicMock(spec_set=unfrackpath, side_effect=lambda x, *args, **kwargs: x) diff --git a/ansible_collections/community/windows/tests/unit/mock/procenv.py b/ansible_collections/community/windows/tests/unit/mock/procenv.py deleted file mode 100644 index 3cb1b5b2f..000000000 --- a/ansible_collections/community/windows/tests/unit/mock/procenv.py +++ /dev/null @@ -1,90 +0,0 @@ -# (c) 2016, Matt Davis <mdavis@ansible.com> -# (c) 2016, Toshio Kuratomi <tkuratomi@ansible.com> -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -import sys -import json - -from contextlib import contextmanager -from io import BytesIO, StringIO -from ansible_collections.community.windows.tests.unit.compat import unittest -from ansible.module_utils.six import PY3 -from ansible.module_utils._text import to_bytes - - -@contextmanager -def swap_stdin_and_argv(stdin_data='', argv_data=tuple()): - """ - context manager that temporarily masks the test runner's values for stdin and argv - """ - real_stdin = sys.stdin - real_argv = sys.argv - - if PY3: - fake_stream = StringIO(stdin_data) - fake_stream.buffer = BytesIO(to_bytes(stdin_data)) - else: - fake_stream = BytesIO(to_bytes(stdin_data)) - - try: - sys.stdin = fake_stream - sys.argv = argv_data - - yield - finally: - sys.stdin = real_stdin - sys.argv = real_argv - - -@contextmanager -def swap_stdout(): - """ - context manager that temporarily replaces stdout for tests that need to verify output - """ - old_stdout = sys.stdout - - if PY3: - fake_stream = StringIO() - else: - fake_stream = BytesIO() - - try: - sys.stdout = fake_stream - - yield fake_stream - finally: - sys.stdout = old_stdout - - -class ModuleTestCase(unittest.TestCase): - def setUp(self, module_args=None): - if module_args is None: - module_args = {'_ansible_remote_tmp': '/tmp', '_ansible_keep_remote_files': False} - - args = json.dumps(dict(ANSIBLE_MODULE_ARGS=module_args)) - - # unittest doesn't have a clean place to use a context manager, so we have to enter/exit manually - self.stdin_swap = swap_stdin_and_argv(stdin_data=args) - self.stdin_swap.__enter__() - - def tearDown(self): - # unittest doesn't have a clean place to use a context manager, so we have to enter/exit manually - self.stdin_swap.__exit__(None, None, None) diff --git a/ansible_collections/community/windows/tests/unit/mock/vault_helper.py b/ansible_collections/community/windows/tests/unit/mock/vault_helper.py deleted file mode 100644 index dcce9c784..000000000 --- a/ansible_collections/community/windows/tests/unit/mock/vault_helper.py +++ /dev/null @@ -1,39 +0,0 @@ -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from ansible.module_utils._text import to_bytes - -from ansible.parsing.vault import VaultSecret - - -class TextVaultSecret(VaultSecret): - '''A secret piece of text. ie, a password. Tracks text encoding. - - The text encoding of the text may not be the default text encoding so - we keep track of the encoding so we encode it to the same bytes.''' - - def __init__(self, text, encoding=None, errors=None, _bytes=None): - super(TextVaultSecret, self).__init__() - self.text = text - self.encoding = encoding or 'utf-8' - self._bytes = _bytes - self.errors = errors or 'strict' - - @property - def bytes(self): - '''The text encoded with encoding, unless we specifically set _bytes.''' - return self._bytes or to_bytes(self.text, encoding=self.encoding, errors=self.errors) diff --git a/ansible_collections/community/windows/tests/unit/mock/yaml_helper.py b/ansible_collections/community/windows/tests/unit/mock/yaml_helper.py deleted file mode 100644 index 1ef172159..000000000 --- a/ansible_collections/community/windows/tests/unit/mock/yaml_helper.py +++ /dev/null @@ -1,124 +0,0 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -import io -import yaml - -from ansible.module_utils.six import PY3 -from ansible.parsing.yaml.loader import AnsibleLoader -from ansible.parsing.yaml.dumper import AnsibleDumper - - -class YamlTestUtils(object): - """Mixin class to combine with a unittest.TestCase subclass.""" - def _loader(self, stream): - """Vault related tests will want to override this. - - Vault cases should setup a AnsibleLoader that has the vault password.""" - return AnsibleLoader(stream) - - def _dump_stream(self, obj, stream, dumper=None): - """Dump to a py2-unicode or py3-string stream.""" - if PY3: - return yaml.dump(obj, stream, Dumper=dumper) - else: - return yaml.dump(obj, stream, Dumper=dumper, encoding=None) - - def _dump_string(self, obj, dumper=None): - """Dump to a py2-unicode or py3-string""" - if PY3: - return yaml.dump(obj, Dumper=dumper) - else: - return yaml.dump(obj, Dumper=dumper, encoding=None) - - def _dump_load_cycle(self, obj): - # Each pass though a dump or load revs the 'generation' - # obj to yaml string - string_from_object_dump = self._dump_string(obj, dumper=AnsibleDumper) - - # wrap a stream/file like StringIO around that yaml - stream_from_object_dump = io.StringIO(string_from_object_dump) - loader = self._loader(stream_from_object_dump) - # load the yaml stream to create a new instance of the object (gen 2) - obj_2 = loader.get_data() - - # dump the gen 2 objects directory to strings - string_from_object_dump_2 = self._dump_string(obj_2, - dumper=AnsibleDumper) - - # The gen 1 and gen 2 yaml strings - self.assertEqual(string_from_object_dump, string_from_object_dump_2) - # the gen 1 (orig) and gen 2 py object - self.assertEqual(obj, obj_2) - - # again! gen 3... load strings into py objects - stream_3 = io.StringIO(string_from_object_dump_2) - loader_3 = self._loader(stream_3) - obj_3 = loader_3.get_data() - - string_from_object_dump_3 = self._dump_string(obj_3, dumper=AnsibleDumper) - - self.assertEqual(obj, obj_3) - # should be transitive, but... - self.assertEqual(obj_2, obj_3) - self.assertEqual(string_from_object_dump, string_from_object_dump_3) - - def _old_dump_load_cycle(self, obj): - '''Dump the passed in object to yaml, load it back up, dump again, compare.''' - stream = io.StringIO() - - yaml_string = self._dump_string(obj, dumper=AnsibleDumper) - self._dump_stream(obj, stream, dumper=AnsibleDumper) - - yaml_string_from_stream = stream.getvalue() - - # reset stream - stream.seek(0) - - loader = self._loader(stream) - # loader = AnsibleLoader(stream, vault_password=self.vault_password) - obj_from_stream = loader.get_data() - - stream_from_string = io.StringIO(yaml_string) - loader2 = self._loader(stream_from_string) - # loader2 = AnsibleLoader(stream_from_string, vault_password=self.vault_password) - obj_from_string = loader2.get_data() - - stream_obj_from_stream = io.StringIO() - stream_obj_from_string = io.StringIO() - - if PY3: - yaml.dump(obj_from_stream, stream_obj_from_stream, Dumper=AnsibleDumper) - yaml.dump(obj_from_stream, stream_obj_from_string, Dumper=AnsibleDumper) - else: - yaml.dump(obj_from_stream, stream_obj_from_stream, Dumper=AnsibleDumper, encoding=None) - yaml.dump(obj_from_stream, stream_obj_from_string, Dumper=AnsibleDumper, encoding=None) - - yaml_string_stream_obj_from_stream = stream_obj_from_stream.getvalue() - yaml_string_stream_obj_from_string = stream_obj_from_string.getvalue() - - stream_obj_from_stream.seek(0) - stream_obj_from_string.seek(0) - - if PY3: - yaml_string_obj_from_stream = yaml.dump(obj_from_stream, Dumper=AnsibleDumper) - yaml_string_obj_from_string = yaml.dump(obj_from_string, Dumper=AnsibleDumper) - else: - yaml_string_obj_from_stream = yaml.dump(obj_from_stream, Dumper=AnsibleDumper, encoding=None) - yaml_string_obj_from_string = yaml.dump(obj_from_string, Dumper=AnsibleDumper, encoding=None) - - assert yaml_string == yaml_string_obj_from_stream - assert yaml_string == yaml_string_obj_from_stream == yaml_string_obj_from_string - assert (yaml_string == yaml_string_obj_from_stream == yaml_string_obj_from_string == yaml_string_stream_obj_from_stream == - yaml_string_stream_obj_from_string) - assert obj == obj_from_stream - assert obj == obj_from_string - assert obj == yaml_string_obj_from_stream - assert obj == yaml_string_obj_from_string - assert obj == obj_from_stream == obj_from_string == yaml_string_obj_from_stream == yaml_string_obj_from_string - return {'obj': obj, - 'yaml_string': yaml_string, - 'yaml_string_from_stream': yaml_string_from_stream, - 'obj_from_stream': obj_from_stream, - 'obj_from_string': obj_from_string, - 'yaml_string_obj_from_string': yaml_string_obj_from_string} diff --git a/ansible_collections/community/windows/tests/unit/modules/__init__.py b/ansible_collections/community/windows/tests/unit/modules/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/ansible_collections/community/windows/tests/unit/modules/__init__.py +++ /dev/null diff --git a/ansible_collections/community/windows/tests/unit/modules/utils.py b/ansible_collections/community/windows/tests/unit/modules/utils.py deleted file mode 100644 index bc627df64..000000000 --- a/ansible_collections/community/windows/tests/unit/modules/utils.py +++ /dev/null @@ -1,50 +0,0 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -import json - -from ansible_collections.community.windows.tests.unit.compat import unittest -from ansible_collections.community.windows.tests.unit.compat.mock import patch -from ansible.module_utils import basic -from ansible.module_utils._text import to_bytes - - -def set_module_args(args): - if '_ansible_remote_tmp' not in args: - args['_ansible_remote_tmp'] = '/tmp' - if '_ansible_keep_remote_files' not in args: - args['_ansible_keep_remote_files'] = False - - args = json.dumps({'ANSIBLE_MODULE_ARGS': args}) - basic._ANSIBLE_ARGS = to_bytes(args) - - -class AnsibleExitJson(Exception): - pass - - -class AnsibleFailJson(Exception): - pass - - -def exit_json(*args, **kwargs): - if 'changed' not in kwargs: - kwargs['changed'] = False - raise AnsibleExitJson(kwargs) - - -def fail_json(*args, **kwargs): - kwargs['failed'] = True - raise AnsibleFailJson(kwargs) - - -class ModuleTestCase(unittest.TestCase): - - def setUp(self): - self.mock_module = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json) - self.mock_module.start() - self.mock_sleep = patch('time.sleep') - self.mock_sleep.start() - set_module_args({}) - self.addCleanup(self.mock_module.stop) - self.addCleanup(self.mock_sleep.stop) diff --git a/ansible_collections/community/windows/tests/unit/plugins/lookup/fixtures/avi.json b/ansible_collections/community/windows/tests/unit/plugins/lookup/fixtures/avi.json deleted file mode 100644 index ae89ca689..000000000 --- a/ansible_collections/community/windows/tests/unit/plugins/lookup/fixtures/avi.json +++ /dev/null @@ -1,104 +0,0 @@ -{ - "mock_single_obj": { - "_last_modified": "", - "cloud_ref": "https://192.0.2.132/api/cloud/cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "dhcp_enabled": true, - "exclude_discovered_subnets": false, - "name": "PG-123", - "synced_from_se": true, - "tenant_ref": "https://192.0.2.132/api/tenant/admin", - "url": "https://192.0.2.132/api/network/dvportgroup-2084-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "uuid": "dvportgroup-2084-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "vcenter_dvs": true, - "vimgrnw_ref": "https://192.0.2.132/api/vimgrnwruntime/dvportgroup-2084-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "vrf_context_ref": "https://192.0.2.132/api/vrfcontext/vrfcontext-31f1b55f-319c-44eb-862f-69d79ffdf295" - }, - "mock_multiple_obj": { - "results": [ - { - "_last_modified": "", - "cloud_ref": "https://192.0.2.132/api/cloud/cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "dhcp_enabled": true, - "exclude_discovered_subnets": false, - "name": "J-PG-0682", - "synced_from_se": true, - "tenant_ref": "https://192.0.2.132/api/tenant/admin", - "url": "https://192.0.2.132/api/network/dvportgroup-2084-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "uuid": "dvportgroup-2084-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "vcenter_dvs": true, - "vimgrnw_ref": "https://192.0.2.132/api/vimgrnwruntime/dvportgroup-2084-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "vrf_context_ref": "https://192.0.2.132/api/vrfcontext/vrfcontext-31f1b55f-319c-44eb-862f-69d79ffdf295" - }, - { - "_last_modified": "", - "cloud_ref": "https://192.0.2.132/api/cloud/cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "dhcp_enabled": true, - "exclude_discovered_subnets": false, - "name": "J-PG-0231", - "synced_from_se": true, - "tenant_ref": "https://192.0.2.132/api/tenant/admin", - "url": "https://192.0.2.132/api/network/dvportgroup-1627-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "uuid": "dvportgroup-1627-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "vcenter_dvs": true, - "vimgrnw_ref": "https://192.0.2.132/api/vimgrnwruntime/dvportgroup-1627-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "vrf_context_ref": "https://192.0.2.132/api/vrfcontext/vrfcontext-31f1b55f-319c-44eb-862f-69d79ffdf295" - }, - { - "_last_modified": "", - "cloud_ref": "https://192.0.2.132/api/cloud/cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "dhcp_enabled": true, - "exclude_discovered_subnets": false, - "name": "J-PG-0535", - "synced_from_se": true, - "tenant_ref": "https://192.0.2.132/api/tenant/admin", - "url": "https://192.0.2.132/api/network/dvportgroup-1934-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "uuid": "dvportgroup-1934-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "vcenter_dvs": true, - "vimgrnw_ref": "https://192.0.2.132/api/vimgrnwruntime/dvportgroup-1934-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "vrf_context_ref": "https://192.0.2.132/api/vrfcontext/vrfcontext-31f1b55f-319c-44eb-862f-69d79ffdf295" - }, - { - "_last_modified": "", - "cloud_ref": "https://192.0.2.132/api/cloud/cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "dhcp_enabled": true, - "exclude_discovered_subnets": false, - "name": "J-PG-0094", - "synced_from_se": true, - "tenant_ref": "https://192.0.2.132/api/tenant/admin", - "url": "https://192.0.2.132/api/network/dvportgroup-1458-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "uuid": "dvportgroup-1458-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "vcenter_dvs": true, - "vimgrnw_ref": "https://192.0.2.132/api/vimgrnwruntime/dvportgroup-1458-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "vrf_context_ref": "https://192.0.2.132/api/vrfcontext/vrfcontext-31f1b55f-319c-44eb-862f-69d79ffdf295" - }, - { - "_last_modified": "", - "cloud_ref": "https://192.0.2.132/api/cloud/cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "dhcp_enabled": true, - "exclude_discovered_subnets": false, - "name": "J-PG-0437", - "synced_from_se": true, - "tenant_ref": "https://192.0.2.132/api/tenant/admin", - "url": "https://192.0.2.132/api/network/dvportgroup-1836-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "uuid": "dvportgroup-1836-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "vcenter_dvs": true, - "vimgrnw_ref": "https://192.0.2.132/api/vimgrnwruntime/dvportgroup-1836-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "vrf_context_ref": "https://192.0.2.132/api/vrfcontext/vrfcontext-31f1b55f-319c-44eb-862f-69d79ffdf295" - }, - { - "_last_modified": "", - "cloud_ref": "https://192.0.2.132/api/cloud/cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "dhcp_enabled": true, - "exclude_discovered_subnets": false, - "name": "J-PG-0673", - "synced_from_se": true, - "tenant_ref": "https://192.0.2.132/api/tenant/admin", - "url": "https://192.0.2.132/api/network/dvportgroup-2075-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "uuid": "dvportgroup-2075-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "vcenter_dvs": true, - "vimgrnw_ref": "https://192.0.2.132/api/vimgrnwruntime/dvportgroup-2075-cloud-4d063be1-99c2-44cf-8b28-977bd970524c", - "vrf_context_ref": "https://192.0.2.132/api/vrfcontext/vrfcontext-31f1b55f-319c-44eb-862f-69d79ffdf295" - } - ] - } -} diff --git a/ansible_collections/community/windows/tests/unit/plugins/lookup/test_laps_password.py b/ansible_collections/community/windows/tests/unit/plugins/lookup/test_laps_password.py index 29e2b938a..d15fc109f 100644 --- a/ansible_collections/community/windows/tests/unit/plugins/lookup/test_laps_password.py +++ b/ansible_collections/community/windows/tests/unit/plugins/lookup/test_laps_password.py @@ -10,8 +10,8 @@ import os import platform import pytest import sys +from unittest.mock import MagicMock -from ansible_collections.community.windows.tests.unit.compat.mock import MagicMock from ansible.errors import AnsibleLookupError from ansible.plugins.loader import lookup_loader diff --git a/ansible_collections/community/windows/tests/utils/shippable/lint.sh b/ansible_collections/community/windows/tests/utils/shippable/lint.sh new file mode 100755 index 000000000..12b5b4cd2 --- /dev/null +++ b/ansible_collections/community/windows/tests/utils/shippable/lint.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -o pipefail -eux + +# This is aligned with the galaxy-importer used by AH +# https://github.com/ansible/galaxy-importer/blob/d4b5e6d12088ba452f129f4824bd049be5543358/setup.cfg#L22C4-L22C33 +python -m pip install \ + 'ansible-lint>=6.2.2,<=6.14.3' + +ansible-lint |