diff --git a/Tests/PSGetFindModule.Tests.ps1 b/Tests/PSGetFindModule.Tests.ps1 index 6ec4a46f..a1270694 100644 --- a/Tests/PSGetFindModule.Tests.ps1 +++ b/Tests/PSGetFindModule.Tests.ps1 @@ -116,7 +116,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' { # Expected Result: Should fail # It "FindModuleNonExistentModule" { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module NonExistentModule} ` + AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module NonExistentModule } ` -expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" } @@ -127,7 +127,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' { # Expected Result: Should fail # It "FindScriptNotModule" { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module Fabrikam-ServerScript} ` + AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module Fabrikam-ServerScript } ` -expectedFullyQualifiedErrorId 'MatchInvalidType,Find-Module' } @@ -149,7 +149,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' { # Expected Result: Should fail with error id # It "FindModuleWithVersionParams" { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer -MinimumVersion 1.0 -RequiredVersion 5.0} ` + AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module ContosoServer -MinimumVersion 1.0 -RequiredVersion 5.0 } ` -expectedFullyQualifiedErrorId "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Find-Module" } @@ -171,7 +171,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' { # Expected Result: Should not find the ContosoServer module # It "FindModuleWithMinVersionNotAvailable" { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer -MinimumVersion 10.0} ` + AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module ContosoServer -MinimumVersion 10.0 } ` -expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" } @@ -182,7 +182,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' { # Expected Result: Should not find the ContosoServer module # It "FindModuleWithReqVersionNotAvailable" { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer -RequiredVersion 10.0} ` + AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module ContosoServer -RequiredVersion 10.0 } ` -expectedFullyQualifiedErrorId "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" } @@ -204,7 +204,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' { # Expected Result: Should fail with error id # It "FindModuleWithMultipleModuleNamesAndReqVersion" { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer, ContosoClient -RequiredVersion 1.0} ` + AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module ContosoServer, ContosoClient -RequiredVersion 1.0 } ` -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module" } @@ -215,7 +215,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' { # Expected Result: Should fail with error id # It "FindModuleWithMultipleModuleNamesAndMinVersion" { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoServer, ContosoClient -MinimumVersion 1.0} ` + AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module ContosoServer, ContosoClient -MinimumVersion 1.0 } ` -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module" } @@ -226,7 +226,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' { # Expected Result: Should fail with error id # It "FindModuleWithWildcardNameAndReqVersion" { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module Contoso*er -RequiredVersion 1.0} ` + AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module Contoso*er -RequiredVersion 1.0 } ` -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module" } @@ -237,7 +237,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' { # Expected Result: Should fail with error id # It "FindModuleWithWildcardNameAndMinVersion" { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module Contoso*er -MinimumVersion 1.0} ` + AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module Contoso*er -MinimumVersion 1.0 } ` -expectedFullyQualifiedErrorId "VersionParametersAreAllowedOnlyWithSingleName,Find-Module" } @@ -281,7 +281,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' { # Expected Result: Find-Module should work and it should have valid metadata # It FindModuleUsingIncludesRoleCapability { - $psgetModuleInfo = Find-Module -Includes RoleCapability | Where-Object {$_.Name -eq "DscTestModule"} + $psgetModuleInfo = Find-Module -Includes RoleCapability | Where-Object { $_.Name -eq "DscTestModule" } AssertNotNull $psgetModuleInfo.Includes "Includes is missing on PSGetModuleInfo, $($psgetModuleInfo.Includes)" Assert $psgetModuleInfo.Includes.RoleCapability.Count "RoleCapability are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.RoleCapability)" Assert $psgetModuleInfo.Includes.DscResource.Count "DscResource are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.DscResource)" @@ -297,7 +297,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' { # Expected Result: Find-Module should work and it should have valid metadata # It FindModuleUsingIncludesDscResource { - $psgetModuleInfo = Find-Module -Includes DscResource | Where-Object {$_.Name -eq "DscTestModule"} + $psgetModuleInfo = Find-Module -Includes DscResource | Where-Object { $_.Name -eq "DscTestModule" } AssertNotNull $psgetModuleInfo.Includes "Includes is missing on PSGetModuleInfo, $($psgetModuleInfo.Includes)" Assert $psgetModuleInfo.Includes.DscResource.Count "DscResource are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.DscResource)" Assert $psgetModuleInfo.Includes.Command.Count "Commands are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.Command)" @@ -312,7 +312,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' { # Expected Result: Find-Module should work and it should have valid metadata # It FindModuleUsingIncludesCmdlet { - $psgetModuleInfo = Find-Module -Includes Cmdlet | Where-Object {$_.Name -eq "DscTestModule"} + $psgetModuleInfo = Find-Module -Includes Cmdlet | Where-Object { $_.Name -eq "DscTestModule" } AssertNotNull $psgetModuleInfo.Includes "Includes is missing on PSGetModuleInfo, $($psgetModuleInfo.Includes)" Assert $psgetModuleInfo.Includes.DscResource.Count "DscResource are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.DscResource)" Assert $psgetModuleInfo.Includes.Command.Count "Commands are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.Command)" @@ -327,7 +327,7 @@ Describe PowerShell.PSGet.FindModuleTests -Tags 'BVT', 'InnerLoop' { # Expected Result: Find-Module should work and it should have valid metadata # It FindModuleUsingIncludesFunction { - $psgetModuleInfo = Find-Module -Includes Function -Tag CommandsAndResource | Where-Object {$_.Name -eq "DscTestModule"} + $psgetModuleInfo = Find-Module -Includes Function -Tag CommandsAndResource | Where-Object { $_.Name -eq "DscTestModule" } AssertNotNull $psgetModuleInfo.Includes "Includes is missing on PSGetModuleInfo, $($psgetModuleInfo.Includes)" Assert $psgetModuleInfo.Includes.DscResource.Count "DscResource are missing on PSGetModuleInfo, $($psgetModuleInfo.Includes.DscResource)" 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' { # Expected Result: should fail with an error id # It FindModuleWithAllVersionsAndMinimumVersion { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoClient -MinimumVersion 2.0 -Repository PSGallery -AllVersions} ` + AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module ContosoClient -MinimumVersion 2.0 -Repository PSGallery -AllVersions } ` -expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Module' } @@ -487,7 +487,7 @@ Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1', 'OuterLoop' { # Expected Result: should fail with an error id # It FindModuleWithAllVersionsAndRequiredVersion { - AssertFullyQualifiedErrorIdEquals -scriptblock {Find-Module ContosoClient -RequiredVersion 2.0 -Repository PSGallery -AllVersions} ` + AssertFullyQualifiedErrorIdEquals -scriptblock { Find-Module ContosoClient -RequiredVersion 2.0 -Repository PSGallery -AllVersions } ` -expectedFullyQualifiedErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters,Find-Module' } @@ -519,7 +519,7 @@ Describe PowerShell.PSGet.FindModuleTests.P1 -Tags 'P1', 'OuterLoop' { $res2 = Find-Module -Name $ModuleName -IncludeDependencies -MaximumVersion "1.0" -MinimumVersion "0.1" Assert ($res2.Count -ge ($DepencyModuleNames.Count + 1)) "Find-Module with -IncludeDependencies returned wrong results, $res2" - $DepencyModuleNames | ForEach-Object { Assert ($res2.Name -Contains $_) "Find-Module with -IncludeDependencies didn't return the $_ module, $($res2.Name)"} + $DepencyModuleNames | ForEach-Object { Assert ($res2.Name -Contains $_) "Find-Module with -IncludeDependencies didn't return the $_ module, $($res2.Name)" } } } @@ -582,3 +582,59 @@ Describe PowerShell.PSGet.FindModuleTests.P2 -Tags 'P2', 'OuterLoop' { $i = $i + 1 } } + + +Describe "Azure Artifacts Credential Provider Integration" -Tags 'BVT' { + + BeforeAll { + $repoName = "OneGetTestPrivateFeed" + # This pkg source is an Azure DevOps private feed + $testLocation = "https://pkgs.dev.azure.com/onegettest/_packaging/onegettest/nuget/v2"; + $username = "onegettest@hotmail.com" + $PAT = "qo2xvzdnfi2mlcq3eq2jkoxup576kt4gnngcicqhup6bbix6sila" + # see https://github.com/Microsoft/artifacts-credprovider#environment-variables for more info on env vars for the credential provider + # The line below is purely for local testing. Make sure to update env vars in AppVeyor and Travis CI as necessary. + $VSS_NUGET_EXTERNAL_FEED_ENDPOINTS = "{'endpointCredentials': [{'endpoint':'$testLocation', 'username':'$username', 'password':'$PAT'}]}" + [System.Environment]::SetEnvironmentVariable("VSS_NUGET_EXTERNAL_FEED_ENDPOINTS", $VSS_NUGET_EXTERNAL_FEED_ENDPOINTS, [System.EnvironmentVariableTarget]::Process) + + + # 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 + $VSinstalledCredProvider = $false; + $programFiles = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::ProgramFilesX86); + $vswhereExePath = $programFiles + "\\Microsoft Visual Studio\\Installer\\vswhere.exe"; + $fullVSwhereExePath = [System.Environment]::ExpandEnvironmentVariables($vswhereExePath); + # If the env variable exists, check to see if the path itself exists + if (Test-Path ($fullVSwhereExePath)) { + $VSinstalledCredProvider = $true; + } + } + + AfterAll { + UnRegister-PSRepository -Name $repoName -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } + + it "Register-PackageSource using Visual Studio installed credential provider" -Skip:(!$VSinstalledCredProvider) { + Register-PSRepository $repoName -SourceLocation $testLocation + + (Get-PSRepository -Name $repoName).Name | should match $repoName + (Get-PSRepository -Name $repoName).SourceLocation | should match $testLocation + + Unregister-PSRepository -Name $repoName -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } + + it "Register-PackageSource using credential provider" -Skip:(!$IsWindows) { + # Make sure the credential provider is installed (works for Windows, Linux, and Mac) + # If the credential provider is already installed, will receive the message: "The netcore Credential Provider is already in C:\Users\\.nuget\plugins" + iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/microsoft/artifacts-credprovider/master/helpers/installcredprovider.ps1')) + + Register-PSRepository $repoName -SourceLocation $testLocation + + (Get-PSRepository -Name $repoName).Name | should match $repoName + (Get-PSRepository -Name $repoName).SourceLocation | should match $testLocation + } + + it "Find-Package using credential provider" -Skip:(!$IsWindows) { + $pkg = Find-Module * -Repository $repoName + $pkg.Count | should -BeGreaterThan 0 + } +}