Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit 867b4f5

Browse files
committed
Merge remote-tracking branch 'origin/development'
2 parents f01849d + 822482f commit 867b4f5

File tree

5 files changed

+286
-19
lines changed

5 files changed

+286
-19
lines changed

Tests/PSGetFindModule.Tests.ps1

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' {
116116
# Expected Result: Should fail
117117
#
118118
It "FindModuleNonExistentModule" {
119-
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module NonExistentModule} `
119+
AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module NonExistentModule } `
120120
-expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage"
121121
}
122122

@@ -127,7 +127,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' {
127127
# Expected Result: Should fail
128128
#
129129
It "FindScriptNotModule" {
130-
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module Fabrikam-ServerScript} `
130+
AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module Fabrikam-ServerScript } `
131131
-expectedFullyQualifiedErrorId 'MatchInvalidType,Find-Module'
132132
}
133133

@@ -149,7 +149,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' {
149149
# Expected Result: Should fail with error id
150150
#
151151
It "FindModuleWithVersionParams" {
152-
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer -MinimumVersion 1.0 -RequiredVersion 5.0} `
152+
AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module ContosoServer -MinimumVersion 1.0 -RequiredVersion 5.0 } `
153153
-expectedFullyQualifiedErrorId "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Find-Module"
154154
}
155155

@@ -171,7 +171,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' {
171171
# Expected Result: Should not find the ContosoServer module
172172
#
173173
It "FindModuleWithMinVersionNotAvailable" {
174-
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer -MinimumVersion 10.0} `
174+
AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module ContosoServer -MinimumVersion 10.0 } `
175175
-expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage"
176176
}
177177

@@ -182,7 +182,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' {
182182
# Expected Result: Should not find the ContosoServer module
183183
#
184184
It "FindModuleWithReqVersionNotAvailable" {
185-
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer -RequiredVersion 10.0} `
185+
AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module ContosoServer -RequiredVersion 10.0 } `
186186
-expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage"
187187
}
188188

@@ -204,7 +204,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' {
204204
# Expected Result: Should fail with error id
205205
#
206206
It "FindModuleWithMultipleModuleNamesAndReqVersion" {
207-
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer, ContosoClient -RequiredVersion 1.0} `
207+
AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module ContosoServer, ContosoClient -RequiredVersion 1.0 } `
208208
-expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module"
209209
}
210210

@@ -215,7 +215,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' {
215215
# Expected Result: Should fail with error id
216216
#
217217
It "FindModuleWithMultipleModuleNamesAndMinVersion" {
218-
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer, ContosoClient -MinimumVersion 1.0} `
218+
AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module ContosoServer, ContosoClient -MinimumVersion 1.0 } `
219219
-expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module"
220220
}
221221

@@ -226,7 +226,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' {
226226
# Expected Result: Should fail with error id
227227
#
228228
It "FindModuleWithWildcardNameAndReqVersion" {
229-
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module Contoso*er -RequiredVersion 1.0} `
229+
AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module Contoso*er -RequiredVersion 1.0 } `
230230
-expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module"
231231
}
232232

@@ -237,7 +237,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' {
237237
# Expected Result: Should fail with error id
238238
#
239239
It "FindModuleWithWildcardNameAndMinVersion" {
240-
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module Contoso*er -MinimumVersion 1.0} `
240+
AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module Contoso*er -MinimumVersion 1.0 } `
241241
-expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module"
242242
}
243243

