public void InsecureLogPath_Fail()
        {
            VerifyRulesOptions options = new VerifyRulesOptions()
            {
                CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                LogFilePath     = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\empty.cpp")
            };

            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                VerifyRulesCommand command = new VerifyRulesCommand(options);
                VerifyRulesResult  result  = command.GetResult();
                exitCode = result.ResultCode;
            }
            catch (Exception)
            {
                exitCode = VerifyRulesResult.ExitCode.CriticalError;
            }

            //because these are static and each test is meant to be indpendent null assign the references to create the log
            WriteOnce.Log = null;
            Utils.Logger  = null;

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.CriticalError);
        }
示例#2
0
        public void LogDebugLevel_Pass()
        {
            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                string appInspectorPath = Helper.GetPath(Helper.AppPath.appInspectorCLI);
                string args             = String.Format(@"verifyrules -r {0} -f text -v debug -l {1}",
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.defaultRules)),
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt"));

                exitCode = (VerifyRulesResult.ExitCode)Helper.RunProcess(appInspectorPath, args);

                if (exitCode == VerifyRulesResult.ExitCode.Verified)
                {
                    string testLogContent = File.ReadAllText(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt"));
                    if (String.IsNullOrEmpty(testLogContent))
                    {
                        exitCode = VerifyRulesResult.ExitCode.CriticalError;
                    }
                    else if (testLogContent.ToLower().Contains("debug"))
                    {
                        exitCode = VerifyRulesResult.ExitCode.Verified;
                    }
                }
            }
            catch (Exception)
            {
                exitCode = VerifyRulesResult.ExitCode.CriticalError;
            }

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.Verified);
        }
        public void CustomRules_Pass()
        {
            VerifyRulesOptions options = new VerifyRulesOptions()
            {
                CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
            };

            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                VerifyRulesCommand command = new VerifyRulesCommand(options);
                VerifyRulesResult  result  = command.GetResult();
                exitCode = result.ResultCode;
            }
            catch (Exception)
            {
                //check for specific error if desired
            }

            //because these are static and each test is meant to be indpendent null assign the references to create the log
            WriteOnce.Log = null;
            Utils.Logger  = null;

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.Verified);
        }
        public void LogErrorLevel_Pass()
        {
            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                string args = string.Format(@"verifyrules -r {0} -f text -l {1}",
                                            Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"\badir\myrule.json"),
                                            Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt"));

                exitCode = (VerifyRulesResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' '));

                if (exitCode == VerifyRulesResult.ExitCode.CriticalError)
                {
                    string testLogContent = File.ReadAllText(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt"));
                    if (!String.IsNullOrEmpty(testLogContent) && testLogContent.ToLower().Contains("error"))
                    {
                        exitCode = VerifyRulesResult.ExitCode.Verified;
                    }
                    else
                    {
                        exitCode = VerifyRulesResult.ExitCode.CriticalError;
                    }
                }
            }
            catch (Exception)
            {
                exitCode = VerifyRulesResult.ExitCode.CriticalError;
            }

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.Verified);
        }
        public void LogErrorLevel_Pass()
        {
            VerifyRulesOptions options = new VerifyRulesOptions()
            {
                CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"mybadrule.json"),
                LogFileLevel    = "error",
                LogFilePath     = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"logerror.txt"),
            };

            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                VerifyRulesCommand command = new VerifyRulesCommand(options);
                VerifyRulesResult  result  = command.GetResult();
                exitCode = result.ResultCode;
            }
            catch (Exception)
            {
                string testLogContent = File.ReadAllText(options.LogFilePath);
                if (!String.IsNullOrEmpty(testLogContent) && testLogContent.ToLower().Contains("error"))
                {
                    exitCode = VerifyRulesResult.ExitCode.Verified;
                }
                else
                {
                    exitCode = VerifyRulesResult.ExitCode.CriticalError;
                }
            }

            //because these are static and each test is meant to be indpendent null assign the references to create the log
            WriteOnce.Log = null;
            Utils.Logger  = null;

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.Verified);
        }
        public void InvalidLogPath_Fail()
        {
            VerifyRulesOptions options = new VerifyRulesOptions()
            {
                CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                LogFilePath     = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"baddir\logdebug.txt"),
            };

            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                VerifyRulesCommand command = new VerifyRulesCommand(options);
                VerifyRulesResult  result  = command.GetResult();
                exitCode = result.ResultCode;
            }
            catch (Exception)
            {
                exitCode = VerifyRulesResult.ExitCode.CriticalError;
            }

            //because these are static and each test is meant to be indpendent null assign the references to create the log
            WriteOnce.Log = null;
            Utils.Logger  = null;

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.CriticalError);//test fails even when values match unless this case run individually -mstest bug?
        }
        [Ignore] //default option won't find rules unless run from CLI; todo to look at addressed
        public void DefaultRules_Pass()
        {
            VerifyRulesOptions options = new VerifyRulesOptions()
            {
                VerifyDefaultRules = true
            };

            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                VerifyRulesCommand command = new VerifyRulesCommand(options);
                VerifyRulesResult  result  = command.GetResult();
                exitCode = result.ResultCode;
            }
            catch (Exception)
            {
                //check for specific error if desired
            }

            //because these are static and each test is meant to be indpendent null assign the references to create the log
            WriteOnce.Log = null;
            Utils.Logger  = null;

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.Verified);
        }
        public void InvalidLogPath_Fail()
        {
            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                string args = string.Format(@"verifyrules -r {0} -f text -l {1}",
                                            Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                                            Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"\badir\log.txt"));

                exitCode = (VerifyRulesResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' '));
            }
            catch (Exception)
            {
            }

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.CriticalError);//test fails even when values match unless this case run individually -mstest bug?
        }
        public void NoConsoleNoFileOutput_Fail()
        {
            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                string args = string.Format(@"verifyrules -r {0} -f text -x none -l {1}",
                                            Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                                            Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt"));

                exitCode = (VerifyRulesResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' '));
            }
            catch (Exception)
            {
            }

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.CriticalError);
        }
        public void NoDefaultNoCustomRules_Fail()
        {
            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                string args = string.Format(@"verifyrules -f text -l {0}",
                                            Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt"));

                exitCode = (VerifyRulesResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' '));
            }
            catch (Exception)
            {
                //check for specific error if desired
            }

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.CriticalError);
        }
        public void InsecureLogPath_Fail()
        {
            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                string args = string.Format(@"verifyrules -r {0} -l {1}",
                                            Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                                            Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\empty.cpp"));

                exitCode = (VerifyRulesResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' '));
            }
            catch (Exception)
            {
            }

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.CriticalError);
        }
