Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#3242) Attempt default credentials for sources #3252

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions Invoke-AuthedTests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#Requires -Module @{ ModuleName = 'pester'; ModuleVersion = '5.3.1' }
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Prepares a system to test as thought it was test kitchen...
#>
param(
# Path to place Chocolatey test related artifacts.
[string]
$TestPath = "$env:TEMP/chocolateyTests",

# Indicate to skip packaging all of the tests packages. Useful for running tests after you've performed the tests previously.
[switch]
$SkipPackaging,

# The remote repository to push packages to and to use during tests.
[string]
$RemoteRepository,

# API Key used by the remote repository for pushing packages
[string]
$ApiKey
)

if (-not (Test-Path "$TestPath/packages") -or -not $SkipPackaging) {
if (($null -ne $RemoteRepository) -and ($null -ne $ApiKey))
$null = New-Item -Path "$TestPath/packages" -ItemType Directory -Force
# Get and pack packages
$nuspecs = Get-ChildItem -Path $PSScriptRoot/src/chocolatey.tests.integration, $PSScriptRoot/tests/packages -Recurse -Include *.nuspec
Get-ChildItem -Path $PSScriptRoot/tests/packages -Recurse -Include *.nupkg | Copy-Item -Destination "$TestPath/packages"

foreach ($file in $nuspecs) {
Write-Host "Packaging $file"
$null = choco pack $file.FullName --out "$TestPath/packages"
}

Get-ChildItem -Path $TestPath/packages | ForEach-Object {
choco push $_.FullName -s $RemoteRepository -k $ApiKey --force --allow-unofficial
}
}

try {
Push-Location $PSScriptRoot/tests
$env:PSModulePath = "$PSScriptRoot/tests;$env:PSModulePath"

Import-Module $PSScriptRoot\tests\helpers\common-helpers.psm1 -Force
$null = Invoke-Choco source add --name hermes --source $RemoteRepository
Enable-ChocolateyFeature -Name allowGlobalConfirmation
$PesterConfiguration = [PesterConfiguration]@{
Run = @{
PassThru = $true
Path = "$PSScriptRoot/tests/chocolatey-tests"
}
TestResult = @{
Enabled = $true
TestSuiteName = "Pester - Chocolatey"
}
Output = @{
Verbosity = 'Minimal'
}
Filter = @{
ExcludeTag = @(
'Background'
'Licensed'
'CCM'
'WIP'
'NonAdmin'
'Internal'
if (-not $env:VM_RUNNING -and -not $env:TEST_KITCHEN) {
'VMOnly'
}
)
}
Should = @{
ErrorAction = 'Continue'
}
}

Invoke-Pester -Configuration $PesterConfiguration
}
finally {
Pop-Location
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,16 @@ public Task<CredentialResponse> GetAsync(Uri uri, IWebProxy proxy, CredentialReq

if (source == null)
{
this.Log().Debug("Asking user for credentials for '{0}'".FormatWith(uri.OriginalString));
return Task.FromResult(new CredentialResponse(GetUserCredentials(uri, proxy, credentialType)));
ICredentials credential = CredentialCache.DefaultNetworkCredentials;

if (isRetry)
{
this.Log().Debug("This is a retry attempt. Asking user for credentials for '{0}'".FormatWith(uri.OriginalString));
credential = GetUserCredentials(uri, proxy, credentialType);

}

return Task.FromResult(new CredentialResponse(credential));
}
else
{
Expand Down