@@ -281,7 +281,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' {
281281
# Expected Result: Find-Module should work and it should have valid metadata
282282
#
283283
It FindModuleUsingIncludesRoleCapability {
284-
$psgetModuleInfo = Find-Module -Includes RoleCapability | Where-Object {$_.Name -eq "DscTestModule"}
284+
$psgetModuleInfo = Find-Module -Includes RoleCapability | Where-Object { $_.Name -eq "DscTestModule" }
285285
AssertNotNull $psgetModuleInfo.Includes "Includes is missing on PSGetModuleInfo, $($psgetModuleInfo.Includes)"
286286
Assert $psgetModuleInfo.Includes.RoleCapability.Count "RoleCapability are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.RoleCapability)"
287287
Assert $psgetModuleInfo.Includes.DscResource.Count "DscResource are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.DscResource)"
@@ -297,7 +297,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' {
297297
# Expected Result: Find-Module should work and it should have valid metadata
298298
#
299299
It FindModuleUsingIncludesDscResource {
300-
$psgetModuleInfo = Find-Module -Includes DscResource | Where-Object {$_.Name -eq "DscTestModule"}
300+
$psgetModuleInfo = Find-Module -Includes DscResource | Where-Object { $_.Name -eq "DscTestModule" }
301301
AssertNotNull $psgetModuleInfo.Includes "Includes is missing on PSGetModuleInfo, $($psgetModuleInfo.Includes)"
302302
Assert $psgetModuleInfo.Includes.DscResource.Count "DscResource are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.DscResource)"
303303
Assert $psgetModuleInfo.Includes.Command.Count "Commands are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.Command)"
@@ -312,7 +312,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' {
312312
# Expected Result: Find-Module should work and it should have valid metadata
313313
#
314314
It FindModuleUsingIncludesCmdlet {
315-
$psgetModuleInfo = Find-Module -Includes Cmdlet | Where-Object {$_.Name -eq "DscTestModule"}
315+
$psgetModuleInfo = Find-Module -Includes Cmdlet | Where-Object { $_.Name -eq "DscTestModule" }
316316
AssertNotNull $psgetModuleInfo.Includes "Includes is missing on PSGetModuleInfo, $($psgetModuleInfo.Includes)"
317317
Assert $psgetModuleInfo.Includes.DscResource.Count "DscResource are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.DscResource)"
318318
Assert $psgetModuleInfo.Includes.Command.Count "Commands are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.Command)"
@@ -327,7 +327,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' {
327327
# Expected Result: Find-Module should work and it should have valid metadata
328328
#
329329
It FindModuleUsingIncludesFunction {
330-
$psgetModuleInfo = Find-Module -Includes Function -Tag CommandsAndResource | Where-Object {$_.Name -eq "DscTestModule"}
330+
$psgetModuleInfo = Find-Module -Includes Function -Tag CommandsAndResource | Where-Object { $_.Name -eq "DscTestModule" }
331331
AssertNotNull $psgetModuleInfo.Includes "Includes is missing on PSGetModuleInfo, $($psgetModuleInfo.Includes)"
332332
Assert $psgetModuleInfo.Includes.DscResource.Count "DscResource are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.DscResource)"
333333
Assert $psgetModuleInfo.Includes.Command.Count "Commands are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.Command)"
@@ -476,7 +476,7 @@ Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1', 'OuterLoop' {
476476
# Expected Result: should fail with an error id
477477
#
478478
It FindModuleWithAllVersionsAndMinimumVersion {
479-
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoClient -MinimumVersion 2.0 -Repository PSGallery -AllVersions} `
479+
AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module ContosoClient -MinimumVersion 2.0 -Repository PSGallery -AllVersions } `
480480
-expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Module'
481481
}
482482

@@ -487,7 +487,7 @@ Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1', 'OuterLoop' {
487487
# Expected Result: should fail with an error id
488488
#
489489
It FindModuleWithAllVersionsAndRequiredVersion {
490-
AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoClient -RequiredVersion 2.0 -Repository PSGallery -AllVersions} `
490+
AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module ContosoClient -RequiredVersion 2.0 -Repository PSGallery -AllVersions } `
491491
-expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Module'
492492
}
493493

@@ -519,7 +519,7 @@ Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1', 'OuterLoop' {
519519
$res2 = Find-Module -Name $ModuleName -IncludeDependencies -MaximumVersion "1.0" -MinimumVersion "0.1"
520520
Assert ($res2.Count -ge ($DepencyModuleNames.Count + 1)) "Find-Module with -IncludeDependencies returned wrong results, $res2"
521521

522-
$DepencyModuleNames | ForEach-Object { Assert ($res2.Name -Contains $_) "Find-Module with -IncludeDependencies didn't return the $_ module, $($res2.Name)"}
522+
$DepencyModuleNames | ForEach-Object { Assert ($res2.Name -Contains $_) "Find-Module with -IncludeDependencies didn't return the $_ module, $($res2.Name)" }
523523
}
524524
}
525525

