MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Describe "Validate start of console host" -Tag CI {5 BeforeAll {6 $allowedAssemblies = @(7 'Microsoft.ApplicationInsights.dll'8 'Microsoft.Management.Infrastructure.dll'9 'Microsoft.PowerShell.ConsoleHost.dll'10 'Microsoft.Win32.Primitives.dll'11 'Microsoft.Win32.Registry.dll'12 'netstandard.dll'13 'Newtonsoft.Json.dll'14 'pwsh.dll'15 'System.Collections.Concurrent.dll'16 'System.Collections.dll'17 'System.Collections.Specialized.dll'18 'System.ComponentModel.dll'19 'System.ComponentModel.Primitives.dll'20 'System.ComponentModel.TypeConverter.dll'21 'System.Console.dll'22 'System.Data.Common.dll'23 'System.Diagnostics.Process.dll'24 'System.Diagnostics.TraceSource.dll'25 'System.Diagnostics.Tracing.dll'26 'System.IO.FileSystem.AccessControl.dll'27 'System.IO.FileSystem.DriveInfo.dll'28 'System.IO.Pipes.dll'29 'System.Linq.dll'30 'System.Linq.Expressions.dll'31 'System.Management.Automation.dll'32 'System.Memory.dll'33 'System.Net.Mail.dll'34 'System.Net.NetworkInformation.dll'35 'System.Net.Primitives.dll'36 'System.Numerics.Vectors.dll'37 'System.ObjectModel.dll'38 'System.Private.CoreLib.dll'39 'System.Private.Uri.dll'40 'System.Private.Xml.dll'41 'System.Reflection.Emit.ILGeneration.dll'42 'System.Reflection.Emit.Lightweight.dll'43 'System.Reflection.Primitives.dll'44 'System.Runtime.dll'45 'System.Runtime.InteropServices.dll'46 'System.Runtime.Loader.dll'47 'System.Runtime.Numerics.dll'48 'System.Runtime.Serialization.Formatters.dll'49 'System.Runtime.Serialization.Primitives.dll'50 'System.Security.AccessControl.dll'51 'System.Security.Cryptography.dll'52 'System.Security.Principal.Windows.dll'53 'System.Text.Encoding.CodePages.dll'54 'System.Text.Encoding.Extensions.dll'55 'System.Text.RegularExpressions.dll'56 'System.Threading.dll'57 'System.Threading.Tasks.Parallel.dll'58 'System.Threading.Thread.dll'59 'System.Threading.ThreadPool.dll'60 'System.Xml.ReaderWriter.dll'61 )62 63 if ($IsWindows) {64 $allowedAssemblies += @(65 'Microsoft.PowerShell.CoreCLR.Eventing.dll'66 'System.DirectoryServices.dll'67 'System.Management.dll'68 'System.Security.Claims.dll'69 'System.Threading.Overlapped.dll'70 )71 }72 else {73 $allowedAssemblies += @(74 'System.Diagnostics.DiagnosticSource.dll'75 'System.Net.Sockets.dll'76 )77 }78 79 if ($IsWindows) {80 $profileDataFile = Join-Path $env:LOCALAPPDATA "Microsoft\PowerShell\StartupProfileData-NonInteractive"81 } else {82 $profileDataFile = Join-Path ([System.Management.Automation.Platform]::SelectProductNameForDirectory("CACHE")) "StartupProfileData-NonInteractive"83 }84 85 if (Test-Path $profileDataFile) {86 Remove-Item $profileDataFile -Force87 }88 89 $loadedAssemblies = & "$PSHOME/pwsh" -noprofile -command '([System.AppDomain]::CurrentDomain.GetAssemblies()).manifestmodule | Where-Object { $_.Name -notlike "<*>" } | ForEach-Object { $_.Name }'90 }91 92 It "No new assemblies are loaded" {93 if ( (Get-PlatformInfo).Platform -eq "alpine" ) {94 Set-ItResult -Pending -Because "Missing MI library causes list to be different"95 return96 }97 98 $diffs = Compare-Object -ReferenceObject $allowedAssemblies -DifferenceObject $loadedAssemblies99 100 if ($null -ne $diffs) {101 $assembliesAllowedButNotLoaded = $diffs | Where-Object SideIndicator -EQ "<=" | ForEach-Object InputObject102 $assembliesLoadedButNotAllowed = $diffs | Where-Object SideIndicator -EQ "=>" | ForEach-Object InputObject103 104 if ($assembliesAllowedButNotLoaded) {105 Write-Host ("Assemblies that are expected but not loaded: {0}" -f ($assembliesAllowedButNotLoaded -join ", "))106 }107 if ($assembliesLoadedButNotAllowed) {108 Write-Host ("Assemblies that are loaded but not expected: {0}" -f ($assembliesLoadedButNotAllowed -join ", "))109 }110 }111 112 $diffs | Should -BeExactly $null113 }114}115 