mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 20:56:02 +00:00
Consolidation of all Windows PowerShell work ported to PSCore6 * Added ps1 file import restriction. Refactored InvokeLanguageModeTestingSupportCmdlet to HelpersSecurity module * JEA loop back fix. Debugger running commands in CL mode. * Support for new AMSI codes. Changed to use AMSI buffer API. Unhandled exception fix. * Fixes for module bugs while running in ConstrainedLanguage mode * Untrusted input tracking work * Configuration keyword bug fix, PSRP protocol version check for reconstruct reconnect, Sharing InitialSessionState in runspace pool. * Restricted remote session in UMCI, Applocker detection collision, Help command exposing functions, Null reference exception fix. * Added mitigation for debugger function exposure
66 lines
1.9 KiB
PowerShell
66 lines
1.9 KiB
PowerShell
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
|
|
##
|
|
## ----------
|
|
## Test Note:
|
|
## ----------
|
|
## Since these tests change session and system state (constrained language and system lockdown)
|
|
## they will all use try/finally blocks instead of Pester AfterEach/AfterAll to ensure session
|
|
## and system state is restored.
|
|
## Pester AfterEach, AfterAll is not reliable when the session is constrained language or locked down.
|
|
##
|
|
|
|
Import-Module HelpersSecurity
|
|
|
|
try
|
|
{
|
|
$defaultParamValues = $PSDefaultParameterValues.Clone()
|
|
$PSDefaultParameterValues["it:Skip"] = !$IsWindows
|
|
|
|
Describe "Importing PowerShell script files are not allowed in ConstrainedLanguage" -Tags 'CI','RequireAdminOnWindows' {
|
|
|
|
BeforeAll {
|
|
|
|
$scriptFileName = (Get-RandomFileName) + ".ps1"
|
|
$scriptFilePath = Join-Path $TestDrive $scriptFileName
|
|
'"Hello!"' > $scriptFilePath
|
|
}
|
|
|
|
It "Verifies that ps1 script file cannot be imported in ConstrainedLanguage mode" {
|
|
|
|
$err = $null
|
|
try
|
|
{
|
|
$ExecutionContext.SessionState.LanguageMode = "ConstrainedLanguage"
|
|
Import-Module -Name $scriptFilePath
|
|
throw "No Exception!"
|
|
}
|
|
catch
|
|
{
|
|
$err = $_
|
|
}
|
|
finally
|
|
{
|
|
Invoke-LanguageModeTestingSupportCmdlet -EnableFullLanguageMode
|
|
}
|
|
|
|
$err.FullyQualifiedErrorId | Should -BeExactly "Modules_ImportPSFileNotAllowedInConstrainedLanguage,Microsoft.PowerShell.Commands.ImportModuleCommand"
|
|
}
|
|
|
|
It "Verifies that ps1 script file can be imported in FullLangauge mode" {
|
|
|
|
{ Import-Module -Name $scriptFilePath } | Should -Not -Throw
|
|
}
|
|
}
|
|
|
|
# End Describe blocks
|
|
}
|
|
finally
|
|
{
|
|
if ($defaultParamValues -ne $null)
|
|
{
|
|
$Global:PSDefaultParameterValues = $defaultParamValues
|
|
}
|
|
}
|