Bump module version to 1.5.4 and update Invoke-GiteaFileDownload to handle URL encoded characters in file names. Update pester tests to account for changes.
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
RootModule = 'PS-GiteaUtilities.psm1'
|
RootModule = 'PS-GiteaUtilities.psm1'
|
||||||
|
|
||||||
# Version number of this module.
|
# Version number of this module.
|
||||||
ModuleVersion = '1.5.3'
|
ModuleVersion = '1.5.4'
|
||||||
|
|
||||||
# Supported PSEditions
|
# Supported PSEditions
|
||||||
# CompatiblePSEditions = @()
|
# CompatiblePSEditions = @()
|
||||||
|
|||||||
@@ -476,6 +476,7 @@ Function Invoke-GiteaFileDownload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$DownloadFilePath = [System.Uri]::UnescapeDataString($DownloadFilePath)
|
$DownloadFilePath = [System.Uri]::UnescapeDataString($DownloadFilePath)
|
||||||
|
$DownloadFileName = [System.Uri]::UnescapeDataString($DownloadFileName)
|
||||||
|
|
||||||
if ($PreserveRelativePath -and $outputPath) {
|
if ($PreserveRelativePath -and $outputPath) {
|
||||||
# If PreserveRelativePath is used, set up the directory structure
|
# If PreserveRelativePath is used, set up the directory structure
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
|
|
||||||
Context 'When all parameters are valid' {
|
Context 'When all parameters are valid' {
|
||||||
It 'Should download a file successfully' {
|
It 'Should download a file successfully' {
|
||||||
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/raw/path/to/file.txt' -token 'abc123'
|
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/test/example/raw/branch/dev/path/to/file.txt' -token 'abc123'
|
||||||
|
|
||||||
$result | Should -Not -BeNullOrEmpty
|
$result | Should -Not -BeNullOrEmpty
|
||||||
$result.Result | Should -Be 'Success'
|
$result.Result | Should -Be 'Success'
|
||||||
@@ -56,7 +56,7 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
|
|
||||||
Context 'When specifying an outputPath' {
|
Context 'When specifying an outputPath' {
|
||||||
It 'Should create a path based on outputPath' {
|
It 'Should create a path based on outputPath' {
|
||||||
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/raw/path/to/file.txt' `
|
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/test/example/raw/branch/dev/path/to/file.txt' `
|
||||||
-outputPath 'docs/manual/' -token 'abc123'
|
-outputPath 'docs/manual/' -token 'abc123'
|
||||||
|
|
||||||
$result.Path | Should -Match 'docs[\\/]+manual[\\/]+file\.txt$'
|
$result.Path | Should -Match 'docs[\\/]+manual[\\/]+file\.txt$'
|
||||||
@@ -66,7 +66,7 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
|
|
||||||
Context 'When specifying an outputName' {
|
Context 'When specifying an outputName' {
|
||||||
It 'Should download file and name it based on outputName' {
|
It 'Should download file and name it based on outputName' {
|
||||||
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/raw/path/to/file.txt' `
|
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/test/example/raw/branch/dev/path/to/file.txt' `
|
||||||
-outputName 'newfile.txt' -token 'abc123'
|
-outputName 'newfile.txt' -token 'abc123'
|
||||||
|
|
||||||
$result.Path | Should -Match 'newfile\.txt$'
|
$result.Path | Should -Match 'newfile\.txt$'
|
||||||
@@ -76,7 +76,7 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
|
|
||||||
Context 'When specifying an outputName and outputPath' {
|
Context 'When specifying an outputName and outputPath' {
|
||||||
It 'Should download file and name it based on outputName' {
|
It 'Should download file and name it based on outputName' {
|
||||||
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/raw/path/to/file.txt' `
|
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/test/example/raw/branch/dev/path/to/file.txt' `
|
||||||
-outputPath 'docs/manual/' -outputName 'newfile.txt' -token 'abc123'
|
-outputPath 'docs/manual/' -outputName 'newfile.txt' -token 'abc123'
|
||||||
|
|
||||||
$result.Path | Should -Match 'docs[\\/]+manual[\\/]+newfile\.txt$'
|
$result.Path | Should -Match 'docs[\\/]+manual[\\/]+newfile\.txt$'
|
||||||
@@ -86,12 +86,20 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
|
|
||||||
Context 'When using -PreserveRelativePath' {
|
Context 'When using -PreserveRelativePath' {
|
||||||
It 'Should preserve the relative path structure' {
|
It 'Should preserve the relative path structure' {
|
||||||
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/raw/path/to/file.txt' `
|
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/test/example/raw/branch/dev/path/to/file.txt' `
|
||||||
-PreserveRelativePath -token 'abc123'
|
-PreserveRelativePath -token 'abc123'
|
||||||
|
|
||||||
$result.Path | Should -Match 'path[\\/]+to[\\/]+file\.txt$'
|
$result.Path | Should -Match 'path[\\/]+to[\\/]+file\.txt$'
|
||||||
$result.Result | Should -Be 'Success'
|
$result.Result | Should -Be 'Success'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It 'Should ensure the outputPath does not contain any URL encoding' {
|
||||||
|
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/test/example/raw/branch/dev/Client%20Files/Certificates/file name.txt' `
|
||||||
|
-PreserveRelativePath -token 'abc123'
|
||||||
|
|
||||||
|
$result.Path | Should -Match 'Client[ ]Files[\\/]+Certificates[\\/]+file name\.txt$'
|
||||||
|
$result.Result | Should -Be 'Success'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context 'When skipping directories' {
|
Context 'When skipping directories' {
|
||||||
@@ -113,7 +121,7 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
}
|
}
|
||||||
|
|
||||||
It 'Should not overwrite existing file without Force' {
|
It 'Should not overwrite existing file without Force' {
|
||||||
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/raw/path/to/existingfile.txt' -token 'abc123'
|
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/test/example/raw/branch/dev/path/to/existingfile.txt' -token 'abc123'
|
||||||
|
|
||||||
$result.Result | Should -Be 'Skipped'
|
$result.Result | Should -Be 'Skipped'
|
||||||
}
|
}
|
||||||
@@ -141,7 +149,7 @@ Describe 'Invoke-GiteaFileDownload' {
|
|||||||
}
|
}
|
||||||
|
|
||||||
It 'Should capture error and mark download as failed' {
|
It 'Should capture error and mark download as failed' {
|
||||||
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/raw/path/to/badfile.txt' -token 'abc123'
|
$result = Invoke-GiteaFileDownload -downloadURL 'https://gitea.example.com/test/example/raw/branch/dev/path/to/badfile.txt' -token 'abc123'
|
||||||
|
|
||||||
$result.Result | Should -Be 'Failure'
|
$result.Result | Should -Be 'Failure'
|
||||||
$result.Error | Should -Match 'Failed to download'
|
$result.Error | Should -Match 'Failed to download'
|
||||||
|
|||||||
Reference in New Issue
Block a user