Skip to content

Commit 06eb38f

Browse files
authored
Integrate credential provider into NugetProvider(#442)
1 parent 5e804a2 commit 06eb38f

File tree

2 files changed

+58
-23
lines changed

2 files changed

+58
-23
lines changed

Test/ModuleTests/tests/nuget.tests.ps1

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,41 @@ function SkipVersion([version]$minVersion,[version]$maxVersion) {
7777
return $true
7878
}
7979

80+
Describe "Azure Artifacts Credential Provider Integration" -Tags "Feature" {
81+
82+
BeforeAll{
83+
# Make sure the credential provider is installed (works for Windows, Linux, and Mac)
84+
# If the credential provider is already installed, will receive the message: "The netcore Credential Provider is already in C:\Users\<alias>\.nuget\plugins"
85+
iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/microsoft/artifacts-credprovider/master/helpers/installcredprovider.ps1'))
86+
87+
$pkgSourceName = "OneGetTestPrivateFeed"
88+
# This pkg source is an Azure DevOps private feed
89+
$testSource = "https://pkgs.dev.azure.com/onegettest/_packaging/onegettest/nuget/v3/index.json";
90+
$username = "[email protected]"
91+
$PAT = "qo2xvzdnfi2mlcq3eq2jkoxup576kt4gnngcicqhup6bbix6sila"
92+
# see https://github.com/Microsoft/artifacts-credprovider#environment-variables for more info on env vars for the credential provider
93+
# The line below is purely for local testing. Make sure to update env vars in AppVeyor and Travis CI as necessary.
94+
$VSS_NUGET_EXTERNAL_FEED_ENDPOINTS = "{'endpointCredentials': [{'endpoint':'$testSource', 'username':'$username', 'password':'$PAT'}]}"
95+
[System.Environment]::SetEnvironmentVariable("VSS_NUGET_EXTERNAL_FEED_ENDPOINTS", $VSS_NUGET_EXTERNAL_FEED_ENDPOINTS, [System.EnvironmentVariableTarget]::Process)
96+
}
97+
98+
AfterAll{
99+
UnRegister-PackageSource -Name $pkgSourceName -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
100+
}
101+
102+
it "Register-PackageSource using credential provider" -Skip:(!$IsWindows){
103+
register-packagesource $pkgSourceName -Location $testSource -providername Nuget
104+
105+
(Get-PackageSource -Name $pkgSourceName).Name | should match $pkgSourceName
106+
(Get-PackageSource -Name $pkgSourceName).Location | should match $testSource
107+
}
108+
109+
it "Find-Package using credential provider" -Skip:(!$IsWindows){
110+
$pkg = find-package * -provider $nuget -source $pkgSourceName
111+
$pkg.Count | should -BeGreaterThan 0
112+
}
113+
}
114+
80115
Describe "Find, Get, Save, and Install-Package with Culture" -Tags "Feature" {
81116

82117
<#
@@ -352,17 +387,17 @@ Describe "Find-Package" -Tags @('Feature','SLOW'){
352387
(find-package -name "ModuleWithDependenciesLoop" -provider $nuget -source "$dependenciesSource\SimpleDependenciesLoop").name | should match "ModuleWithDependenciesLoop"
353388
}
354389

355-
It "EXPECTED: Finds 'grpc.dependencies.zlib' Package with -IncludeDependencies" {
356-
$version = "1.2.8.10"
357-
$packages = Find-Package -Name "grpc.dependencies.zlib" -ProviderName $nuget -Source $source -RequiredVersion $version -IncludeDependencies
358-
$packages.Count | should match 2
359-
$expectedPackages = @("grpc.dependencies.zlib","grpc.dependencies.zlib.redist")
390+
It "EXPECTED: Finds 'Microsoft.AspNet.Mvc' Package with -IncludeDependencies" {
391+
$version = "5.2.7"
392+
$packages = Find-Package -Name "Microsoft.AspNet.Mvc" -ProviderName $nuget -Source $source -RequiredVersion $version -IncludeDependencies
393+
$packages.Count | should match 4
394+
$expectedPackages = @("Microsoft.AspNet.Razor", "Microsoft.AspNet.WebPages", "Microsoft.AspNet.Razor", "Microsoft.Web.Infrastructure")
360395

361396
foreach ($expectedPackage in $expectedPackages) {
362397
$match = $false
363398
foreach ($package in $packages) {
364-
# All the packages have the same version for grpc.dependencies.zlib
365-
if ($package.Name -match $expectedPackage -and $package.Version -match $version) {
399+
# All the packages have the same version for Microsoft.AspNet.Mvc
400+
if ($package.Name -match $expectedPackage) {
366401
$match = $true
367402
break
368403
}
@@ -465,8 +500,8 @@ Describe "Find-Package" -Tags @('Feature','SLOW'){
465500
}
466501
}
467502

468-
It "EXPECTED: Finds 'grpc.dependencies.zlib' Package After Piping The Provider" {
469-
(get-packageprovider -name $nuget | find-package -name grpc.dependencies.zlib -source $source ).name | should be "grpc.dependencies.zlib"
503+
It "EXPECTED: Finds 'Microsoft.AspNet.Mvc' Package After Piping The Provider" {
504+
(get-packageprovider -name $nuget | find-package -name Microsoft.AspNet.Mvc -source $source -requiredversion $version).name | should be "Microsoft.AspNet.Mvc"
470505
}
471506

472507
It "EXPECTED: -FAILS- To Find Package Due To Too Long Of Name" {
@@ -728,11 +763,11 @@ Describe "Save-Package" -Tags "Feature" {
728763
}
729764
}
730765

731-
It "EXPECTED: Saves 'grpc.dependencies.zlib' Package After Having The Provider Piped" {
732-
(find-package -name "grpc.dependencies.zlib" -provider $nuget -source $source | save-package -Path $destination)
733-
(Test-Path -Path $destination\grpc.dependencies.zlib*) | should be $true
734-
if (Test-Path -Path $destination\grpc.dependencies.zlib*) {
735-
Remove-Item $destination\grpc.dependencies.zlib* -Force -Recurse
766+
It "EXPECTED: Saves 'Microsoft.AspNet.Mvc' Package After Having The Provider Piped" {
767+
(find-package -name "Microsoft.AspNet.Mvc" -provider $nuget -source $source | save-package -Path $destination)
768+
(Test-Path -Path $destination\Microsoft.AspNet.Mvc*) | should be $true
769+
if (Test-Path -Path $destination\Microsoft.AspNet.Mvc*) {
770+
Remove-Item $destination\Microsoft.AspNet.Mvc* -Force -Recurse
736771
}
737772
}
738773

@@ -814,7 +849,7 @@ Describe "save-package with Whatif" -Tags "Feature" {
814849
}
815850

816851
It "install-package -name nuget with whatif where package has a dependencies, Expect succeed" {
817-
{Save-Package -name zlib -source $source `
852+
{Save-Package -name Microsoft.AspNet.Mvc -source $source `
818853
-ProviderName NuGet -Path $tempDir -whatif -ErrorAction SilentlyContinue} | should not throw
819854
}
820855
}
@@ -861,7 +896,7 @@ Describe "install-package with Whatif" -Tags "Feature" {
861896
}
862897

863898
It "install-package -name nuget with whatif where package has a dependencies, Expect succeed" {
864-
{install-Package -name grpc.dependencies.zlib -source $source `
899+
{install-Package -name Microsoft.AspNet.Mvc -source $source `
865900
-ProviderName NuGet -destination $installationPath -whatif} | should not throw
866901
}
867902
}
@@ -878,7 +913,7 @@ Describe "Install-Package dependencies" -Tags "Feature" {
878913
if($pkg.Version -le "2.8.5.205") { return }
879914

880915
$version = "1.2.8.10"
881-
$zlib = Install-Package -Provider $nuget -Source $source -Destination $tempDir -SkipDependencies -Force grpc.dependencies.zlib
916+
$zlib = Install-Package -Provider $nuget -Source $source -Destination $tempDir -RequiredVersion $version -SkipDependencies -Force grpc.dependencies.zlib
882917

883918
$zlib.Count | should be 1
884919
(test-path "$tempDir\grpc.dependencies.zlib*") | should be $true
@@ -1221,11 +1256,11 @@ Describe Install-Package -Tags "Feature" {
12211256
}
12221257
}
12231258

1224-
It "EXPECTED: Installs 'grpc.dependencies.zlib' Package After Having The Provider Piped" {
1225-
(find-package -name "grpc.dependencies.zlib" -provider $nuget -source $source | install-package -destination $destination -force -Verbose)
1226-
(Test-Path -Path $destination\grpc.dependencies.zlib*) | should be $true
1227-
if (Test-Path -Path $destination\grpc.dependencies.zlib*) {
1228-
(Remove-Item -Recurse -Force -Path $destination\grpc.dependencies.zlib* -ErrorAction SilentlyContinue)
1259+
It "EXPECTED: Installs 'Microsoft.AspNet.Mvc' Package After Having The Provider Piped" {
1260+
(find-package -name "Microsoft.AspNet.Mvc" -provider $nuget -source $source | install-package -destination $destination -force -Verbose)
1261+
(Test-Path -Path $destination\Microsoft.AspNet.Mvc*) | should be $true
1262+
if (Test-Path -Path $destination\Microsoft.AspNet.Mvc*) {
1263+
(Remove-Item -Recurse -Force -Path $destination\Microsoft.AspNet.Mvc* -ErrorAction SilentlyContinue)
12291264
}
12301265
}
12311266

0 commit comments

Comments
 (0)