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

Move credential provider tests from PackageManagement to PSGet #507

Merged
merged 1 commit into from
Jul 1, 2019
Merged
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
88 changes: 72 additions & 16 deletions Tests/PSGetFindModule.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -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'
}

Expand All @@ -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"
}

Expand All @@ -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"
}

Expand All @@ -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"
}

Expand All @@ -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"
}

Expand All @@ -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"
}

Expand All @@ -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"
}

Expand All @@ -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"
}

Expand Down Expand Up @@ -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)"
Expand All @@ -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)"
Expand All @@ -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)"
Expand All @@ -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)"
Expand Down Expand Up @@ -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'
}

Expand All @@ -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'
}

Expand Down Expand Up @@ -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)" }
}
}

Expand Down Expand Up @@ -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\<alias>\.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
}
}