Fix win_psmodule and win_psrepository tests

pull/68979/head
Jordan Borean 5 years ago committed by Matt Clay
parent e40b96ed88
commit 330112a45c

@ -0,0 +1,4 @@
bugfixes:
- win_psmodule - Fix TLS 1.2 compatibility with PSGallery.
- win_psrepository - Fix TLS 1.2 compatibility with PSGallery.
- win_psrepository - Fix ``Ignore`` error when trying to retrieve the list of registered repositories

@ -27,6 +27,18 @@ $result = @{changed = $false
nuget_changed = $false
repository_changed = $false}
# Enable TLS1.1/TLS1.2 if they're available but disabled (eg. .NET 4.5)
$security_protocols = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::SystemDefault
if ([System.Net.SecurityProtocolType].GetMember("Tls11").Count -gt 0) {
$security_protocols = $security_protocols -bor [System.Net.SecurityProtocolType]::Tls11
}
if ([System.Net.SecurityProtocolType].GetMember("Tls12").Count -gt 0) {
$security_protocols = $security_protocols -bor [System.Net.SecurityProtocolType]::Tls12
}
[System.Net.ServicePointManager]::SecurityProtocol = $security_protocols
Function Install-NugetProvider {
Param(
[Bool]$CheckMode
@ -162,7 +174,7 @@ Function Add-DefinedParameter {
)
ForEach ($ParameterName in $ParametersNames) {
$ParameterVariable = Get-Variable -Name $ParameterName -ErrorAction Ignore
$ParameterVariable = Get-Variable -Name $ParameterName -ErrorAction SilentlyContinue
if ( $ParameterVariable.Value -and $Hashtable.Keys -notcontains $ParameterName ){
$Hashtable.Add($ParameterName,$ParameterVariable.Value)
}
@ -381,7 +393,7 @@ if ( ($state -eq "latest") -and
}
if ( $repo -and (-not $url) ) {
$RepositoryExists = Get-PSRepository -Name $repo -ErrorAction Ignore
$RepositoryExists = Get-PSRepository -Name $repo -ErrorAction SilentlyContinue
if ( $null -eq $RepositoryExists) {
$ErrorMessage = "The repository $repo doesn't exist."
Fail-Json $result $ErrorMessage

@ -18,6 +18,16 @@ $installationpolicy = Get-AnsibleParam -obj $params -name "installation_policy"
$result = @{"changed" = $false}
# Enable TLS1.1/TLS1.2 if they're available but disabled (eg. .NET 4.5)
$security_protocols = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::SystemDefault
if ([System.Net.SecurityProtocolType].GetMember("Tls11").Count -gt 0) {
$security_protocols = $security_protocols -bor [System.Net.SecurityProtocolType]::Tls11
}
if ([System.Net.SecurityProtocolType].GetMember("Tls12").Count -gt 0) {
$security_protocols = $security_protocols -bor [System.Net.SecurityProtocolType]::Tls12
}
[System.Net.ServicePointManager]::SecurityProtocol = $security_protocols
Function Update-NuGetPackageProvider {
$PackageProvider = Get-PackageProvider -ListAvailable | Where-Object { ($_.name -eq 'Nuget') -and ($_.version -ge "2.8.5.201") }
if ($null -eq $PackageProvider) {
@ -25,7 +35,7 @@ Function Update-NuGetPackageProvider {
}
}
$Repo = Get-PSRepository -Name $name -ErrorAction Ignore
$Repo = Get-PSRepository -Name $name -ErrorAction SilentlyContinue
if ($state -eq "present") {
if ($null -eq $Repo) {
if ($null -eq $installationpolicy) {

@ -5,7 +5,7 @@
---
- name: unregister the repository
win_shell: Unregister-PSRepository {{ repository_name | quote }} -ErrorAction Ignore
win_shell: Unregister-PSRepository {{ repository_name | quote }} -ErrorAction SilentlyContinue
- block:
- name: run all tests
@ -13,4 +13,4 @@
always:
- name: ensure test repo is unregistered
win_shell: Unregister-PSRepository {{ repository_name | quote }} -ErrorAction Ignore
win_shell: Unregister-PSRepository {{ repository_name | quote }} -ErrorAction SilentlyContinue

@ -161,7 +161,7 @@
register: removing_repository_check
- name: get result of remove repository - check mode
win_shell: '(Get-PSRepository -Name {{ repository_name | quote }} -ErrorAction Ignore | Measure-Object).Count'
win_shell: '(Get-PSRepository -Name {{ repository_name | quote }} -ErrorAction SilentlyContinue | Measure-Object).Count'
changed_when: false
register: result_removing_repository_check
@ -178,7 +178,7 @@
register: removing_repository
- name: get result of remove repository
win_shell: '(Get-PSRepository -Name {{ repository_name | quote }} -ErrorAction Ignore | Measure-Object).Count'
win_shell: '(Get-PSRepository -Name {{ repository_name | quote }} -ErrorAction SilentlyContinue | Measure-Object).Count'
changed_when: false
register: result_removing_repository

Loading…
Cancel
Save