Exemple #1
0
        public void CheckCli_FakeLanguage_CorrectlyProcessed()
        {
            if (Helper.IsRunningOnLinux)
            {
                Assert.Ignore("TODO: fix failed Cli unit-test on mono (Linux)");
            }

            // Patterns: [{"Name":"","Key":"1","Languages":"Fake","DataFormat":"Dsl","Value":"<[(?i)password(?-i)]> = <[\"\\w*\" || null]>","CweId":"","Description":""}]
            ProcessExecutionResult result = ProcessHelpers.SetupHiddenProcessAndStart(exeName,
                                                                                      $"--stage {Stage.Patterns} " +
                                                                                      $"--patterns kAAAAB+LCAAAAAAABAAljb0KwjAURl8l3KkVHVyltoOhUBRHlyTDxYYSTJOSH4JY391b3M534PCJD9xx1nAC2MNVvwmORDd0U8ZJR9o9vjQpjgl7H2ZM5Hi0pB5o85Y2oupMvWCMxYex6g6mVi07s0ZIkLLsJLB1ZS5bq1rKLkUP4/+R6/gMZknGu0181Q+1349CkAAAAA== " +
                                                                                      $"--log-debugs --log-errors");

            Assert.AreEqual("Pattern \"1\" ignored because of it doesn't have target languages.", result.Output[2]);
        }
Exemple #2
0
        public static ProcessExecutionResult SetupHiddenProcessAndStart(string fileName, string arguments, string workingDirectory = ".", bool waitForExit = true)
        {
            var result = new ProcessExecutionResult();

            var process   = new Process();
            var startInfo = process.StartInfo;

            startInfo.FileName  = fileName;
            startInfo.Arguments = arguments;
            if (workingDirectory != null)
            {
                startInfo.WorkingDirectory = workingDirectory;
            }
            startInfo.RedirectStandardInput  = true;
            startInfo.RedirectStandardError  = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute        = false;
            startInfo.CreateNoWindow         = true;
            process.ErrorDataReceived       += (sender, e) =>
            {
                if (!string.IsNullOrEmpty(e.Data))
                {
                    result.Errors.Add(e.Data);
                }
            };
            process.OutputDataReceived += (sender, e) =>
            {
                if (!string.IsNullOrEmpty(e.Data))
                {
                    result.Output.Add(e.Data);
                }
            };
            process.EnableRaisingEvents = true;
            process.Start();
            process.StandardInput.WriteLine();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            result.ProcessId = process.Id;
            if (waitForExit)
            {
                process.WaitForExit();
            }

            return(result);
        }
Exemple #3
0
        public void CheckCli_SeveralLanguages_OnlyPassedLanguagesProcessed()
        {
            if (Helper.IsRunningOnLinux)
            {
                Assert.Ignore("TODO: fix failed Cli unit-test on mono (Linux)");
            }

            ProcessExecutionResult result = ProcessHelpers.SetupHiddenProcessAndStart(exeName,
                                                                                      $"-f \"{TestHelper.TestsDataPath}\" " +
                                                                                      $"-l {Language.PlSql},{Language.TSql} " +
                                                                                      $"--stage {Stage.Parse} --log-debugs");

            // Do not process php (csharp, java etc.) files.
            Assert.IsTrue(result.Output.Any(line => line.Contains(".php has not been read")));
            Assert.IsTrue(result.Output.Any(line => line.Contains("has been detected")));

            result = ProcessHelpers.SetupHiddenProcessAndStart(exeName,
                                                               $"-f \"{TestHelper.TestsDataPath}\" " +
                                                               $"-l {Language.PlSql} " +
                                                               $"--stage {Stage.Parse} --log-debugs");

            // Do not detect language for only one language.
            Assert.IsFalse(result.Output.Any(line => line.Contains("has been detected")));
        }