示例#12
0
        public void NoDefaultNoCustomRules_Fail()
        {
            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                string appInspectorPath = Helper.GetPath(Helper.AppPath.appInspectorCLI);
                string args             = String.Format(@"verifyrules -f text -l {0}",
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt"));

                exitCode = (VerifyRulesResult.ExitCode)Helper.RunProcess(appInspectorPath, args);
            }
            catch (Exception)
            {
                //check for specific error if desired
            }

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.CriticalError);
        }
示例#13
0
        public void InvalidLogPath_Fail()
        {
            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                string appInspectorPath = Helper.GetPath(Helper.AppPath.appInspectorCLI);
                string args             = String.Format(@"verifyrules -r {0} -f text -l {1}",
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"\badir\log.txt"));

                exitCode = (VerifyRulesResult.ExitCode)Helper.RunProcess(appInspectorPath, args);
            }
            catch (Exception)
            {
            }

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.CriticalError);//test fails even when values match unless this case run individually -mstest bug?
        }
示例#14
0
        public void NoConsoleNoFileOutput_Fail()
        {
            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                string appInspectorPath = Helper.GetPath(Helper.AppPath.appInspectorCLI);
                string args             = String.Format(@"verifyrules -r {0} -f text -x none -l {1}",
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt"));

                exitCode = (VerifyRulesResult.ExitCode)Helper.RunProcess(appInspectorPath, args);
            }
            catch (Exception)
            {
            }

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.CriticalError);
        }
示例#15
0
        public void InsecureLogPath_Fail()
        {
            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                string appInspectorPath = Helper.GetPath(Helper.AppPath.appInspectorCLI);
                string args             = String.Format(@"verifyrules -r {0} -l {1}",
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\empty.cpp"));

                exitCode = (VerifyRulesResult.ExitCode)Helper.RunProcess(appInspectorPath, args);
            }
            catch (Exception)
            {
            }

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.CriticalError);
        }
        public void VerifyRulesToTxtFile_Pass()
        {
            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                string args = string.Format(@"verifyrules -r {0} -f json -o {1} -l {2}",
                                            Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                                            Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.txt"),
                                            Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt"));

                exitCode = (VerifyRulesResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' '));
            }
            catch (Exception)
            {
                //check for specific error if desired
            }

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.Verified);
        }
示例#17
0
        private static int RunVerifyRulesCommand(CLIVerifyRulesCmdOptions cliOptions)
        {
            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;

            VerifyRulesCommand command = new VerifyRulesCommand(new VerifyRulesOptions()
            {
                VerifyDefaultRules    = cliOptions.VerifyDefaultRules,
                CustomRulesPath       = cliOptions.CustomRulesPath,
                ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel,
                Failfast = cliOptions.Failfast,
                Log      = cliOptions.Log
            });

            VerifyRulesResult exportTagsResult = command.GetResult();

            exitCode = exportTagsResult.ResultCode;
            ResultsWriter.Write(exportTagsResult, cliOptions);

            return((int)exitCode);
        }
示例#18
0
        public void VerifyRulesToJsonFile_Pass()
        {
            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                string appInspectorPath = Helper.GetPath(Helper.AppPath.appInspectorCLI);
                string args             = String.Format(@"verifyrules -r {0} -f json -o {1} -l {2}",
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.json"),
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt"));

                exitCode = (VerifyRulesResult.ExitCode)Helper.RunProcess(appInspectorPath, args);
            }
            catch (Exception)
            {
                //check for specific error if desired
            }

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.Verified);
        }
        public void NoConsoleOutput_Pass()
        {
            VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError;
            try
            {
                string appInspectorPath = Helper.GetPath(Helper.AppPath.appInspectorCLI);
                string args             = string.Format(@"verifyrules -r {0} -f text -x none -o {1} -l {2}",
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.txt"),
                                                        Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt"));

                exitCode = (VerifyRulesResult.ExitCode)Helper.RunProcess(appInspectorPath, args, out string testContent);

                if (exitCode == VerifyRulesResult.ExitCode.Verified)
                {
                    exitCode = String.IsNullOrEmpty(testContent) ? VerifyRulesResult.ExitCode.Verified : VerifyRulesResult.ExitCode.CriticalError;
                }
            }
            catch (Exception)
            {
            }

            Assert.IsTrue(exitCode == VerifyRulesResult.ExitCode.Verified);
        }