Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Describe "Remote import-module tests" -Tags 'Feature','RequireAdminOnWindows' {
if ($IsWindows) {
$pssession | Remove-PSSession -ErrorAction SilentlyContinue
}

Remove-Module TestImport -Force -ErrorAction SilentlyContinue
}

BeforeEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ try
"@{ ModuleVersion='1.0'; RootModule='$moduleFilePathI' }" | Out-File $moduleManifestPathI

# Module with using directive
$sriptModuleNameJ = "ModuleWithUsing_System32"
$moduleFilePathJ = Join-Path $TestModulePath ($sriptModuleNameJ + ".psm1")
$scriptModuleNameJ = "ModuleWithUsing_System32"
$moduleFilePathJ = Join-Path $TestModulePath ($scriptModuleNameJ + ".psm1")
@'
using module {0}
function PublicUsingFn {{ [Class1]::GetMessage() }}
Expand All @@ -247,6 +247,19 @@ try
Write-Verbose "Test module files created"
}

AfterAll {
Remove-Module $scriptModuleNameA -Force -ErrorAction SilentlyContinue
Remove-Module $scriptModuleNameB -Force -ErrorAction SilentlyContinue
Remove-Module $scriptModuleNameC -Force -ErrorAction SilentlyContinue
Remove-Module $scriptModuleNameD -Force -ErrorAction SilentlyContinue
Remove-Module $scriptModuleNameE -Force -ErrorAction SilentlyContinue
Remove-Module $scriptModuleNameF -Force -ErrorAction SilentlyContinue
Remove-Module $scriptModuleNameG -Force -ErrorAction SilentlyContinue
Remove-Module $scriptModuleNameH -Force -ErrorAction SilentlyContinue
Remove-Module $scriptModuleNameI -Force -ErrorAction SilentlyContinue
Remove-Module $scriptModuleNameJ -Force -ErrorAction SilentlyContinue
}

It "Verifies that importing trusted module in system lockdown which dot sources a ps1 file while exporting all functions with wildcard throws expected error" {

try
Expand Down Expand Up @@ -457,6 +470,10 @@ try
"@{ ModuleVersion = '1.0'; RootModule = '$moduleFileName'; FunctionsToExport = 'PublicFn' }" > $manifestFileName
}

AfterAll {
Remove-Module ImportTrustedManifestWithCallOperator_System32 -Force -ErrorAction SilentlyContinue
}

It "Verifies expected error when call operator attempts to access trusted module scope function" {

try
Expand Down Expand Up @@ -638,6 +655,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportUnTrustedManifestWithFnExport_System32 -Force -ErrorAction SilentlyContinue
}

$expectedError.FullyQualifiedErrorId | Should -BeExactly "Modules_MismatchedLanguageModes,Microsoft.PowerShell.Commands.ImportModuleCommand"
Expand Down Expand Up @@ -807,6 +825,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportTrustedModuleWithNoFnExport_System32 -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 0
Expand Down Expand Up @@ -837,6 +856,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportTrustedModuleWithFnExport_System32 -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 1
Expand Down Expand Up @@ -868,6 +888,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportTrustedModuleWithWildcardFnExport_System32 -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 2
Expand Down Expand Up @@ -927,6 +948,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportTrustedManifestWithNoFnExport_System32 -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 0
Expand Down Expand Up @@ -957,6 +979,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportTrustedManifestWithWildcardFnExport1_System32 -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 0
Expand Down Expand Up @@ -987,6 +1010,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportTrustedManifestWithWildcardNameFnExport_System32 -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 0
Expand Down Expand Up @@ -1019,6 +1043,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportTrustedManifestWithWildcardModFnExport_System32 -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 1
Expand Down Expand Up @@ -1050,6 +1075,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportTrustedManifestWithCmdletExport_System32 -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 0
Expand Down Expand Up @@ -1092,6 +1118,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportTrustedManifestWithTwoMods_System32 -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 1
Expand Down Expand Up @@ -1124,6 +1151,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportTrustedManifestWithExportFn_System32 -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 1
Expand Down Expand Up @@ -1155,6 +1183,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportTrustedManifestWithNestedModsAndFnExport_System32 -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 1
Expand Down Expand Up @@ -1186,6 +1215,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportTrustedManifestWithNestedModsAndNoFnExport_System32 -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 0
Expand Down Expand Up @@ -1216,6 +1246,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportTrustedManifestWithNestedModsAndNoExtNoFnExport_System32 -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 1
Expand Down Expand Up @@ -1260,6 +1291,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportTrustedManifestWithDotSourceModAndFnExport_System32 -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 1
Expand Down Expand Up @@ -1305,6 +1337,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportUntrustedManifestWithNoFnExport -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 2
Expand Down Expand Up @@ -1335,6 +1368,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportUntrustedManifestWithFnExport -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 1
Expand Down Expand Up @@ -1365,6 +1399,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportUnTrustedModuleWithNoFnExport -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 2
Expand Down Expand Up @@ -1395,6 +1430,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module ImportUnTrustedModuleWithFnExport -Force -ErrorAction SilentlyContinue
}

$module.ExportedCommands.Count | Should -Be 1
Expand Down Expand Up @@ -1518,6 +1554,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
Remove-Module UntrustedScriptFoo -Force -ErrorAction SilentlyContinue
}

$result | Should -BeExactly "ConstrainedLanguage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ try
$template -f $configFilePath > $moduleFilePath
}

AfterAll {
Remove-Module $scriptModuleName -Force -ErrorAction SilentlyContinue
}

It "Verifies that a NoLanguage runspace pool throws the expected 'script not allowed' error" {

try
Expand Down Expand Up @@ -405,6 +409,7 @@ try
finally
{
Invoke-LanguageModeTestingSupportCmdlet -EnableFullLanguageMode
Remove-Module PSDiagnostics -Force -ErrorAction SilentlyContinue
}

$expectedError.FullyQualifiedErrorId | Should -BeExactly "CantInvokeCallOperatorAcrossLanguageBoundaries"
Expand Down Expand Up @@ -889,17 +894,17 @@ try
$PSDefaultParameterValues["it:skip"] = $true
}
}

AfterAll {

if ($skipTest) {
$global:PSDefaultParameterValues = $originalDefaultParameterValues
}
}

It 'Foreach-Object -Parallel must run in ConstrainedLanguage mode under system lock down' {

try
try
{
$ExecutionContext.SessionState.LanguageMode = "ConstrainedLanguage"
Invoke-LanguageModeTestingSupportCmdlet -SetLockdownMode
Expand Down Expand Up @@ -940,6 +945,10 @@ try
'@ -f $scriptFilePath | Out-File -FilePath $scriptModulePath
}

AfterAll {
Remove-Module $scriptModuleName -Force -ErrorAction SilentlyContinue
}

It "Verifies a scriptblock from a trusted script file does not run as trusted" {

$result = $null
Expand Down Expand Up @@ -985,6 +994,11 @@ try
'@ -f $importModulePath | Out-File -FilePath $scriptModulePath
}

AfterAll {
Remove-Module $importModuleName -Force -ErrorAction SilentlyContinue
Remove-Module $scriptModuleName -Force -ErrorAction SilentlyContinue
}

It "Verifies that trusted module functions run in FullLanguage" {

$result1 = $null
Expand Down Expand Up @@ -1040,6 +1054,7 @@ try
AfterAll {

Remove-Module -Name T1ScriptClass_System32 -Force -ErrorAction Ignore
Remove-Module -Name T1ScriptClass -Force -ErrorAction Ignore
}

It "Verifies that classes cannot be created in script running under constrained language" {
Expand Down