Skip to content

Commit

Permalink
Fix failing test that checks for runtime loaded assembly when running…
Browse files Browse the repository at this point in the history
… in serial (#15637)
  • Loading branch information
aparajit-pratap authored Nov 14, 2024
1 parent f760711 commit 421e48e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/Dynamo.All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DynamoPythonTests", "..\tes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DynamoMLDataPipeline", "DynamoMLDataPipeline\DynamoMLDataPipeline.csproj", "{5DF79F45-5F2C-41C1-BACC-890AE514CDA8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestCodeBlockNodeSecurityIssue", "..\test\Engine\TestCodeBlockNodeSecurityIssue\TestCodeBlockNodeSecurityIssue.csproj", "{0E822F71-154F-4442-BBD6-382181A7415C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -530,6 +532,10 @@ Global
{5DF79F45-5F2C-41C1-BACC-890AE514CDA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5DF79F45-5F2C-41C1-BACC-890AE514CDA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5DF79F45-5F2C-41C1-BACC-890AE514CDA8}.Release|Any CPU.Build.0 = Release|Any CPU
{0E822F71-154F-4442-BBD6-382181A7415C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E822F71-154F-4442-BBD6-382181A7415C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E822F71-154F-4442-BBD6-382181A7415C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E822F71-154F-4442-BBD6-382181A7415C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -609,6 +615,7 @@ Global
{AE7F2579-104A-4AF4-AA7B-614AE9E79279} = {5B9B5B6B-0BA7-4606-B8E5-70C958346D57}
{C4964946-B367-44EE-9ED2-451FF2A83D32} = {5B9B5B6B-0BA7-4606-B8E5-70C958346D57}
{773988FE-EDF6-45CB-A63F-482955EB3553} = {4CA0BC62-DCB3-456B-80D6-348247640BAB}
{0E822F71-154F-4442-BBD6-382181A7415C} = {91C57567-DDF1-409A-880B-3A290A486AAC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {89CB19C6-BF0A-4E6A-BFDA-79D143EAB59D}
Expand Down
15 changes: 15 additions & 0 deletions src/DynamoCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSOffice", "Libraries\DSOff
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSOfficeUtilities", "Libraries\DSOfficeUtilities\DSOfficeUtilities.csproj", "{9B4FDC96-E2F9-4B8F-894A-4294405D50E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestCodeBlockNodeSecurityIssue", "..\test\Engine\TestCodeBlockNodeSecurityIssue\TestCodeBlockNodeSecurityIssue.csproj", "{03E83DF3-097F-4710-832C-3CA4445D9917}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -589,6 +591,18 @@ Global
{9B4FDC96-E2F9-4B8F-894A-4294405D50E7}.Release|Any CPU.Build.0 = Release|Any CPU
{9B4FDC96-E2F9-4B8F-894A-4294405D50E7}.Release|NET_Linux.ActiveCfg = Release|NET_Linux
{9B4FDC96-E2F9-4B8F-894A-4294405D50E7}.Release|Publish_Linux.ActiveCfg = Release|Publish_Linux
{03E83DF3-097F-4710-832C-3CA4445D9917}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03E83DF3-097F-4710-832C-3CA4445D9917}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03E83DF3-097F-4710-832C-3CA4445D9917}.Debug|NET_Linux.ActiveCfg = Debug|NET_Linux
{03E83DF3-097F-4710-832C-3CA4445D9917}.Debug|NET_Linux.Build.0 = Debug|NET_Linux
{03E83DF3-097F-4710-832C-3CA4445D9917}.Debug|Publish_Linux.ActiveCfg = Debug|Publish_Linux
{03E83DF3-097F-4710-832C-3CA4445D9917}.Debug|Publish_Linux.Build.0 = Debug|Publish_Linux
{03E83DF3-097F-4710-832C-3CA4445D9917}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03E83DF3-097F-4710-832C-3CA4445D9917}.Release|Any CPU.Build.0 = Release|Any CPU
{03E83DF3-097F-4710-832C-3CA4445D9917}.Release|NET_Linux.ActiveCfg = Release|NET_Linux
{03E83DF3-097F-4710-832C-3CA4445D9917}.Release|NET_Linux.Build.0 = Release|NET_Linux
{03E83DF3-097F-4710-832C-3CA4445D9917}.Release|Publish_Linux.ActiveCfg = Release|Publish_Linux
{03E83DF3-097F-4710-832C-3CA4445D9917}.Release|Publish_Linux.Build.0 = Release|Publish_Linux
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -630,6 +644,7 @@ Global
{61169E56-DED9-464F-B800-AE31AEC1F750} = {FA7BE306-A3B0-45FA-9D87-0C69E6932C13}
{6CC1E399-B5A5-4FA2-A98C-5D8B2BA280A1} = {FA7BE306-A3B0-45FA-9D87-0C69E6932C13}
{9B4FDC96-E2F9-4B8F-894A-4294405D50E7} = {FA7BE306-A3B0-45FA-9D87-0C69E6932C13}
{03E83DF3-097F-4710-832C-3CA4445D9917} = {9739B26B-F223-458C-88AA-88D11E025EA0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {89CB19C6-BF0A-4E6A-BFDA-79D143EAB59D}
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoInstall/DynamoInstall.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<Output TaskParameter="Value" PropertyName="DefineConstants" />
</CreateProperty>
<Exec Command="rd /s /q $(DYNAMO_HARVEST_PATH)" />
<Exec Command="robocopy $(DYNAMO_BASE_PATH)\bin\AnyCPU\$(Configuration) $(DYNAMO_HARVEST_PATH) -XF %2aTest%2a.dll %2a.pdb TestResult.xml %2a.deps.json -e -XD int -XD Revit_2016 -XD Revit_2017 -XD Revit_2018 -XD samples -XD 0.8" IgnoreExitCode="true" />
<Exec Command="robocopy $(DYNAMO_BASE_PATH)\bin\AnyCPU\$(Configuration) $(DYNAMO_HARVEST_PATH) -XF %2aTest%2a.dll %2a.pdb %2aTest%2a.runtimeconfig.json TestResult.xml FFITarget.dll FFITarget.Migrations.xml FFITarget.runtimeconfig.json TestCodeBlockNodeSecurityIssue.dll ProtoTestConsoleRunner.exe %2a.deps.json nunit.%2a.dll -e -XD int -XD samples -XD 0.8" IgnoreExitCode="true" />
<Exec Command="$(DYNAMO_BASE_PATH)\tools\install\Extra\InstallerSpec.exe $(DYNAMO_HARVEST_PATH) $(DYNAMO_HARVEST_PATH)\InstallSpec.xml /f:$(DYNAMO_BASE_PATH)\tools\install\Extra\additional-files-to-sign.txt" IgnoreExitCode="false" />
<Exec Condition="Exists('$(MSBuildProjectDirectory)\Digital_Sign.bat')" Command="$(MSBuildProjectDirectory)\Digital_Sign.bat $(DYNAMO_HARVEST_PATH)\binariestosign.txt" IgnoreExitCode="false" />

Expand Down
9 changes: 5 additions & 4 deletions test/DynamoCoreTests/CodeBlockNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Loader;
using CoreNodeModels;
using Dynamo.Engine.CodeCompletion;
using Dynamo.Graph;
Expand Down Expand Up @@ -1807,14 +1808,14 @@ public void ImportStatementInCodeBlock_DoesNotLoadAssemblyIntoProcess()
var codeBlockNode = CreateCodeBlockNode();
var guid = codeBlockNode.GUID.ToString();

string assemblyName = "FFITarget";
string assemblyName = "TestCodeBlockNodeSecurityIssue";
UpdateCodeBlockNodeContent(codeBlockNode, $"import(\"{assemblyName}.dll\")");

var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
var loadedAssemblies = AssemblyLoadContext.All.SelectMany(context => context.Assemblies);

var ffiTargetAsm = loadedAssemblies.Any(assembly => assembly.GetName().Name.Equals(assemblyName, StringComparison.OrdinalIgnoreCase));
var asm = loadedAssemblies.Any(assembly => assembly.GetName().Name.Equals(assemblyName, StringComparison.OrdinalIgnoreCase));

Assert.False(ffiTargetAsm);
Assert.False(asm);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace TestCodeBlockNodeSecurityIssue
{
/// <summary>
/// This project assembly is used in
/// Dynamo.Tests.CodeBlockNodeTests.ImportStatementInCodeBlock_DoesNotLoadAssemblyIntoProcess
/// to test a security issue in CodeBlockNodes where an import statement
/// would unexpectedly load the assembly into the process.
/// This should be prevented as import statements are not permitted in CBNs
/// and therefore should not be loaded into the process in the first place.
/// NOTE: This assembly shouldn't be used in any other tests.
/// </summary>
public class TestCodeBlockNodeSecurityIssue
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<ImportGroup Label="PropertySheets">
<Import Project="$(SolutionDir)Config/CS_SDK.props" />
</ImportGroup>

</Project>

0 comments on commit 421e48e

Please sign in to comment.