Skip to content

Commit d823c71

Browse files
authored
Ensure InstallVersion() is case insensitive (#1598)
1 parent 57e630f commit d823c71

File tree

4 files changed

+97
-55
lines changed

4 files changed

+97
-55
lines changed

src/code/ACRServerAPICalls.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,12 @@ public override Stream InstallPackage(string packageName, string packageVersion,
305305
}
306306

307307
private Stream InstallVersion(
308-
string moduleName,
308+
string packageName,
309309
string moduleVersion,
310310
out ErrorRecord errRecord)
311311
{
312312
errRecord = null;
313+
string packageNameLowercase = packageName.ToLower();
313314
string accessToken = string.Empty;
314315
string tenantID = string.Empty;
315316
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
@@ -323,8 +324,8 @@ private Stream InstallVersion(
323324
}
324325

325326
string registry = Repository.Uri.Host;
326-
_cmdletPassedIn.WriteVerbose($"Getting manifest for {moduleName} - {moduleVersion}");
327-
var manifest = GetAcrRepositoryManifestAsync(registry, moduleName, moduleVersion, acrAccessToken, out errRecord);
327+
_cmdletPassedIn.WriteVerbose($"Getting manifest for {packageNameLowercase} - {moduleVersion}");
328+
var manifest = GetAcrRepositoryManifestAsync(registry, packageNameLowercase, moduleVersion, acrAccessToken, out errRecord);
328329
if (errRecord != null)
329330
{
330331
return null;
@@ -335,9 +336,9 @@ private Stream InstallVersion(
335336
return null;
336337
}
337338

338-
_cmdletPassedIn.WriteVerbose($"Downloading blob for {moduleName} - {moduleVersion}");
339+
_cmdletPassedIn.WriteVerbose($"Downloading blob for {packageNameLowercase} - {moduleVersion}");
339340
// TODO: error handling here?
340-
var responseContent = GetAcrBlobAsync(registry, moduleName, digest, acrAccessToken).Result;
341+
var responseContent = GetAcrBlobAsync(registry, packageNameLowercase, digest, acrAccessToken).Result;
341342

342343
return responseContent.ReadAsStreamAsync().Result;
343344
}

test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ Import-Module $modPath -Force -Verbose
77
Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
88

99
BeforeAll{
10-
$testModuleName = "test_local_mod"
10+
$testModuleName = "test-module"
1111
$testModuleParentName = "test_parent_mod"
1212
$testModuleDependencyName = "test_dependency_mod"
13-
$testScript = "testscript"
13+
$testScriptName = "test-script"
1414
$ACRRepoName = "ACRRepo"
1515
$ACRRepoUri = "https://psresourcegettest.azurecr.io"
1616
Get-NewPSResourceRepositoryFile
@@ -95,7 +95,7 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
9595
$res = Find-PSResource -Name $testModuleName -Repository $ACRRepoName -Prerelease
9696
$res.Name | Should -Be $testModuleName
9797
$res.Version | Should -Be "5.2.5"
98-
$res.Prerelease | Should -Be "alpha001"
98+
$res.Prerelease | Should -Be "alpha"
9999
}
100100

101101
It "Find resource with latest (including prerelease) version given Prerelease parameter" {
@@ -106,7 +106,7 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
106106

107107
$resPrerelease = Find-PSResource -Name $testModuleName -Prerelease -Repository $ACRRepoName
108108
$resPrerelease.Version | Should -Be "5.2.5"
109-
$resPrerelease.Prerelease | Should -Be "alpha001"
109+
$resPrerelease.Prerelease | Should -Be "alpha"
110110
}
111111

112112
It "Find resources, including Prerelease version resources, when given Prerelease parameter" {
@@ -161,44 +161,47 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
161161

162162
It "Should find script given Name" {
163163
# FindName()
164-
$res = Find-PSResource -Name $testScript -Repository $ACRRepoName
164+
$res = Find-PSResource -Name $testScriptName -Repository $ACRRepoName
165165
$res | Should -Not -BeNullOrEmpty
166-
$res.Name | Should -BeExactly $testScript
167-
$res.Version | Should -Be "2.0.0"
166+
$res.Name | Should -BeExactly $testScriptName
167+
$res.Version | Should -Be "3.0.0"
168+
$res.Type.ToString() | Should -Be "Script"
168169
}
169170

170171
It "Should find script given Name and Prerelease" {
171172
# latest version is a prerelease version
172-
$res = Find-PSResource -Name $testScript -Prerelease -Repository $ACRRepoName
173+
$res = Find-PSResource -Name $testScriptName -Prerelease -Repository $ACRRepoName
173174
$res | Should -Not -BeNullOrEmpty
174-
$res.Name | Should -BeExactly $testScript
175-
$res.Version | Should -Be "3.5.0"
175+
$res.Name | Should -BeExactly $testScriptName
176+
$res.Version | Should -Be "5.0.0"
176177
$res.Prerelease | Should -Be "alpha"
178+
$res.Type.ToString() | Should -Be "Script"
177179
}
178180

179181
It "Should find script given Name and Version" {
180182
# FindVersion()
181-
$res = Find-PSResource -Name $testScript -Version "1.0.0" -Repository $ACRRepoName
183+
$res = Find-PSResource -Name $testScriptName -Version "1.0.0" -Repository $ACRRepoName
182184
$res | Should -Not -BeNullOrEmpty
183-
$res.Name | Should -BeExactly $testScript
185+
$res.Name | Should -BeExactly $testScriptName
184186
$res.Version | Should -Be "1.0.0"
187+
$res.Type.ToString() | Should -Be "Script"
185188
}
186189

187190
It "Should find script given Name, Version and Prerelease" {
188191
# latest version is a prerelease version
189-
$res = Find-PSResource -Name $testScript -Version "3.5.0-alpha" -Prerelease -Repository $ACRRepoName
192+
$res = Find-PSResource -Name $testScriptName -Version "5.0.0-alpha" -Prerelease -Repository $ACRRepoName
190193
$res | Should -Not -BeNullOrEmpty
191-
$res.Name | Should -BeExactly $testScript
192-
$res.Version | Should -Be "3.5.0"
194+
$res.Name | Should -BeExactly $testScriptName
195+
$res.Version | Should -Be "5.0.0"
193196
$res.Prerelease | Should -Be "alpha"
197+
$res.Type.ToString() | Should -Be "Script"
194198
}
195199

196200
It "Should find and return correct resource type - module" {
197-
$moduleName = "test_dependency_mod"
198-
$res = Find-PSResource -Name $moduleName -Repository $ACRRepoName
201+
$res = Find-PSResource -Name $testModuleName -Repository $ACRRepoName
199202
$res | Should -Not -BeNullOrEmpty
200-
$res.Name | Should -BeExactly $moduleName
201-
$res.Version | Should -Be "1.0.0"
203+
$res.Name | Should -BeExactly $testModuleName
204+
$res.Version | Should -Be "5.0.0"
202205
$res.Type.ToString() | Should -Be "Module"
203206
}
204207

@@ -207,6 +210,20 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
207210
$res = Find-PSResource -Name $scriptName -Repository $ACRRepoName
208211
$res | Should -Not -BeNullOrEmpty
209212
$res.Name | Should -BeExactly $scriptName
213+
$res.Version | Should -Be "3.0.0"
214+
$res.Type.ToString() | Should -Be "Script"
215+
}
216+
217+
It "Should find module with varying case sensitivity" {
218+
$res = Find-PSResource -Name "test-camelCaseModule" -Repository $ACRRepoName
219+
$res.Name | Should -BeExactly "test-camelCaseModule"
220+
$res.Version | Should -Be "1.0.0"
221+
$res.Type.ToString() | Should -Be "Module"
222+
}
223+
224+
It "Should find script with varying case sensitivity" {
225+
$res = Find-PSResource -Name "test-camelCaseScript" -Repository $ACRRepoName
226+
$res.Name | Should -BeExactly "test-camelCaseScript"
210227
$res.Version | Should -Be "1.0.0"
211228
$res.Type.ToString() | Should -Be "Script"
212229
}

test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ Import-Module $modPath -Force -Verbose
88
Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' {
99

1010
BeforeAll {
11-
$testModuleName = "test_local_mod"
12-
$testModuleName2 = "test_local_mod2"
11+
$testModuleName = "test-module"
12+
$testModuleName2 = "test-module2"
13+
$testCamelCaseModuleName = "test-camelCaseModule"
14+
$testCamelCaseScriptName = "test-camelCaseScript"
1315
$testModuleParentName = "test_parent_mod"
1416
$testModuleDependencyName = "test_dependency_mod"
15-
$testScriptName = "testscript"
17+
$testScriptName = "test-script"
1618
$ACRRepoName = "ACRRepo"
1719
$ACRRepoUri = "https://psresourcegettest.azurecr.io/"
1820
Get-NewPSResourceRepositoryFile
@@ -31,16 +33,16 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' {
3133
}
3234

3335
AfterEach {
34-
Uninstall-PSResource $testModuleName, $testModuleName2, $testScriptName -Version "*" -SkipDependencyCheck -ErrorAction SilentlyContinue
36+
Uninstall-PSResource $testModuleName, $testModuleName2, $testCamelCaseModuleName, $testScriptName, $testCamelCaseScriptName -Version "*" -SkipDependencyCheck -ErrorAction SilentlyContinue
3537
}
3638

3739
AfterAll {
3840
Get-RevertPSResourceRepositoryFile
3941
}
4042

4143
$testCases = @{Name="*"; ErrorId="NameContainsWildcard"},
42-
@{Name="Test_local_m*"; ErrorId="NameContainsWildcard"},
43-
@{Name="Test?local","Test[local"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"}
44+
@{Name="Test-mod*"; ErrorId="NameContainsWildcard"},
45+
@{Name="Test?modu","Test[module"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"}
4446

4547
It "Should not install resource with wildcard in name" -TestCases $testCases {
4648
param($Name, $ErrorId)
@@ -62,7 +64,8 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' {
6264
Install-PSResource -Name $testScriptName -Repository $ACRRepoName -TrustRepository
6365
$pkg = Get-InstalledPSResource $testScriptName
6466
$pkg.Name | Should -BeExactly $testScriptName
65-
$pkg.Version | Should -Be "2.0.0"
67+
$pkg.Version | Should -Be "3.0.0"
68+
$pkg.Type.ToString() | Should -Be "Script"
6669
}
6770

6871
It "Install script resource by name and version" {
@@ -148,7 +151,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' {
148151
$pkg = Get-InstalledPSResource $testModuleName
149152
$pkg.Name | Should -Be $testModuleName
150153
$pkg.Version | Should -Be "5.2.5"
151-
$pkg.Prerelease | Should -Be "alpha001"
154+
$pkg.Prerelease | Should -Be "alpha"
152155
}
153156

154157
It "Install resource via InputObject by piping from Find-PSresource" {
@@ -159,11 +162,10 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' {
159162
}
160163

161164
It "Install resource with copyright, description and repository source location and validate properties" {
162-
$testModule = "test_module"
163-
Install-PSResource -Name $testModule -Version "7.0.0" -Repository $ACRRepoName -TrustRepository
164-
$pkg = Get-InstalledPSResource $testModule
165-
$pkg.Name | Should -Be $testModule
166-
$pkg.Version | Should -Be "7.0.0"
165+
Install-PSResource -Name $testModuleName -Version "3.0.0" -Repository $ACRRepoName -TrustRepository
166+
$pkg = Get-InstalledPSResource $testModuleName
167+
$pkg.Name | Should -Be $testModuleName
168+
$pkg.Version | Should -Be "3.0.0"
167169
$pkg.Copyright | Should -Be "(c) Anam Navied. All rights reserved."
168170
$pkg.Description | Should -Be "This is a test module, for PSGallery team internal testing. Do not take a dependency on this package. This version contains tags for the package."
169171
$pkg.RepositorySourceLocation | Should -Be $ACRRepoUri
@@ -231,7 +233,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' {
231233
}
232234

233235
It "Install PSResourceInfo object piped in" {
234-
Find-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $ACRRepoName | Install-PSResource -TrustRepository
236+
Find-PSResource -Name $testModuleName -Version "1.0.0" -Repository $ACRRepoName | Install-PSResource -TrustRepository
235237
$res = Get-InstalledPSResource -Name $testModuleName
236238
$res.Name | Should -Be $testModuleName
237239
$res.Version | Should -Be "1.0.0"
@@ -241,6 +243,22 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' {
241243
$res = Install-PSResource -Name $testModuleName -Repository $ACRRepoName -PassThru -TrustRepository
242244
$res.Name | Should -Contain $testModuleName
243245
}
246+
247+
It "Install module with varying case sensitivity" {
248+
Install-PSResource -Name $testCamelCaseModuleName -Repository $ACRRepoName -TrustRepository
249+
$res = Get-InstalledPSResource -Name $testCamelCaseModuleName
250+
$res.Name | Should -BeExactly $testCamelCaseModuleName
251+
$res.Version | Should -Be "1.0.0"
252+
$res.Type.ToString() | Should -Be "Module"
253+
}
254+
255+
It "Install script with varying case sensitivity" {
256+
Install-PSResource -Name $testCamelCaseScriptName -Repository $ACRRepoName -TrustRepository
257+
$res = Get-InstalledPSResource -Name $testCamelCaseScriptName
258+
$res.Name | Should -BeExactly $testCamelCaseScriptName
259+
$res.Version | Should -Be "1.0.0"
260+
$res.Type.ToString() | Should -Be "Script"
261+
}
244262
}
245263

246264
Describe 'Test Install-PSResource for V3Server scenarios' -tags 'ManualValidationOnly' {

test/PublishPSResourceTests/PublishPSResourceACRServer.Tests.ps1

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Describe "Test Publish-PSResource" -tags 'CI' {
7575
$script:ModuleWithoutRequiredModuleName = "temp-testmodulewithoutrequiredmodule-" + [System.Guid]::NewGuid()
7676
$script:ScriptName = "temp-testscript" + [System.Guid]::NewGuid()
7777
$script:ScriptWithExternalDeps = "temp-testscriptwithexternaldeps" + [System.Guid]::NewGuid()
78+
$script:ScriptWithoutEmptyLinesInMetadata = "temp-scriptwithoutemptylinesinmetadata" + [System.Guid]::NewGuid()
79+
$script:ScriptWithoutEmptyLinesBetweenCommentBlocks = "temp-scriptwithoutemptylinesbetweencommentblocks" + [System.Guid]::NewGuid()
7880

7981
# Create temp destination path
8082
$script:destinationPath = [IO.Path]::GetFullPath((Join-Path -Path $TestDrive -ChildPath "tmpDestinationPath"))
@@ -106,7 +108,7 @@ Describe "Test Publish-PSResource" -tags 'CI' {
106108
Get-RevertPSResourceRepositoryFile
107109

108110
# Note: all repository names provided as test packages for ACR, must have lower cased names, otherwise the Az cmdlets will not be able to properly find and delete it.
109-
$acrRepositoryNames = @($script:PublishModuleName, $script:ModuleWithoutRequiredModuleName, $script:ScriptName, $script:ScriptWithExternalDeps)
111+
$acrRepositoryNames = @($script:PublishModuleName, $script:ModuleWithoutRequiredModuleName, $script:ScriptName, $script:ScriptWithExternalDeps, $script:ScriptWithoutEmptyLinesInMetadata, $script:ScriptWithoutEmptyLinesBetweenCommentBlocks)
110112
Set-TestACRRepositories $acrRepositoryNames
111113
}
112114

@@ -360,36 +362,40 @@ Describe "Test Publish-PSResource" -tags 'CI' {
360362

361363
Publish-PSResource -Path $scriptPath -Repository $ACRRepoName
362364

363-
$results = Find-PSResource -Name $script:ScriptName -Repository $ACRRepoName
364-
$results | Should -Not -BeNullOrEmpty
365-
$results[0].Name | Should -Be $script:ScriptName
366-
$results[0].Version | Should -Be $scriptVersion
365+
$result = Find-PSResource -Name $script:ScriptName -Repository $ACRRepoName
366+
$result | Should -Not -BeNullOrEmpty
367+
$result.Name | Should -Be $script:ScriptName
368+
$result.Version | Should -Be $scriptVersion
367369
}
368370

369371
It "Should publish a script without lines in between comment blocks locally" {
370372
$scriptName = "ScriptWithoutEmptyLinesBetweenCommentBlocks"
371373
$scriptVersion = "1.0"
372-
$scriptPath = (Join-Path -Path $script:testScriptsFolderPath -ChildPath "$scriptName.ps1")
374+
$scriptSrcPath = Join-Path -Path $script:testScriptsFolderPath -ChildPath "$scriptName.ps1"
375+
$scriptDestPath = Join-Path -Path $script:tmpScriptsFolderPath -ChildPath "$script:ScriptWithoutEmptyLinesBetweenCommentBlocks.ps1"
376+
Copy-Item -Path $scriptSrcPath -Destination $scriptDestPath
373377

374-
Publish-PSResource -Path $scriptPath -Repository $ACRRepoName
378+
Publish-PSResource -Path $scriptDestPath -Repository $ACRRepoName
375379

376-
$results = Find-PSResource -Name $scriptName -Repository $ACRRepoName
377-
$results | Should -Not -BeNullOrEmpty
378-
$results[0].Name | Should -Be $scriptName
379-
$results[0].Version | Should -Be $scriptVersion
380+
$result = Find-PSResource -Name $script:ScriptWithoutEmptyLinesBetweenCommentBlocks -Repository $ACRRepoName
381+
$result | Should -Not -BeNullOrEmpty
382+
$result.Name | Should -Be $script:ScriptWithoutEmptyLinesBetweenCommentBlocks
383+
$result.Version | Should -Be $scriptVersion
380384
}
381385

382386
It "Should publish a script without lines in help block locally" {
383387
$scriptName = "ScriptWithoutEmptyLinesInMetadata"
384388
$scriptVersion = "1.0"
385-
$scriptPath = (Join-Path -Path $script:testScriptsFolderPath -ChildPath "$scriptName.ps1")
389+
$scriptSrcPath = Join-Path -Path $script:testScriptsFolderPath -ChildPath "$scriptName.ps1"
390+
$scriptDestPath = Join-Path -Path $script:tmpScriptsFolderPath -ChildPath "$script:ScriptWithoutEmptyLinesInMetadata.ps1"
391+
Copy-Item -Path $scriptSrcPath -Destination $scriptDestPath
386392

387-
Publish-PSResource -Path $scriptPath -Repository $ACRRepoName
393+
Publish-PSResource -Path $scriptDestPath -Repository $ACRRepoName
388394

389-
$results = Find-PSResource -Name $scriptName -Repository $ACRRepoName
390-
$results | Should -Not -BeNullOrEmpty
391-
$results[0].Name | Should -Be $scriptName
392-
$results[0].Version | Should -Be $scriptVersion
395+
$result = Find-PSResource -Name $script:ScriptWithoutEmptyLinesInMetadata -Repository $ACRRepoName
396+
$result | Should -Not -BeNullOrEmpty
397+
$result.Name | Should -Be $script:ScriptWithoutEmptyLinesInMetadata
398+
$result.Version | Should -Be $scriptVersion
393399
}
394400

395401
It "Should publish a script with ExternalModuleDependencies that are not published" {

0 commit comments

Comments
 (0)