public void Variables_SessionFlood_1() { using (var gate = new NetGate(null)) { gate.Configure(CONFIG_SESSION.AsLaconicConfig()); gate.Start(); Rule rule; Assert.AreEqual(GateAction.Allow, gate.CheckTraffic(new GeneralTraffic { FromAddress = "170.12.14.12" }, out rule)); Assert.IsNull(rule); gate.IncreaseVariable(TrafficDirection.Incoming, "170.12.14.12", "newSession", 5); Assert.AreEqual(GateAction.Deny, gate.CheckTraffic(new GeneralTraffic { FromAddress = "170.12.14.12" }, out rule)); Assert.IsNotNull(rule); Assert.AreEqual("Session Flood", rule.Name); Assert.AreEqual(GateAction.Allow, gate.CheckTraffic(new GeneralTraffic { FromAddress = "170.1.99.144" }, out rule)); Assert.IsNull(rule); Assert.AreEqual(GateAction.Deny, gate.CheckTraffic(new GeneralTraffic { FromAddress = "170.12.14.12" }, out rule)); Assert.IsNotNull(rule); Assert.AreEqual("Session Flood", rule.Name); System.Threading.Thread.Sleep(5000); Assert.AreEqual(GateAction.Allow, gate.CheckTraffic(new GeneralTraffic { FromAddress = "170.12.14.12" }, out rule)); Assert.IsNull(rule); } }
public void DefaultDeny() { using (var gate = new NetGate(null)) { gate.Configure(CONFIG_DEFAULT_DENY.AsLaconicConfig()); gate.Start(); Assert.AreEqual(GateAction.Deny, gate.CheckTraffic(new GeneralTraffic { FromAddress = "123.0.0.1" })); Rule rule; Assert.AreEqual(GateAction.Allow, gate.CheckTraffic(new GeneralTraffic { FromAddress = "170.12.14.12" }, out rule)); Assert.IsNotNull(rule); Assert.AreEqual("AdminAccess", rule.Name); Assert.AreEqual(GateAction.Allow, gate.CheckTraffic(new GeneralTraffic { FromAddress = "170.12.14.13" }, out rule)); Assert.IsNotNull(rule); Assert.AreEqual("AdminAccess", rule.Name); Assert.AreEqual(GateAction.Allow, gate.CheckTraffic(new GeneralTraffic { FromAddress = "14.2.1.12" }, out rule)); Assert.IsNotNull(rule); Assert.AreEqual("Workgroups", rule.Name); Assert.AreEqual(GateAction.Allow, gate.CheckTraffic(new GeneralTraffic { FromAddress = "14.2.1.46" }, out rule)); Assert.IsNotNull(rule); Assert.AreEqual("Workgroups", rule.Name); Assert.AreEqual(GateAction.Allow, gate.CheckTraffic(new GeneralTraffic { FromAddress = "14.2.1.18" }, out rule)); Assert.IsNotNull(rule); Assert.AreEqual("Workgroups", rule.Name); Assert.AreEqual(GateAction.Deny, gate.CheckTraffic(new GeneralTraffic { FromAddress = "14.2.2.18" }, out rule)); Assert.IsNull(rule); Assert.AreEqual(GateAction.Allow, gate.CheckTraffic(new GeneralTraffic { FromAddress = "3.118.2.12" }, out rule)); Assert.IsNotNull(rule); Assert.AreEqual("Workgroups", rule.Name); Assert.AreEqual(GateAction.Allow, gate.CheckTraffic(new GeneralTraffic { FromAddress = "3.118.2.13" }, out rule)); Assert.IsNotNull(rule); Assert.AreEqual("Workgroups", rule.Name); Assert.AreEqual(GateAction.Allow, gate.CheckTraffic(new GeneralTraffic { FromAddress = "3.118.2.14" }, out rule)); Assert.IsNotNull(rule); Assert.AreEqual("Workgroups", rule.Name); Assert.AreEqual(GateAction.Deny, gate.CheckTraffic(new GeneralTraffic { FromAddress = "3.118.2.15" }, out rule)); Assert.IsNull(rule); Assert.AreEqual(GateAction.Allow, gate.CheckTraffic(new GeneralTraffic { FromAddress = "77.123.1.14" }, out rule)); Assert.IsNotNull(rule); Assert.AreEqual("Workgroups", rule.Name); Assert.AreEqual(GateAction.Allow, gate.CheckTraffic(new GeneralTraffic { FromAddress = "45.2.2.12" }, out rule)); Assert.IsNotNull(rule); Assert.AreEqual("Workgroups", rule.Name); Assert.AreEqual(GateAction.Allow, gate.CheckTraffic(new GeneralTraffic { FromAddress = "45.2.2.75" }, out rule)); Assert.IsNotNull(rule); Assert.AreEqual("Workgroups", rule.Name); } }
public void DefaultAllow() { using (var gate = new NetGate(NOPApplication.Instance)) { gate.Configure(CONFIG_DEFAULT_ALLOW.AsLaconicConfig()); gate.Start(); Aver.IsTrue(GateAction.Allow == gate.CheckTraffic(new GeneralTraffic { FromAddress = "123.0.0.1" })); Rule rule; Aver.IsTrue(GateAction.Deny == gate.CheckTraffic(new GeneralTraffic { FromAddress = "170.12.14.12" }, out rule)); Aver.IsNotNull(rule); Aver.AreEqual("AdminAccess", rule.Name); Aver.IsTrue(GateAction.Deny == gate.CheckTraffic(new GeneralTraffic { FromAddress = "170.12.14.13" }, out rule)); Aver.IsNotNull(rule); Aver.AreEqual("AdminAccess", rule.Name); Aver.IsTrue(GateAction.Deny == gate.CheckTraffic(new GeneralTraffic { FromAddress = "14.2.1.12" }, out rule)); Aver.IsNotNull(rule); Aver.AreEqual("Workgroups", rule.Name); Aver.IsTrue(GateAction.Deny == gate.CheckTraffic(new GeneralTraffic { FromAddress = "14.2.1.46" }, out rule)); Aver.IsNotNull(rule); Aver.AreEqual("Workgroups", rule.Name); Aver.IsTrue(GateAction.Deny == gate.CheckTraffic(new GeneralTraffic { FromAddress = "14.2.1.18" }, out rule)); Aver.IsNotNull(rule); Aver.AreEqual("Workgroups", rule.Name); Aver.IsTrue(GateAction.Allow == gate.CheckTraffic(new GeneralTraffic { FromAddress = "14.2.2.18" }, out rule)); Aver.IsNull(rule); Aver.IsTrue(GateAction.Deny == gate.CheckTraffic(new GeneralTraffic { FromAddress = "3.118.2.12" }, out rule)); Aver.IsNotNull(rule); Aver.AreEqual("Workgroups", rule.Name); Aver.IsTrue(GateAction.Deny == gate.CheckTraffic(new GeneralTraffic { FromAddress = "3.118.2.13" }, out rule)); Aver.IsNotNull(rule); Aver.AreEqual("Workgroups", rule.Name); Aver.IsTrue(GateAction.Deny == gate.CheckTraffic(new GeneralTraffic { FromAddress = "3.118.2.14" }, out rule)); Aver.IsNotNull(rule); Aver.AreEqual("Workgroups", rule.Name); Aver.IsTrue(GateAction.Allow == gate.CheckTraffic(new GeneralTraffic { FromAddress = "3.118.2.15" }, out rule)); Aver.IsNull(rule); Aver.IsTrue(GateAction.Deny == gate.CheckTraffic(new GeneralTraffic { FromAddress = "77.123.1.14" }, out rule)); Aver.IsNotNull(rule); Aver.AreEqual("Workgroups", rule.Name); Aver.IsTrue(GateAction.Deny == gate.CheckTraffic(new GeneralTraffic { FromAddress = "45.2.2.12" }, out rule)); Aver.IsNotNull(rule); Aver.AreEqual("Workgroups", rule.Name); Aver.IsTrue(GateAction.Deny == gate.CheckTraffic(new GeneralTraffic { FromAddress = "45.2.2.75" }, out rule)); Aver.IsNotNull(rule); Aver.AreEqual("Workgroups", rule.Name); } }