mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 20:56:02 +00:00
Based on standard practices, we need to have a copyright and license notice at the top of each source file. Removed existing copyrights and updated/added copyright notices for .h, .cpp, .cs, .ps1, and .psm1 files. Updated module manifests for consistency to have Author = "PowerShell" and Company = "Microsoft Corporation". Removed multiple line breaks. Separate PR coming to update contribution document for new source files: #6140 Manually reviewed each change. Fix #6073
78 lines
2.5 KiB
PowerShell
78 lines
2.5 KiB
PowerShell
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
function Test-UnblockFile {
|
|
try {
|
|
Get-Content -Path $testfilepath -Stream Zone.Identifier -ErrorAction Stop | Out-Null
|
|
}
|
|
catch {
|
|
if ($_.FullyQualifiedErrorId -eq "GetContentReaderFileNotFoundError,Microsoft.PowerShell.Commands.GetContentCommand") {
|
|
return $true
|
|
}
|
|
}
|
|
|
|
return $false
|
|
}
|
|
|
|
Describe "Unblock-File" -Tags "CI" {
|
|
|
|
BeforeAll {
|
|
if ( ! $IsWindows )
|
|
{
|
|
$origDefaults = $PSDefaultParameterValues.Clone()
|
|
$PSDefaultParameterValues['it:skip'] = $true
|
|
|
|
} else {
|
|
$testfilepath = Join-Path -Path $TestDrive -ChildPath testunblockfile.ttt
|
|
}
|
|
}
|
|
|
|
AfterAll {
|
|
if ( ! $IsWindows ){
|
|
$global:PSDefaultParameterValues = $origDefaults
|
|
}
|
|
}
|
|
|
|
BeforeEach {
|
|
if ( $IsWindows ){
|
|
Set-Content -Value "[ZoneTransfer]`r`nZoneId=4" -Path $testfilepath -Stream Zone.Identifier
|
|
}
|
|
}
|
|
|
|
It "With '-Path': no file exist" {
|
|
{ Unblock-File -Path nofileexist.ttt -ErrorAction Stop } | ShouldBeErrorId "FileNotFound,Microsoft.PowerShell.Commands.UnblockFileCommand"
|
|
}
|
|
|
|
It "With '-LiteralPath': no file exist" {
|
|
{ Unblock-File -LiteralPath nofileexist.ttt -ErrorAction Stop } | ShouldBeErrorId "FileNotFound,Microsoft.PowerShell.Commands.UnblockFileCommand"
|
|
}
|
|
|
|
It "With '-Path': file exist" {
|
|
Unblock-File -Path $testfilepath
|
|
Test-UnblockFile | Should Be $true
|
|
|
|
# If a file is not blocked we silently return without an error.
|
|
{ Unblock-File -Path $testfilepath -ErrorAction Stop } | Should Not Throw
|
|
}
|
|
|
|
It "With '-LiteralPath': file exist" {
|
|
Unblock-File -LiteralPath $testfilepath
|
|
Test-UnblockFile | Should Be $true
|
|
}
|
|
|
|
It "Write an error if a file is read only" {
|
|
$TestFile = Join-Path $TestDrive "testfileunlock.ps1"
|
|
Set-Content -Path $TestFile -value 'test'
|
|
$ZoneIdentifier = {
|
|
[ZoneTransfer]
|
|
ZoneId=3
|
|
}
|
|
Set-Content -Path $TestFile -Value $ZoneIdentifier -Stream 'Zone.Identifier'
|
|
Set-ItemProperty -Path $TestFile -Name IsReadOnly -Value $True
|
|
|
|
$TestFileCreated = Get-ChildItem $TestFile
|
|
$TestFileCreated.IsReadOnly | Should Be $true
|
|
|
|
{ Unblock-File -LiteralPath $TestFile -ErrorAction Stop } | ShouldBeErrorId "RemoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.UnblockFileCommand"
|
|
}
|
|
}
|