Пример #1
0
        protected override CommandResult ProcessXmppMessage(string message)
        {
            InfoInstruction infoResult;

            try
            {
                infoResult = InfoInstruction.Parse(message);
            }
            catch (Exception e)
            {
                return(CreateError($"Can't parse {CmdName} instruction output: got exception \n{e}"));
            }

            if (!string.IsNullOrEmpty(infoResult.Error))
            {
                return(CreateError(infoResult.Error));
            }


            TextOutput updateResult;

            try
            {
                updateResult = SyncSoftwareInfo(infoResult.Software);
            }
            catch (Exception e)
            {
                return(CreateError($"Command {CmdName} failed. Can't sync command {infoResult.Code} to lib: \n{e}"));
            }

            //todo: sync soft effect info

            CommandResult result = CreateOutput(new TextOutput(Verbosity, message), CommandState.Finished);

            result.Output.Add(updateResult);

            return(result);
        }
Пример #2
0
        public void TestInfo()
        {
            string hack = @"--------------------
#180 programm info:
Effect: disable
Allowed node types:
 -Firewall
 -Antivirus
 -VPN
 -Brandmauer
 -Router
 -Traffic monitor
 -Cyptographic system
Duration: 600sec.
END ----------------";

            var infoResponse = InfoInstruction.Parse(hack);

            Assert.NotNull(hack, "Parsed not successfully");
            Assert.IsTrue(string.IsNullOrEmpty(infoResponse.Error), "Should be a success");

            Assert.AreEqual(180, infoResponse.Code, "Code");
            Assert.AreEqual(600, infoResponse.Duration, "Duration");
            Assert.AreEqual("disable", infoResponse.Effect, "Effect");
            Assert.AreEqual("", infoResponse.InevitableEffect, "InevitableEffect");
            Assert.AreEqual("[Firewall,Antivirus,VPN,Brandmauer,Router,Traffic monitor,Cyptographic system]", infoResponse.SupportedNodes, "SupportedNodes");
            Assert.AreEqual("exploit", infoResponse.Software.SoftwareType, "SoftwareType");



            hack = @"--------------------
#180 programm info:
Effect: disable
Inevitable effect: logname
Allowed node types:
 -Firewall
 -Antivirus
 -VPN
 -Brandmauer
 -Router
 -Traffic monitor
 -Cyptographic system
Duration: 600sec.
END ----------------";

            infoResponse = InfoInstruction.Parse(hack);

            Assert.NotNull(hack, "Parsed not successfully");
            Assert.IsTrue(string.IsNullOrEmpty(infoResponse.Error), "Should be a success");


            Assert.AreEqual("logname", infoResponse.InevitableEffect, "InevitableEffect");

            string soft = @"--------------------
#2294523 programm info:
Effect: trace
Inevitable effect: logname
Allowed node types:
 -Firewall
 -Antivirus
 -VPN
 -Brandmauer
 -Router
 -Traffic monitor
 -Cyptographic system
END ----------------";

            infoResponse = InfoInstruction.Parse(soft);

            Assert.NotNull(soft, "Parsed not successfully");
            Assert.IsTrue(string.IsNullOrEmpty(infoResponse.Error), "Should be a success");

            Assert.AreEqual(2294523, infoResponse.Code, "Code");
            Assert.AreEqual(0, infoResponse.Duration, "Duration");
            Assert.AreEqual("trace", infoResponse.Effect, "Effect");
            Assert.AreEqual("logname", infoResponse.InevitableEffect, "InevitableEffect");
            Assert.AreEqual("[Firewall,Antivirus,VPN,Brandmauer,Router,Traffic monitor,Cyptographic system]", infoResponse.SupportedNodes, "SupportedNodes");
            Assert.AreEqual("protection", infoResponse.Software.SoftwareType, "SoftwareType");


            soft = @"--------------------
#2294523 programm info:
Allowed node types:
 -Firewall
END ----------------";

            infoResponse = InfoInstruction.Parse(soft);

            Assert.NotNull(soft, "Parsed not successfully");
            Assert.IsTrue(string.IsNullOrEmpty(infoResponse.Error), "Should be a success");

            Assert.AreEqual(2294523, infoResponse.Code, "2294523");
            Assert.AreEqual(0, infoResponse.Duration, "Duration");
            Assert.AreEqual("", infoResponse.Effect, "");
            Assert.AreEqual("", infoResponse.InevitableEffect, "");
            Assert.AreEqual("[Firewall]", infoResponse.SupportedNodes, "SupportedNodes");
            Assert.AreEqual("protection", infoResponse.Software.SoftwareType, "SoftwareType");
        }