public static void Dispatch(RunConfiguration config, TopshelfArguments args) { if (!string.IsNullOrEmpty(args.Instance)) { _log.Info("Using instance name from commandline."); config.WinServiceSettings.ServiceName = new ServiceName( config.WinServiceSettings.ServiceName.Name, args.Instance); } //find the command by the args 'Command' var run = new RunCommand(config.Coordinator, config.WinServiceSettings.ServiceName); var command = new List<Command> { run, new InstallService(config.WinServiceSettings), new UninstallService(config.WinServiceSettings) } .Where(x => x.Name == args.ActionName) .DefaultIfEmpty(run) .SingleOrDefault(); _log.DebugFormat("Running command: '{0}'", command.Name); command.Execute(); }
/// <summary> /// Go go gadget /// </summary> public static void Host(RunConfiguration configuration, string[] args) { if (args.Length > 0) _log.DebugFormat("Command Line Arguments: '{0}'", args); var a = TopshelfArgumentParser.Parse(args); TopshelfDispatcher.Dispatch(configuration, a); }
/// <summary> /// Go go gadget /// </summary> public static void Host(RunConfiguration configuration, string[] args) { _log.Info("Starting Host"); if (args.Length > 0) _log.DebugFormat("Arguments: {0}", args); var a = TopshelfArgumentParser.Parse(args); TopshelfDispatcher.Dispatch(configuration, a); }
/// <summary> /// Go go gadget /// </summary> public static void Host(RunConfiguration configuration, string[] args) { var commandLine = string.Join(" ", args); if (commandLine.Length > 0) _log.DebugFormat("Command Line Arguments: '{0}'", commandLine); Command command = new CommandLineArguments(configuration) .GetCommand(commandLine); command.Execute(); }
/// <summary> /// Go go gadget /// </summary> public static void Host(RunConfiguration configuration, string[] args) { _log.Info("Starting Host"); if (args.Length > 0) _log.DebugFormat("Arguments: {0}", args); //make it so this can be passed in var argv = args.Aggregate("", (l, r) => "{0} {1}".FormatWith(l, r)); var a = TopshelfArgumentParser.Parse(argv); TopshelfDispatcher.Dispatch(configuration, a); }
public void Test32Default() { // standard test string xml = @"<?xml version=""1.0"" encoding=""utf-8""?> <Peach> <DataModel name=""TheDataModel""> <Number name=""CRC"" size=""32"" signed=""false""> <Fixup class=""CrcFixup""> <Param name=""ref"" value=""Data""/> <Param name=""type"" value=""CRC32""/> </Fixup> </Number> <Blob name=""Data"" value=""Hello""/> </DataModel> <StateModel name=""TheState"" initialState=""Initial""> <State name=""Initial""> <Action type=""output""> <DataModel ref=""TheDataModel""/> </Action> </State> </StateModel> <Test name=""Default""> <StateModel ref=""TheState""/> <Publisher class=""Null""/> </Test> </Peach>" ; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); e.startFuzzing(dom, config); // verify values // -- this is the pre-calculated checksum from Peach2.3 on the blob: "Hello" byte[] precalcChecksum = new byte[] { 0x82, 0x89, 0xD1, 0xF7 }; Assert.AreEqual(1, values.Count); Assert.AreEqual(precalcChecksum, values[0].ToArray()); }
public void RelationOfDataModel() { string xml = @" <Peach> <DataModel name=""TheModel""> <Number name=""marker"" value=""1"" size=""8"" token=""true""/> <Number name=""id"" value=""1"" size=""8""/> <Number name=""length"" size=""16""> <Relation type=""size"" of=""TheModel""/> </Number> <String name=""value"" value=""Hello World!"" /> </DataModel> <StateModel name=""TheState"" initialState=""Initial""> <State name=""Initial""> <Action type=""output""> <DataModel name=""foo"" ref=""TheModel""/> </Action> </State> </StateModel> <Test name=""Default""> <StateModel ref=""TheState""/> <Publisher class=""Null""/> <Strategy class=""Sequential""/> </Test> </Peach> "; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); Assert.IsTrue(dom.dataModels[0].Count == 4); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); e.startFuzzing(dom, config); Assert.AreEqual(1, dataModels.Count); var actual = dom.dataModels[0].Value.ToArray(); var expected = Encoding.ASCII.GetBytes("\x01\x01\x10\x00Hello World!"); Assert.AreEqual(expected, actual); }
public void Test2() { // testing N-hint // : N = 5, generating values 95 - 105 string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <Number name=\"num1\" size=\"32\" value=\"100\" signed=\"false\">" + " <Hint name=\"NumericalVarianceMutator-N\" value=\"5\"/>" + " </Number>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " <Strategy class=\"Sequential\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); dom.tests[0].includedMutators = new List <string>(); dom.tests[0].includedMutators.Add("NumericalVarianceMutator"); RunConfiguration config = new RunConfiguration(); Engine e = new Engine(null); e.startFuzzing(dom, config); // verify values Assert.AreEqual(11, mutations.Count); for (int i = 0; i <= 10; ++i) { Assert.AreEqual(Variant.VariantType.ULong, mutations[i].GetVariantType()); Assert.AreEqual(95 + i, (ulong)mutations[i]); } }
public void BadParent() { string xml = @" <Peach> <DataModel name='DM'> <Blob name='blob'> <Fixup class='SequenceIncrementFixup'/> </Blob> </DataModel> <StateModel name='TheState' initialState='Initial'> <State name='Initial'> <Action type='output'> <DataModel ref='DM'/> </Action> </State> </StateModel> <Test name='Default'> <StateModel ref='TheState'/> <Publisher class='Null'/> </Test> </Peach> "; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); Assert.AreEqual(new byte[0], dom.dataModels[0][0].DefaultValue.BitsToArray()); Assert.AreEqual(new byte[0], dom.dataModels[0][0].InternalValue.BitsToArray()); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); try { e.startFuzzing(dom, config); Assert.Fail("Should throw"); } catch (PeachException ex) { Assert.AreEqual("SequenceIncrementFixup has non numeric parent 'DM.blob'.", ex.Message); } }
public void Test1() { // standard test string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <Block name=\"TheBlock\">" + " <Transformer class=\"Bz2Decompress\"/>" + " <Blob name=\"Data\" valueType=\"hex\" value=\"0x42, 0x5A, 0x68, 0x39, 0x31, 0x41, 0x59, 0x26, 0x53, 0x59, 0x64, " + "0x8C, 0xBB, 0x73, 0x00, 0x00, 0x00, 0x01, 0x00, 0x38, 0x00, 0x20, 0x00," + "0x30, 0xcc, 0x0c, 0xc2, 0x30, 0xbb, 0x92, 0x29," + "0xc2, 0x84, 0x83, 0x24, 0x65, 0xdb, 0x98\"/>" + " </Block>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); e.startFuzzing(dom, config); // verify values // -- this is the pre-calculated result from Peach2.3 on the blob: "" byte[] precalcResult = new byte[] { (byte)'a', (byte)'b', (byte)'c' }; Assert.AreEqual(1, values.Count); Assert.AreEqual(precalcResult, values[0].ToArray()); }
public void TestEmptyValue() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <String name=\"sizeRelation1\">" + " <Relation type=\"size\" of=\"string1\" expressionSet=\"size + 10\"/>" + " </String>" + " <String name=\"string1\" value=\"\"/>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " <Strategy class=\"Sequential\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); dom.tests[0].includedMutators = new List <string>(); dom.tests[0].includedMutators.Add("SizedVaranceMutator"); RunConfiguration config = new RunConfiguration(); Engine e = new Engine(null); e.startFuzzing(dom, config); // verify values Assert.Greater(dataModels.Count, 1); foreach (var item in dataModels) { Assert.AreEqual(Variant.VariantType.Long, item[0].InternalValue.GetVariantType()); long len = (long)item[0].InternalValue; Assert.GreaterOrEqual(len, 10); Assert.AreEqual(len - 10, item[1].Value.Length); } }
public void Test5() { // testing generating 100 UInt32's string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <Number name=\"num1\" size=\"32\" signed=\"false\">" + " <Hint name=\"FiniteRandomNumbersMutator-N\" value=\"100\"/>" + " </Number>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " <Strategy class=\"Sequential\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); dom.tests[0].includedMutators = new List <string>(); dom.tests[0].includedMutators.Add("FiniteRandomNumbersMutator"); RunConfiguration config = new RunConfiguration(); Engine e = new Engine(null); e.startFuzzing(dom, config); // verify values Assert.AreEqual(100, mutations.Count); foreach (var item in mutations) { Assert.AreEqual(Variant.VariantType.Long, item.GetVariantType()); uint val = Convert.ToUInt32((long)item); Assert.NotNull(val); } }
public void Test1() { // standard test (Odd length string) string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <Number name=\"TCPChecksum\" endian=\"big\" size=\"16\">" + " <Fixup class=\"TCPChecksumFixup\">" + " <Param name=\"ref\" value=\"Data\"/>" + " <Param name=\"src\" value=\"10.0.1.34\"/>" + " <Param name=\"dst\" value=\"10.0.1.30\"/>" + " </Fixup>" + " </Number>" + " <Blob name=\"Data\" value=\"Hello\"/>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); e.startFuzzing(dom, config); // verify values byte[] precalcChecksum = new byte[] { 0xc5, 0xe2 }; Assert.AreEqual(1, values.Count); Assert.AreEqual(precalcChecksum, values[0].ToArray()); }
public void FieldOverride() { string xml = @" <Peach> <DataModel name='DM'> <String name='str1' value='000' length='3' mutable='false'/> <String name='str2'/> </DataModel> <StateModel name='TheState' initialState='Initial'> <State name='Initial'> <Action type='output'> <DataModel ref='DM'/> <Data> <Field name='str1' value='111'/> </Data> </Action> </State> </StateModel> <Test name='Default'> <StateModel ref='TheState'/> <Publisher class='Null'/> <Strategy class='Sequential'/> <Mutators mode='include'> <Mutator class='StringMutator'/> </Mutators> </Test> </Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); RunConfiguration config = new RunConfiguration(); Engine e = new Engine(null); e.startFuzzing(dom, config); Assert.AreEqual(2380, dataModels.Count); for (int i = 0; i < dataModels.Count; ++i) { string val = (string)dataModels[i][0].InternalValue; Assert.AreEqual("111", val); } }
public void TruncateTest() { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <Blob name=\"Checksum\">" + " <Fixup class=\"HMAC\">" + " <Param name=\"ref\" value=\"Data\"/>" + " <Param name=\"Key\" value=\"4141414141414141414141414141414141414141\"/>" + " <Param name=\"Hash\" value=\"HMACSHA1\"/>" + " <Param name=\"Length\" value=\"12\"/>" + " </Fixup>" + " </Blob>" + " <Blob name=\"Data\" valueType=\"hex\" value=\"0000020100000001baae9ef59ff1ee56211769bd91da50ed22e9ef5f17345fc170ff0b2e713c00e3811c991c817b6484c788762f6c22d0682b96addf984d28a11f156b950b6d12613201816bbd269d5c\"/>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); e.startFuzzing(dom, config); // verify values // -- this is the pre-calculated checksum from Peach2.3 on the blob: { 1, 2, 3, 4, 5 } byte[] precalcChecksum = new byte[] { 0x37, 0xf4, 0xbd, 0x2e, 0x44, 0x93, 0x01, 0x3c, 0x5d, 0x82, 0x99, 0xf2 }; Assert.AreEqual(1, values.Count); Assert.AreEqual(precalcChecksum, values[0].ToArray()); }
public void Test1() { // standard tests generating specified valid values for each <String> element string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <String name=\"str1\" value=\"Hello, World!\">" + " <Hint name=\"ValidValues\" value=\"one;two;three;four;five;abc;123\"/>" + " </String>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " <Strategy class=\"Sequential\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); dom.tests[0].includedMutators = new List <string>(); dom.tests[0].includedMutators.Add("ValidValuesMutator"); RunConfiguration config = new RunConfiguration(); Engine e = new Engine(null); e.startFuzzing(dom, config); // verify values string[] expected = new string[] { "one", "two", "three", "four", "five", "abc", "123" }; Assert.AreEqual(expected.Length, mutations.Count); for (int i = 0; i < mutations.Count; ++i) { Assert.AreEqual(Variant.VariantType.String, mutations[i].GetVariantType()); Assert.AreEqual(expected[i], (string)mutations[i]); } }
public void Test2() { // standard test var tmp = Path.GetTempFileName(); File.WriteAllBytes(tmp, precalcResult); string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <Block name=\"TheBlock\">" + " <Transformer class=\"Bz2Compress\"/>" + " <Blob name=\"Data\"/>" + " </Block>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " <Data fileName=\"" + tmp + "\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); e.startFuzzing(dom, config); var blk = dataModels[0][0] as Dom.Block; Assert.AreEqual("abc", blk[0].InternalValue.BitsToString()); }
public void TestBitWiseEmpty() { string xml = @" <Peach> <DataModel name='TheDataModel'> <Number name='Number' size='8' value='0'> <Relation type='size' of='Blob' lengthType='bits'/> </Number> <Blob name='Blob'/> </DataModel> <StateModel name='TheState' initialState='Initial'> <State name='Initial'> <Action type='output'> <DataModel ref='TheDataModel'/> </Action> </State> </StateModel> <Test name='Default'> <StateModel ref='TheState'/> <Publisher class='Null'/> <Strategy class='Sequential'/> </Test> </Peach> "; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); dom.tests[0].includedMutators = new List <string>(); dom.tests[0].includedMutators.Add("SizedVaranceMutator"); RunConfiguration config = new RunConfiguration(); Engine e = new Engine(null); e.startFuzzing(dom, config); // verify values Assert.AreEqual(51, dataModels.Count); for (int i = 0; i < 51; ++i) { Assert.AreEqual(i, (int)dataModels[i][0].InternalValue); Assert.AreEqual(8 + i, dataModels[i].Value.LengthBits); } }
public void BadAddressFamily() { // Tests what happens when we give an ipv4 address to an ipv6 publisher. string xml = string.Format(raw_template, "RawV6", IPAddress.Loopback, "PupStateModel", "17"); PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); e.startFuzzing(dom, config); }
private bool AddOrUpdateConsoleLogger(XmlDocument document, RunConfiguration runConfiguration, LoggerRunSettings loggerRunSettings) { // Update console logger settings bool consoleLoggerUpdated = this.UpdateConsoleLoggerIfExists(document, loggerRunSettings); // In case of CLI, add console logger if not already present. bool designMode = runConfiguration.DesignModeSet ? runConfiguration.DesignMode : this.commandLineOptions.IsDesignMode; if (!designMode && !consoleLoggerUpdated) { this.AddConsoleLogger(document, loggerRunSettings); } // Update is required 1) in case of CLI 2) in case of design mode if console logger is present in runsettings. return(!designMode || consoleLoggerUpdated); }
public void TestBadUdp6Send() { string xml = string.Format(udp6_xml_template, "fe80::"); PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); e.startFuzzing(dom, config); }
private Guid?GetPartitionFromRunProfile(string runProfileName, ManagementAgent ma) { if (runProfileName == null) { return(null); } if (!ma.RunProfiles.ContainsKey(runProfileName)) { return(null); } RunConfiguration r = ma.RunProfiles[runProfileName]; return(r.RunSteps?.FirstOrDefault()?.Partition); }
public void RunConfigurationDefaultValuesMustBeUsedOnCreation() { var runConfiguration = new RunConfiguration(); // Verify Default Assert.AreEqual(Constants.DefaultPlatform, runConfiguration.TargetPlatform); Assert.AreEqual(Framework.DefaultFramework, runConfiguration.TargetFrameworkVersion); Assert.AreEqual(Constants.DefaultResultsDirectory, runConfiguration.ResultsDirectory); Assert.AreEqual(null, runConfiguration.SolutionDirectory); Assert.AreEqual(Constants.DefaultTreatTestAdapterErrorsAsWarnings, runConfiguration.TreatTestAdapterErrorsAsWarnings); Assert.AreEqual(null, runConfiguration.BinariesRoot); Assert.AreEqual(null, runConfiguration.TestAdaptersPaths); Assert.AreEqual(Constants.DefaultCpuCount, runConfiguration.MaxCpuCount); Assert.AreEqual(false, runConfiguration.DisableAppDomain); Assert.AreEqual(false, runConfiguration.DisableParallelization); }
public void TcpConnectRetry() { // Should throw PeachException if unable to connect during a control iteration string xml = string.Format(template, "ClientState", "TcpClient", "Host", 20); PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); Assert.Throws <PeachException>(delegate() { e.startFuzzing(dom, config); }); }
public void Test1() { // standard test of generating values of +/- 50 around numerical edge cases // - testing with a number size of 8, and signed, so edge cases are [0, -128, 127, 255] // - if the value produced is out of range, the default value of '0' is returned string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <Number name=\"num1\" size=\"8\" signed=\"true\"/>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " <Strategy class=\"Sequential\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); dom.tests[0].includedMutators = new List <string>(); dom.tests[0].includedMutators.Add("NumericalEdgeCaseMutator"); RunConfiguration config = new RunConfiguration(); Engine e = new Engine(null); e.startFuzzing(dom, config); // verify values Assert.Greater(mutations.Count, 0); foreach (var item in mutations) { Assert.AreEqual(Variant.VariantType.Long, item.GetVariantType()); Assert.NotNull(Convert.ToSByte((long)item)); } }
public void ArrayOverride() { string xml = @" <Peach> <DataModel name='ArrayTest'> <Blob name='Data' minOccurs='3' maxOccurs='5' length='2' value='44 44' valueType='hex' /> </DataModel> <StateModel name='StateModel' initialState='State1'> <State name='State1'> <Action type='output'> <DataModel ref='ArrayTest'/> <Data > <Field name='Data[2]' value='41 41' valueType='hex' /> <Field name='Data[1]' value='42 42' valueType='hex' /> <Field name='Data[0]' value='45 45' valueType='hex'/> </Data> </Action> </State> </StateModel> <Test name='Default'> <StateModel ref='StateModel'/> <Publisher class='Null'/> </Test> </Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); e.startFuzzing(dom, config); var value = dom.tests[0].stateModel.states["State1"].actions[0].dataModel.Value; Assert.AreEqual(6, value.Length); var expected = new byte[] { 0x45, 0x45, 0x42, 0x42, 0x41, 0x41 }; Assert.AreEqual(expected, value.ToArray()); }
public void RunWaitTime(string waitTime, double min, double max) { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <Blob name=\"blob1\"/>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\" waitTime=\"{0}\">".Fmt(waitTime) + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " <Strategy class=\"Sequential\"/>" + " </Test>" + "</Peach>"; iterationStarted = DateTime.MinValue; iterationTimeSeconds = -1; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); dom.tests[0].includedMutators = new List <string>(); dom.tests[0].includedMutators.Add("BlobMutator"); RunConfiguration config = new RunConfiguration(); config.range = true; config.rangeStart = 1; config.rangeStop = 1; Engine e = new Engine(null); e.IterationStarting += new Engine.IterationStartingEventHandler(e_IterationStarting); e.startFuzzing(dom, config); // verify values Assert.GreaterOrEqual(iterationTimeSeconds, min); Assert.LessOrEqual(iterationTimeSeconds, max); }
public void Test1() { // standard test performing the W3C parser tests for each <String> element, only works with hints: "XMLHint" / "xml" string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <String name=\"str1\" value=\"Hello, World!\">" + " <Hint name=\"XMLhint\" value=\"xml\"/>" + " </String>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " <Strategy class=\"Sequential\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); dom.tests[0].includedMutators = new List <string>(); dom.tests[0].includedMutators.Add("XmlW3CParserTestsMutator"); RunConfiguration config = new RunConfiguration(); Engine e = new Engine(null); e.startFuzzing(dom, config); // verify count (= 1510) Assert.AreEqual(1510, mutations.Count); foreach (var item in mutations) { Assert.AreEqual(Variant.VariantType.ByteString, item.GetVariantType()); Assert.NotNull((byte[])item); } }
public void Test1() { // standard test of flipping 20% of the bits in a blob // : in this case, we'll use 1 byte with a value of 0, so we should get 1 bit flipped. string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <Blob name=\"blob1\" length=\"1\" valueType=\"hex\" value=\"00\"/>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " <Strategy class=\"Sequential\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); dom.tests[0].includedMutators = new List <string>(); dom.tests[0].includedMutators.Add("BlobBitFlipperMutator"); RunConfiguration config = new RunConfiguration(); Engine e = new Engine(null); e.startFuzzing(dom, config); // verify values Assert.AreEqual(1, mutations.Count); Assert.AreEqual(Variant.VariantType.BitStream, mutations[0].GetVariantType()); var item = (BitwiseStream)mutations[0]; Assert.AreEqual(1, item.Length); Assert.AreEqual(1, CountBits(item.ToArray()[0])); }
private void RunTest(string xml, uint iterations, Engine.FaultEventHandler OnFault) { var pid = System.Diagnostics.Process.GetCurrentProcess().Id; var rng = new Random((uint)pid); var iface = GetInterface(); var port1 = rng.Next(8000, 10000); var port2 = rng.Next(100, 1000) + port1; xml = pre_xml + string.Format(xml, iface.Item1, iface.Item2, port1, port2) + post_xml; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); config.range = true; config.rangeStart = 1; config.rangeStop = 1 + iterations; if (OnFault == null) { e.startFuzzing(dom, config); return; } e.Fault += OnFault; try { e.startFuzzing(dom, config); Assert.Fail("Should throw."); } catch (PeachException ex) { Assert.AreEqual("Fault detected on control iteration.", ex.Message); } Assert.AreEqual(1, testResults.Count); testResults.Clear(); Assert.AreEqual(0, testResults.Count); }
public void Test3() { // Test to show that this should be a SoftException // Since a numeric string can be fuzzed into a non-numeric string string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <String name=\"TheString\" value=\"15\">" + " <Transformer class=\"IntToHex\"/>" + " </String>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " <Strategy class=\"Sequential\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); dom.tests[0].includedMutators = new List <string>(); dom.tests[0].includedMutators.Add("StringMutator"); RunConfiguration config = new RunConfiguration(); config.range = true; config.rangeStart = 1; config.rangeStop = 1; Engine e = new Engine(null); e.startFuzzing(dom, config); string val1 = "Peach"; Assert.AreEqual(val1, (string)mutations[0]); }
public void RunTest(string key, string iv, byte[] expected) { // standard test string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <Blob name=\"Data\" value=\"Hello\">" + " <Transformer class=\"TripleDes\">" + " <Param name=\"Key\" value=\"{0}\"/>" + " <Param name=\"IV\" value=\"{1}\"/>" + " </Transformer>" + " </Blob>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " </Test>" + "</Peach>"; xml = string.Format(xml, key, iv); PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); e.startFuzzing(dom, config); // verify values // -- this is the pre-calculated result on the blob: "Hello" Assert.AreEqual(1, values.Count); Assert.AreEqual(expected, values[0].ToArray()); }
private static void Main(string[] args) { BootstrapLogger(); MsmqEndpointConfigurator.Defaults(x => { x.CreateMissingQueues = true; }); ObjectFactory.Initialize(x => { x.For <IConfiguration>().Use <Configuration>(); }); var serviceConfiguration = ObjectFactory.GetInstance <IConfiguration>(); RunConfiguration configuration = RunnerConfigurator.New(config => { config.SetServiceName(typeof(Program).Namespace); config.SetDisplayName(typeof(Program).Namespace); config.SetDescription("MassTransit Runtime Services (Subscription, Timeout, Health Monitoring)"); if (serviceConfiguration.UseServiceCredentials) { config.RunAs(serviceConfiguration.ServiceUsername, serviceConfiguration.ServicePassword); } else { config.RunAsLocalSystem(); } config.DependencyOnMsmq(); if (serviceConfiguration.SubscriptionServiceEnabled) { config.ConfigureService <SubscriptionService>(service => { ConfigureService <SubscriptionService, SubscriptionServiceRegistry>(service, start => start.Start(), stop => stop.Stop()); }); } if (serviceConfiguration.HealthServiceEnabled) { config.ConfigureService <HealthService>(service => { ConfigureService <HealthService, HealthServiceRegistry>(service, start => start.Start(), stop => stop.Stop()); }); } if (serviceConfiguration.TimeoutServiceEnabled) { config.ConfigureService <TimeoutService>(service => { ConfigureService <TimeoutService, TimeoutServiceRegistry>(service, start => start.Start(), stop => stop.Stop()); }); } config.AfterStoppingTheHost(x => { _log.Info("MassTransit Runtime Services are exiting..."); }); }); Runner.Host(configuration, args); }
public void Test1() { // standard test string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <Blob name=\"Checksum\">" + " <Fixup class=\"MD5Fixup\">" + " <Param name=\"ref\" value=\"Data\"/>" + " </Fixup>" + " </Blob>" + " <Blob name=\"Data\" value=\"12345\"/>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); e.startFuzzing(dom, config); // verify values // -- this is the pre-calculated checksum from Peach2.3 on the blob: { 1, 2, 3, 4, 5 } byte[] precalcChecksum = new byte[] { 0x82, 0x7C, 0xCB, 0x0E, 0xEA, 0x8A, 0x70, 0x6C, 0x4C, 0x34, 0xA1, 0x68, 0x91, 0xF8, 0x4E, 0x7B }; Assert.AreEqual(1, values.Count); Assert.AreEqual(precalcChecksum, values[0].ToArray()); }
public void Test1() { // standard test string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <Number name=\"CRC\" size=\"32\" signed=\"false\">" + " <Fixup class=\"LRCFixup\">" + " <Param name=\"ref\" value=\"Data\"/>" + " </Fixup>" + " </Number>" + " <Blob name=\"Data\" value=\"12345\"/>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); RunConfiguration config = new RunConfiguration(); config.singleIteration = true; Engine e = new Engine(null); e.startFuzzing(dom, config); // verify values // -- this is the pre-calculated result from Peach2.3 on the blob: "12345" byte[] precalcResult = new byte[] { 0x01, 0x00, 0x00, 0x00 }; Assert.AreEqual(1, values.Count); Assert.AreEqual(precalcResult, values[0].Value); }
public static void Dispatch(RunConfiguration config, TopshelfArguments args) { //find the command by the args 'Command' var run = new RunCommand(config.Coordinator, config.WinServiceSettings.ServiceName); var command = new List<Command> { run, new InstallService(config.WinServiceSettings), new UninstallService(config.WinServiceSettings) } .Where(x => x.Name == args.ActionName) .DefaultIfEmpty(run) .SingleOrDefault(); _log.DebugFormat("Running command: '{0}'", command.Name); command.Execute(); }
public static void Dispatch(RunConfiguration config, TopshelfArguments args) { //find the command by the args 'Command' var run = new RunCommand(config.Coordinator, config.WinServiceSettings.ServiceName); Command command = new List<Command> { run, new ServiceCommand(config.Coordinator, config.WinServiceSettings) } .Where(x => x.Name == args.Command) .DefaultIfEmpty(run) .SingleOrDefault(); _log.DebugFormat("Running command: '{0}'", command.Name); //what to do with the config? //flow the args down command.Execute(args.CommandArgs); }
private static RunnableApplication CreateApplication(RunConfiguration runConfiguration, IDictionary<string, string[]> hostArguments) { var applicationName = GetApplicationName(runConfiguration.Application); return new RunnableApplication(runConfiguration.Environment, runConfiguration.Application, Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "", $"Applications\\{applicationName}"), applicationName, runConfiguration.Hosts.Select(x => new ApplicationHost(x.Name)).ToList(), hostArguments, (runConfiguration.IgnoredPaths ?? new List<string>()).ToArray()); }
private static IEnumerable<RunnableApplication> GetApplications(RunConfiguration runConfiguration) { var hostArguments = runConfiguration.Hosts.ToDictionary(x => x.Name, x => (x.Arguments ?? new List<string>()).ToArray()); yield return CreateApplication(runConfiguration, hostArguments); }
public static void Host(RunConfiguration configuration, string[] args) { configuration.Run(); }
public CommandLineArguments(RunConfiguration configuration) { _configuration = configuration; }