summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLee Garrett <lgarrett@rocketjump.eu>2021-11-04 16:41:17 +0100
committerLee Garrett <lgarrett@rocketjump.eu>2021-11-04 16:41:17 +0100
commit13e2c2e94d3559b85a7d813d98e9835b891b0a9f (patch)
treeca70a2b7963bb6dc05327d9c1169e5cc97d7f8aa /test
parent64aab4bd2d3ded02da538beb94a4a7fbf7781699 (diff)
downloaddebian-ansible-core-13e2c2e94d3559b85a7d813d98e9835b891b0a9f.zip
New upstream version 2.11.6
Diffstat (limited to 'test')
-rw-r--r--test/integration/targets/ansible-galaxy-collection/tasks/install.yml32
-rw-r--r--test/integration/targets/ansible-galaxy-collection/tasks/main.yml3
-rw-r--r--test/integration/targets/ansible-galaxy-collection/tasks/verify.yml34
-rw-r--r--test/integration/targets/ansible-galaxy-collection/templates/ansible.cfg.j25
-rw-r--r--test/integration/targets/module_utils_Ansible.ModuleUtils.AddType/library/add_type_test.ps123
-rw-r--r--test/integration/targets/roles_arg_spec/roles/empty_argspec/meta/argument_specs.yml2
-rw-r--r--test/integration/targets/roles_arg_spec/roles/empty_argspec/tasks/main.yml3
-rw-r--r--test/integration/targets/roles_arg_spec/roles/empty_file/meta/argument_specs.yml1
-rw-r--r--test/integration/targets/roles_arg_spec/roles/empty_file/tasks/main.yml3
-rw-r--r--test/integration/targets/roles_arg_spec/test.yml16
-rwxr-xr-xtest/lib/ansible_test/_data/sanity/pslint/pslint.ps113
-rw-r--r--test/units/module_utils/test_connection.py22
12 files changed, 137 insertions, 20 deletions
diff --git a/test/integration/targets/ansible-galaxy-collection/tasks/install.yml b/test/integration/targets/ansible-galaxy-collection/tasks/install.yml
index 66d79e59..7d66be2f 100644
--- a/test/integration/targets/ansible-galaxy-collection/tasks/install.yml
+++ b/test/integration/targets/ansible-galaxy-collection/tasks/install.yml
@@ -4,6 +4,38 @@
path: '{{ galaxy_dir }}/ansible_collections'
state: directory
+- name: install simple collection from first accessible server
+ command: ansible-galaxy collection install namespace1.name1 {{ galaxy_verbosity }}
+ environment:
+ ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
+ register: from_first_good_server
+
+- name: get installed files of install simple collection from first good server
+ find:
+ path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1'
+ file_type: file
+ register: install_normal_files
+
+- name: get the manifest of install simple collection from first good server
+ slurp:
+ path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json'
+ register: install_normal_manifest
+
+- name: assert install simple collection from first good server
+ assert:
+ that:
+ - '"Installing ''namespace1.name1:1.0.9'' to" in from_first_good_server.stdout'
+ - install_normal_files.files | length == 3
+ - install_normal_files.files[0].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
+ - install_normal_files.files[1].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
+ - install_normal_files.files[2].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
+ - (install_normal_manifest.content | b64decode | from_json).collection_info.version == '1.0.9'
+
+- name: Remove the collection
+ file:
+ path: '{{ galaxy_dir }}/ansible_collections/namespace1'
+ state: absent
+
- name: install simple collection with implicit path - {{ test_name }}
command: ansible-galaxy collection install namespace1.name1 -s '{{ test_name }}' {{ galaxy_verbosity }}
environment:
diff --git a/test/integration/targets/ansible-galaxy-collection/tasks/main.yml b/test/integration/targets/ansible-galaxy-collection/tasks/main.yml
index a536a720..0f6af191 100644
--- a/test/integration/targets/ansible-galaxy-collection/tasks/main.yml
+++ b/test/integration/targets/ansible-galaxy-collection/tasks/main.yml
@@ -176,9 +176,10 @@
environment:
ANSIBLE_CONFIG: '{{ galaxy_dir }}/ansible.cfg'
vars:
+ test_api_fallback: 'pulp_v2'
+ test_api_fallback_versions: 'v1, v2'
test_name: 'galaxy_ng'
test_server: '{{ galaxy_ng_server }}'
- vX: "v3/"
- name: run ansible-galaxy collection list tests
include_tasks: list.yml
diff --git a/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml b/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml
index eacb8d6b..8bf39577 100644
--- a/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml
+++ b/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml
@@ -25,12 +25,24 @@
"ERROR! 'file' type is not supported. The format namespace.name is expected." in verify.stderr
- name: install the collection from the server
- command: ansible-galaxy collection install ansible_test.verify:1.0.0
+ command: ansible-galaxy collection install ansible_test.verify:1.0.0 -s {{ test_api_fallback }} {{ galaxy_verbosity }}
environment:
ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}'
+- name: verify the collection against the first valid server
+ command: ansible-galaxy collection verify ansible_test.verify:1.0.0 -vvv {{ galaxy_verbosity }}
+ environment:
+ ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}'
+ register: verify
+
+- assert:
+ that:
+ - verify is success
+ - >-
+ "Found API version '{{ test_api_fallback_versions }}' with Galaxy server {{ test_api_fallback }}" in verify.stdout
+
- name: verify the installed collection against the server
- command: ansible-galaxy collection verify ansible_test.verify:1.0.0
+ command: ansible-galaxy collection verify ansible_test.verify:1.0.0 -s {{ test_name }} {{ galaxy_verbosity }}
environment:
ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}'
register: verify
@@ -41,12 +53,12 @@
- "'Collection ansible_test.verify contains modified content' not in verify.stdout"
- name: verify the installed collection against the server, with unspecified version in CLI
- command: ansible-galaxy collection verify ansible_test.verify
+ command: ansible-galaxy collection verify ansible_test.verify -s {{ test_name }} {{ galaxy_verbosity }}
environment:
ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}'
- name: verify a collection that doesn't appear to be installed
- command: ansible-galaxy collection verify ansible_test.verify:1.0.0
+ command: ansible-galaxy collection verify ansible_test.verify:1.0.0 -s {{ test_name }} {{ galaxy_verbosity }}
register: verify
failed_when: verify.rc == 0
@@ -82,7 +94,7 @@
chdir: '{{ galaxy_dir }}'
- name: verify a version of a collection that isn't installed
- command: ansible-galaxy collection verify ansible_test.verify:2.0.0
+ command: ansible-galaxy collection verify ansible_test.verify:2.0.0 -s {{ test_name }} {{ galaxy_verbosity }}
environment:
ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}'
register: verify
@@ -94,12 +106,12 @@
- '"ansible_test.verify has the version ''1.0.0'' but is being compared to ''2.0.0''" in verify.stdout'
- name: install the new version from the server
- command: ansible-galaxy collection install ansible_test.verify:2.0.0 --force
+ command: ansible-galaxy collection install ansible_test.verify:2.0.0 --force -s {{ test_name }} {{ galaxy_verbosity }}
environment:
ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}'
- name: verify the installed collection against the server
- command: ansible-galaxy collection verify ansible_test.verify:2.0.0
+ command: ansible-galaxy collection verify ansible_test.verify:2.0.0 -s {{ test_name }} {{ galaxy_verbosity }}
environment:
ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}'
register: verify
@@ -145,7 +157,7 @@
- "updated_file.stat.checksum != file.stat.checksum"
- name: test verifying checksumes of the modified collection
- command: ansible-galaxy collection verify ansible_test.verify:2.0.0
+ command: ansible-galaxy collection verify ansible_test.verify:2.0.0 -s {{ test_name }} {{ galaxy_verbosity }}
register: verify
environment:
ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}'
@@ -165,7 +177,7 @@
diff: true
- name: ensure a modified FILES.json is validated
- command: ansible-galaxy collection verify ansible_test.verify:2.0.0
+ command: ansible-galaxy collection verify ansible_test.verify:2.0.0 -s {{ test_name }} {{ galaxy_verbosity }}
register: verify
environment:
ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}'
@@ -189,7 +201,7 @@
line: ' "chksum_sha256": "{{ manifest_info.stat.checksum }}",'
- name: ensure the MANIFEST.json is validated against the uncorrupted file from the server
- command: ansible-galaxy collection verify ansible_test.verify:2.0.0
+ command: ansible-galaxy collection verify ansible_test.verify:2.0.0 -s {{ test_name }} {{ galaxy_verbosity }}
register: verify
environment:
ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}'
@@ -219,7 +231,7 @@
dest: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/galaxy.yml'
- name: test we only verify collections containing a MANIFEST.json with the version on the server
- command: ansible-galaxy collection verify ansible_test.verify:2.0.0
+ command: ansible-galaxy collection verify ansible_test.verify:2.0.0 -s {{ test_name }} {{ galaxy_verbosity }}
register: verify
environment:
ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}'
diff --git a/test/integration/targets/ansible-galaxy-collection/templates/ansible.cfg.j2 b/test/integration/targets/ansible-galaxy-collection/templates/ansible.cfg.j2
index 62f3dcf9..00c1fe4d 100644
--- a/test/integration/targets/ansible-galaxy-collection/templates/ansible.cfg.j2
+++ b/test/integration/targets/ansible-galaxy-collection/templates/ansible.cfg.j2
@@ -1,7 +1,10 @@
[galaxy]
# Ensures subsequent unstable reruns don't use the cached information causing another failure
cache_dir={{ remote_tmp_dir }}/galaxy_cache
-server_list=pulp_v2,pulp_v3,galaxy_ng,secondary
+server_list=offline,pulp_v2,pulp_v3,galaxy_ng,secondary
+
+[galaxy_server.offline]
+url=https://test-hub.demolab.local/api/galaxy/content/api/
[galaxy_server.pulp_v2]
url={{ pulp_server }}published/api/
diff --git a/test/integration/targets/module_utils_Ansible.ModuleUtils.AddType/library/add_type_test.ps1 b/test/integration/targets/module_utils_Ansible.ModuleUtils.AddType/library/add_type_test.ps1
index d89f99b7..d6b05691 100644
--- a/test/integration/targets/module_utils_Ansible.ModuleUtils.AddType/library/add_type_test.ps1
+++ b/test/integration/targets/module_utils_Ansible.ModuleUtils.AddType/library/add_type_test.ps1
@@ -295,5 +295,28 @@ namespace Namespace11
Add-CSharpType -Reference $arch_class
Assert-Equals -actual ([Namespace11.Class11]::GetIntPtrSize()) -expected ([System.IntPtr]::Size)
+$lib_set = @'
+using System;
+
+namespace Namespace12
+{
+ public class Class12
+ {
+ public static string GetString()
+ {
+ return "b";
+ }
+ }
+}
+'@
+$env:LIB = "C:\fake\folder\path"
+try {
+ Add-CSharpType -Reference $lib_set
+}
+finally {
+ Remove-Item -LiteralPath env:\LIB
+}
+Assert-Equals -actual ([Namespace12.Class12]::GetString()) -expected "b"
+
$result.res = "success"
Exit-Json -obj $result
diff --git a/test/integration/targets/roles_arg_spec/roles/empty_argspec/meta/argument_specs.yml b/test/integration/targets/roles_arg_spec/roles/empty_argspec/meta/argument_specs.yml
new file mode 100644
index 00000000..b592aa05
--- /dev/null
+++ b/test/integration/targets/roles_arg_spec/roles/empty_argspec/meta/argument_specs.yml
@@ -0,0 +1,2 @@
+---
+argument_specs:
diff --git a/test/integration/targets/roles_arg_spec/roles/empty_argspec/tasks/main.yml b/test/integration/targets/roles_arg_spec/roles/empty_argspec/tasks/main.yml
new file mode 100644
index 00000000..90aab0e0
--- /dev/null
+++ b/test/integration/targets/roles_arg_spec/roles/empty_argspec/tasks/main.yml
@@ -0,0 +1,3 @@
+---
+- debug:
+ msg: "Role with empty argument_specs key"
diff --git a/test/integration/targets/roles_arg_spec/roles/empty_file/meta/argument_specs.yml b/test/integration/targets/roles_arg_spec/roles/empty_file/meta/argument_specs.yml
new file mode 100644
index 00000000..ed97d539
--- /dev/null
+++ b/test/integration/targets/roles_arg_spec/roles/empty_file/meta/argument_specs.yml
@@ -0,0 +1 @@
+---
diff --git a/test/integration/targets/roles_arg_spec/roles/empty_file/tasks/main.yml b/test/integration/targets/roles_arg_spec/roles/empty_file/tasks/main.yml
new file mode 100644
index 00000000..b77b8357
--- /dev/null
+++ b/test/integration/targets/roles_arg_spec/roles/empty_file/tasks/main.yml
@@ -0,0 +1,3 @@
+---
+- debug:
+ msg: "Role with empty argument_specs.yml"
diff --git a/test/integration/targets/roles_arg_spec/test.yml b/test/integration/targets/roles_arg_spec/test.yml
index 06268c6a..5eca7c73 100644
--- a/test/integration/targets/roles_arg_spec/test.yml
+++ b/test/integration/targets/roles_arg_spec/test.yml
@@ -338,3 +338,19 @@
- debug: var=ansible_failed_result
- fail:
msg: "Should not get here"
+
+- name: "New play to reset vars: Test empty argument_specs.yml"
+ hosts: localhost
+ gather_facts: false
+ tasks:
+ - name: Import role with an empty argument_specs.yml
+ import_role:
+ name: empty_file
+
+- name: "New play to reset vars: Test empty argument_specs key"
+ hosts: localhost
+ gather_facts: false
+ tasks:
+ - name: Import role with an empty argument_specs key
+ import_role:
+ name: empty_argspec
diff --git a/test/lib/ansible_test/_data/sanity/pslint/pslint.ps1 b/test/lib/ansible_test/_data/sanity/pslint/pslint.ps1
index 1ef2743a..21007db6 100755
--- a/test/lib/ansible_test/_data/sanity/pslint/pslint.ps1
+++ b/test/lib/ansible_test/_data/sanity/pslint/pslint.ps1
@@ -2,7 +2,6 @@
#Requires -Version 6
#Requires -Modules PSScriptAnalyzer, PSSA-PSCustomUseLiteralPath
-Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
$WarningPreference = "Stop"
@@ -21,14 +20,12 @@ $PSSAParams = @{
Setting = (Join-Path -Path $PSScriptRoot -ChildPath "settings.psd1")
}
-$Results = @()
-
-ForEach ($Path in $Args) {
+$Results = @(ForEach ($Path in $Args) {
$Retries = 3
Do {
Try {
- $Results += Invoke-ScriptAnalyzer -Path $Path @PSSAParams 3> $null
+ Invoke-ScriptAnalyzer -Path $Path @PSSAParams 3> $null
$Retries = 0
}
Catch {
@@ -38,6 +35,8 @@ ForEach ($Path in $Args) {
}
}
Until ($Retries -le 0)
-}
+})
-ConvertTo-Json -InputObject $Results
+# Since pwsh 7.1 results that exceed depth will produce a warning which fails the process.
+# Ignore warnings only for this step.
+ConvertTo-Json -InputObject $Results -Depth 1 -WarningAction SilentlyContinue
diff --git a/test/units/module_utils/test_connection.py b/test/units/module_utils/test_connection.py
new file mode 100644
index 00000000..bd0285b3
--- /dev/null
+++ b/test/units/module_utils/test_connection.py
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+# Copyright: (c) 2021, Matt Martz <matt@sivel.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+from ansible.module_utils import connection
+
+import pytest
+
+
+def test_set_options_credential_exposure():
+ def send(data):
+ return '{'
+
+ c = connection.Connection(connection.__file__)
+ c.send = send
+ with pytest.raises(connection.ConnectionError) as excinfo:
+ c._exec_jsonrpc('set_options', become_pass='password')
+
+ assert 'password' not in str(excinfo.value)