public string invokeStrutsRules_Variation_1_UsingPreCalculatedO2StrutsMappingFile() { var strutsMappingsFile = @"...\_OunceApplication\O2Data\....O2StrutsMapping"; var baseO2FindingsFile = @"...\_OunceApplication\O2Data\....ozasmt"; // make sure these files exist Assert.That(File.Exists(strutsMappingsFile), "Could not find file with strutsMappingsFile:\r\n " + strutsMappingsFile); Assert.That(File.Exists(baseO2FindingsFile), "Could not find file with baseO2FindingsFile:\r\n " + baseO2FindingsFile); // load the files var strutsMapping = XUtils_Struts_v0_1.loadStrutsMappingsFromFile(strutsMappingsFile); var baseO2Findings = XUtils_Findings_v0_1.loadFindingsFile(baseO2FindingsFile); // make sure the file where correctly loaded Assert.That(strutsMapping != null, "strutsMapping was null"); Assert.That(baseO2Findings != null, "baseO2Findings was null"); Assert.That(baseO2Findings.Count > 0, "baseO2Findings had no findings"); // execute the struts rule var o2Results = XRule_Struts.strutsRule_fromGetParameterToPringViaGetSetAttributeJoins(baseO2Findings, strutsMapping); // make sure we had results Assert.That(o2Results.Count > 0, "There were no results"); // save results var fileWithSavedResults = XUtils_Findings_v0_1.saveFindings(o2Results); // make sure saved file exists Assert.That(fileWithSavedResults != null, "fileWithSavedResults was null"); Assert.That(File.Exists(fileWithSavedResults), "fileWithSavedResults did not exist: " + fileWithSavedResults); return(string.Format("All OK. There were {0} results \r\nsaved to: {1}", o2Results.Count, fileWithSavedResults)); }
public void task4_CalculateStrutsFindings() { O2Cmd.log.write("TASK #4: Calculate Struts Findings"); // check if there are Struts Mappings var folderWithStrutsMappings = Path.Combine(folderWithArtifacts_Phase2, "Struts Mappings"); if (Directory.Exists(folderWithStrutsMappings)) { //Assert.That(Directory.Exists(folderWithStrutsMappings), "Directory with struts mappings did not exist: " + folderWithStrutsMappings); // check if we have the filtered findings files required var findingsWith_KnownSinks = Path.Combine(folderWithArtifacts_Phase3, "Findings with Known Sinks.ozasmt"); Assert.That(File.Exists(findingsWith_KnownSinks), "Could not find findingsWith_KnownSinks: " + findingsWith_KnownSinks); // load findings var o2Findings_KnownSinks = XUtils_Findings_v0_1.loadFindingsFile(findingsWith_KnownSinks); // extract just the ones needed for the struts mappings var o2Findings = new XRule_Findings_Filter().whereSourceAndSink_ContainsRegex(o2Findings_KnownSinks, "getParameter", "setAttribute"); o2Findings.AddRange(new XRule_Findings_Filter().whereSourceAndSink_ContainsRegex(o2Findings_KnownSinks, "getAttribute", "print")); foreach (var strutsMappingsFile in Files.getFilesFromDir_returnFullPath(folderWithStrutsMappings)) { var fileName = Path.GetFileName(strutsMappingsFile); var projectName = Path.GetFileNameWithoutExtension(strutsMappingsFile); O2Cmd.log.write("Processing file {0} from project {1}", fileName, projectName); // load struts mappings var strutsMapping = XUtils_Struts_v0_1.loadStrutsMappingsFromFile(strutsMappingsFile); Assert.That(strutsMapping != null, "strutsMapping was null"); // execute the struts rule var o2Results = XRule_Struts.strutsRule_fromGetParameterToPringViaGetSetAttributeJoins(o2Findings, strutsMapping); // make sure we had results //Assert.That(o2Results.Count > 0 , "There were no results"); if (o2Results.Count == 0) { O2Cmd.log.error("there were no results in task4_CalculateStrutsFindings"); } else { // save results var targetFolder = Path.Combine(folderWithArtifacts_Phase3, "Struts Mappings"); Files.checkIfDirectoryExistsAndCreateIfNot(targetFolder); var fileWithSavedResults = Path.Combine(targetFolder, projectName + ".ozasmt"); XUtils_Findings_v0_1.saveFindings(o2Results, fileWithSavedResults); // make sure saved file exists Assert.That(File.Exists(fileWithSavedResults), "fileWithSavedResults did not exist: " + fileWithSavedResults); O2Cmd.log.write("All OK. There were {0} results \r\nsaved to: {1}", o2Results.Count, fileWithSavedResults); } } } }