/// <summary>
 /// Excised section from TestPluginCompliance. Tests the specified AssemblyDefinition against all chosen security tests.
 /// </summary>
 /// <param name="testConfig">Mirror.</param>
 /// <param name="asmDef">Mirror.</param>
 /// <param name="singleResult">Mirror.</param>
 private static void RunCecilTests(SecurityLevelComplianceTestConfiguration testConfig, AssemblyDefinition asmDef, SecurityLevelComplianceSingleTestResult singleResult)
 {
     // Run the tests
     if (testConfig.RunLevel1Test)
     {
         SecurityComplianceSingleCecilTestResult level1TestResults = SecurityComplianceCecilTests.TestLevel1(asmDef);
         singleResult.TestedLevel1 = true;
         singleResult.PassLevel1   = level1TestResults.Passed;
         singleResult.MessagesLevel1.AddRange(level1TestResults.Messages);
     }
     if (testConfig.RunLevel2Test)
     {
         SecurityComplianceSingleCecilTestResult level2TestResults = SecurityComplianceCecilTests.TestLevel2(asmDef);
         singleResult.TestedLevel2 = true;
         singleResult.PassLevel2   = level2TestResults.Passed;
         singleResult.MessagesLevel2.AddRange(level2TestResults.Messages);
     }
     if (testConfig.RunLevel3Test)
     {
         SecurityComplianceSingleCecilTestResult level3TestResults = SecurityComplianceCecilTests.TestLevel3(asmDef);
         singleResult.TestedLevel3 = true;
         singleResult.PassLevel3   = level3TestResults.Passed;
         singleResult.MessagesLevel3.AddRange(level3TestResults.Messages);
     }
     if (testConfig.RunLevel4Test)
     {
         SecurityComplianceSingleCecilTestResult level4TestResults = SecurityComplianceCecilTests.TestLevel4(asmDef);
         singleResult.TestedLevel4 = true;
         singleResult.PassLevel4   = level4TestResults.Passed;
         singleResult.MessagesLevel4.AddRange(level4TestResults.Messages);
     }
 }
Example #2
0
        /// <summary>
        /// Tests all found PluginFiles against all security levels so as to determine the maximum security level that will allow each plugin to function.
        /// </summary>
        /// <param name="terrariaPath">Path to Terraria.exe, which will be referenced by CodeDom during compilation.</param>
        /// <param name="terrariaDependencyAssemblies">List of Terraria.exe's embedded dependency assemblies, which will be temporarily written to disk and reference by CodeDom during compilation.</param>
        /// <returns>A SecurityLevelComplianceTestResult object containing the test results.</returns>
        public static SecurityLevelComplianceTestsResults TestAllSecurityLevelComplianceForAllPlugins(string terrariaPath, List <byte[]> terrariaDependencyAssemblies)
        {
            SecurityLevelComplianceTestConfiguration config = new SecurityLevelComplianceTestConfiguration();

            config.PluginFilesToTest = new List <PluginFile>();
            config.PluginFilesToTest.AddRange(FoundUserPluginFiles);
            config.TerrariaPath = terrariaPath;
            config.TerrariaDependencyAssemblies = terrariaDependencyAssemblies;
            return(SecurityComplianceCecilTests.TestPluginCompliance(config));
        }