@@ -582,3 +582,59 @@ Describe PowerShell.PSGet.FindModuleTests.P2 -Tags 'P2', 'OuterLoop' {
582582
$i = $i + 1
583583
}
584584
}
585+
586+
587+
Describe "Azure Artifacts Credential Provider Integration" -Tags 'BVT' {
588+
589+
BeforeAll {
590+
$repoName = "OneGetTestPrivateFeed"
591+
# This pkg source is an Azure DevOps private feed
592+
$testLocation = "https://pkgs.dev.azure.com/onegettest/_packaging/onegettest/nuget/v2";
593+
$username = "onegettest@hotmail.com"
594+
$PAT = "qo2xvzdnfi2mlcq3eq2jkoxup576kt4gnngcicqhup6bbix6sila"
595+
# see https://github.com/Microsoft/artifacts-credprovider#environment-variables for more info on env vars for the credential provider
596+
# The line below is purely for local testing. Make sure to update env vars in AppVeyor and Travis CI as necessary.
597+
$VSS_NUGET_EXTERNAL_FEED_ENDPOINTS = "{'endpointCredentials': [{'endpoint':'$testLocation', 'username':'$username', 'password':'$PAT'}]}"
598+
[System.Environment]::SetEnvironmentVariable("VSS_NUGET_EXTERNAL_FEED_ENDPOINTS", $VSS_NUGET_EXTERNAL_FEED_ENDPOINTS, [System.EnvironmentVariableTarget]::Process)
599+
600+
601+
# Figure out if Visual Studio is installed, and if it is, we'll use the credential provider that's installed there for the first test
602+
$VSinstalledCredProvider = $false;
603+
$programFiles = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::ProgramFilesX86);
604+
$vswhereExePath = $programFiles + "\\Microsoft Visual Studio\\Installer\\vswhere.exe";
605+
$fullVSwhereExePath = [System.Environment]::ExpandEnvironmentVariables($vswhereExePath);
606+
# If the env variable exists, check to see if the path itself exists
607+
if (Test-Path ($fullVSwhereExePath)) {
608+
$VSinstalledCredProvider = $true;
609+
}
610+
}
611+
612+
AfterAll {
613+
UnRegister-PSRepository -Name $repoName -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
614+
}
615+
616+
it "Register-PackageSource using Visual Studio installed credential provider" -Skip:(!$VSinstalledCredProvider) {
617+
Register-PSRepository $repoName -SourceLocation $testLocation
618+
619+
(Get-PSRepository -Name $repoName).Name | should match $repoName
620+
(Get-PSRepository -Name $repoName).SourceLocation | should match $testLocation
621+
622+
Unregister-PSRepository -Name $repoName -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
623+
}
624+
625+
it "Register-PackageSource using credential provider" -Skip:(!$IsWindows) {
626+
# Make sure the credential provider is installed (works for Windows, Linux, and Mac)
627+
# If the credential provider is already installed, will receive the message: "The netcore Credential Provider is already in C:\Users\<alias>\.nuget\plugins"
628+
iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/microsoft/artifacts-credprovider/master/helpers/installcredprovider.ps1'))
629+
630+
Register-PSRepository $repoName -SourceLocation $testLocation
631+
632+
(Get-PSRepository -Name $repoName).Name | should match $repoName
633+
(Get-PSRepository -Name $repoName).SourceLocation | should match $testLocation
634+
}
635+
636+
it "Find-Package using credential provider" -Skip:(!$IsWindows) {
637+
$pkg = Find-Module * -Repository $repoName
638+
$pkg.Count | should -BeGreaterThan 0
639+
}
640+
}

src/PowerShellGet/PSGet.Resource.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ ConvertFrom-StringData @'
110110
UseDefaultParameterSetOnRegisterPSRepository=Use 'Register-PSRepository -Default' to register the PSGallery repository.
111111
RepositoryNameContainsWildCards=The repository name '{0}' should not have wildcards, correct it and try again.
112112
InvalidRepository=The specified repository '{0}' is not a valid registered repository name. Please ensure that '{1}' is a registered repository.
113+
RepositoryCannotBeRegistered=The specified repository '{0}' is unauthorized and cannot be registered. Try running with -Credential.
113114
RepositoryRegistered=Successfully registered the repository '{0}' with source location '{1}'.
114115
RepositoryUnregistered=Successfully unregistered the repository '{0}'.
115116
PSGalleryPublishLocationIsMissing=The specified repository '{0}' does not have a valid PublishLocation. Retry after setting the PublishLocation for repository '{1}' to a valid NuGet publishing endpoint using the Set-PSRepository cmdlet.

src/PowerShellGet/PowerShellGet.psd1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
RootModule = 'PSModule.psm1'
3-
ModuleVersion = '2.1.5'
3+
ModuleVersion = '2.2'
44
GUID = '1d73a601-4a6c-43c5-ba3f-619b18bbb404'
55
Author = 'Microsoft Corporation'
66
CompanyName = 'Microsoft Corporation'
@@ -14,6 +14,7 @@
1414
'Find-Module',
1515
'Find-RoleCapability',
1616
'Find-Script',
17+
'Get-CredsFromCredentialProvider',
1718
'Get-InstalledModule',
1819
'Get-InstalledScript',
1920
'Get-PSRepository',
@@ -55,6 +56,11 @@
5556
LicenseUri = 'https://go.microsoft.com/fwlink/?LinkId=829061'
5657
ReleaseNotes = @'
5758
59+
## 2.2
60+
Bug Fix
61+
62+
- Fix for prompting for credentials when passing in -Credential parameter when using Register-PSRepository
63+
5864
## 2.1.5
5965
New Features
6066

0 commit comments

Comments
 (0)