New-ModuleManifest was incorrectly checking if a Uri was well formed by using ToString() which just outputs the original (#3631)

string.  If the string was a uri with spaces, ToString() doesn't return the escaped version.  The AbsoluteUri property
should be used instead which returns an escaped absolute uri (if valid).

Also renamed TestModuleManfest.ps1 to TestModuleManifest.Tests.ps1 so that it gets picked up correctly as Pester test.

Since HelpInfoUri is just a string, ensure it is a valid absolute uri and escaped correctly whereas before it was just
an opaque string that wasn't validated.
This commit is contained in:
Steve Lee
2017-04-25 17:45:24 -07:00
committed by Mike Richmond
parent f8f603ada6
commit ee9049b61f
3 changed files with 64 additions and 6 deletions
@@ -0,0 +1,30 @@
Import-Module $PSScriptRoot\..\..\Common\Test.Helpers.psm1
Describe "New-ModuleManifest tests" -tags "CI" {
BeforeEach {
New-Item -ItemType Directory -Path testdrive:/module
$testModulePath = "testdrive:/module/test.psd1"
}
AfterEach {
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue testdrive:/module
}
It "Uris with spaces are allowed and escaped correctly" {
$testUri = [Uri]"http://foo.com/hello world"
$absoluteUri = $testUri.AbsoluteUri
New-ModuleManifest -Path $testModulePath -ProjectUri $testUri -LicenseUri $testUri -IconUri $testUri -HelpInfoUri $testUri
$module = Test-ModuleManifest -Path $testModulePath
$module.HelpInfoUri | Should BeExactly $absoluteUri
$module.PrivateData.PSData.IconUri | Should BeExactly $absoluteUri
$module.PrivateData.PSData.LicenseUri | Should BeExactly $absoluteUri
$module.PrivateData.PSData.ProjectUri | Should BeExactly $absoluteUri
}
It "Relative URIs are not allowed" {
$testUri = [Uri]"../foo"
{ New-ModuleManifest -Path $testModulePath -ProjectUri $testUri -LicenseUri $testUri -IconUri $testUri } | ShouldBeErrorId "System.InvalidOperationException,Microsoft.PowerShell.Commands.NewModuleManifestCommand"
}
}