/// <summary> /// Splits the rule flags. /// </summary> /// <param name="flags">The flags.</param> /// <returns></returns> protected IRuleFlagProcessor SplitRuleFlags(string flags) { RuleFlagProcessor dictionary = new RuleFlagProcessor(); List <string> temporaryHolding = new List <string>(); dictionary.BeginAdd(); foreach (string flag in flags.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { string temp = flag; if (flag.Contains("\"") || temporaryHolding.Count > 0) { temporaryHolding.Add(flag.Replace("\"", String.Empty)); if (flag.Contains("\"") && temporaryHolding.Count > 1) { temp = String.Join(",", temporaryHolding.ToArray()); temporaryHolding.Clear(); } else { continue; } } IRuleFlag ruleFlag = AddRuleFlag(temp); if (ruleFlag != null) { dictionary.Add(ruleFlag); } } dictionary.EndAdd(); return(dictionary); }
public void OrderOfOpperations_Followed_3() { // arrange var processor = new RuleFlagProcessor(); // act processor.BeginAdd(); processor.Add(new NoCaseFlag()); processor.Add(new NoEscapeFlag()); processor.Add(new ResponseCookieFlag("test", "test", "test", null, "/")); processor.Add(new RedirectFlag(302)); processor.EndAdd(); // assert var list = processor.ToList(); Assert.IsInstanceOf<NoCaseFlag>(list[0]); Assert.IsInstanceOf<NoEscapeFlag>(list[1]); Assert.IsInstanceOf<ResponseCookieFlag>(list[2]); Assert.IsInstanceOf<RedirectFlag>(list[3]); }
public void OrderOfOpperations_Followed_3() { // arrange var processor = new RuleFlagProcessor(); // act processor.BeginAdd(); processor.Add(new NoCaseFlag()); processor.Add(new NoEscapeFlag()); processor.Add(new ResponseCookieFlag("test", "test", "test", null, "/")); processor.Add(new RedirectFlag(302)); processor.EndAdd(); // assert var list = processor.ToList(); Assert.IsInstanceOf <NoCaseFlag>(list[0]); Assert.IsInstanceOf <NoEscapeFlag>(list[1]); Assert.IsInstanceOf <ResponseCookieFlag>(list[2]); Assert.IsInstanceOf <RedirectFlag>(list[3]); }
public void OrderOfOpperations_NotFollowed_LastMiddleFirst() { // arrange var processor = new RuleFlagProcessor(); // act processor.BeginAdd(); processor.Add(new ProxyFlag()); processor.Add(new NoCaseFlag()); processor.Add(new LastFlag()); processor.Add(new NoEscapeFlag()); processor.Add(new ResponseCookieFlag("test", "test", "test", null, "/")); processor.Add(new LastFlag()); processor.EndAdd(); // assert var list = processor.ToList(); Assert.IsInstanceOf <NoCaseFlag>(list[0]); Assert.IsInstanceOf <NoEscapeFlag>(list[1]); Assert.IsInstanceOf <ResponseCookieFlag>(list[2]); Assert.IsInstanceOf <ProxyFlag>(list[3]); Assert.IsInstanceOf <LastFlag>(list[4]); Assert.IsInstanceOf <LastFlag>(list[5]); }
public void NotBulkLoaded() { // arrange var processor = new RuleFlagProcessor(); // act processor.Add(new ProxyFlag()); processor.Add(new NoCaseFlag()); processor.Add(new LastFlag()); processor.Add(new NoEscapeFlag()); processor.Add(new ResponseCookieFlag("test", "test", "test", null, "/")); processor.Add(new LastFlag()); // assert var list = processor.ToList(); Assert.IsInstanceOf <NoCaseFlag>(list[0]); Assert.IsInstanceOf <NoEscapeFlag>(list[1]); Assert.IsInstanceOf <ResponseCookieFlag>(list[2]); Assert.IsInstanceOf <ProxyFlag>(list[3]); Assert.IsInstanceOf <LastFlag>(list[4]); Assert.IsInstanceOf <LastFlag>(list[5]); }
public void NotBulkLoaded() { // arrange var processor = new RuleFlagProcessor(); // act processor.Add(new ProxyFlag()); processor.Add(new NoCaseFlag()); processor.Add(new LastFlag()); processor.Add(new NoEscapeFlag()); processor.Add(new ResponseCookieFlag("test", "test", "test", null, "/")); processor.Add(new LastFlag()); // assert var list = processor.ToList(); Assert.IsInstanceOf<NoCaseFlag>(list[0]); Assert.IsInstanceOf<NoEscapeFlag>(list[1]); Assert.IsInstanceOf<ResponseCookieFlag>(list[2]); Assert.IsInstanceOf<ProxyFlag>(list[3]); Assert.IsInstanceOf<LastFlag>(list[4]); Assert.IsInstanceOf<LastFlag>(list[5]); }
public void OrderOfOpperations_NotFollowed_LastMiddleFirst() { // arrange var processor = new RuleFlagProcessor(); // act processor.BeginAdd(); processor.Add(new ProxyFlag()); processor.Add(new NoCaseFlag()); processor.Add(new LastFlag()); processor.Add(new NoEscapeFlag()); processor.Add(new ResponseCookieFlag("test", "test", "test", null, "/")); processor.Add(new LastFlag()); processor.EndAdd(); // assert var list = processor.ToList(); Assert.IsInstanceOf<NoCaseFlag>(list[0]); Assert.IsInstanceOf<NoEscapeFlag>(list[1]); Assert.IsInstanceOf<ResponseCookieFlag>(list[2]); Assert.IsInstanceOf<ProxyFlag>(list[3]); Assert.IsInstanceOf<LastFlag>(list[4]); Assert.IsInstanceOf<LastFlag>(list[5]); }
/// <summary> /// Gets the rule. /// </summary> /// <param name="ruleElement">The rule element.</param> /// <returns></returns> private IRule GetRule(XmlNode ruleElement) { if (ruleElement == null) { throw new ArgumentNullException("ruleElement"); } if (ruleElement.Name != "rule") { throw new RuleSetException("The node is not a \"rule\"."); } bool enabled = true; // from schema definition if (ruleElement.Attributes["enabled"] != null) { enabled = XmlConvert.ToBoolean(ruleElement.Attributes["enabled"].Value); } // if it is not enabled there is no reason to continue processing if (!enabled) { return(null); } string name = String.Empty; bool stopProcessing = false; // from schema definition string patternSyntax = "ECMAScript"; // from schema definiton if (ruleElement.Attributes["name"] != null) { name = ruleElement.Attributes["name"].Value; } if (ruleElement.Attributes["stopProcessing"] != null) { stopProcessing = XmlConvert.ToBoolean(ruleElement.Attributes["stopProcessing"].Value); } if (ruleElement.Attributes["patternSyntax"] != null) { patternSyntax = ruleElement.Attributes["patternSyntax"].Value; } XmlNode matchElement = ruleElement.SelectSingleNode("match"); XmlNode conditionsElement = ruleElement.SelectSingleNode("conditions"); XmlNode serverVariablesElement = ruleElement.SelectSingleNode("serverVariables"); XmlNode actionElement = ruleElement.SelectSingleNode("action"); IRuleFlagProcessor ruleFlags = new RuleFlagProcessor(); IRule rule = new DefaultRule(); rule.Name = name; // <match /> Pattern match = GetMatch(matchElement, ref ruleFlags); // <condition /> IEnumerable <ICondition> conditions = GetConditions(conditionsElement); // <serverVariables /> foreach (var flag in GetServerVariables(serverVariablesElement)) { ruleFlags.Add(flag); } // <action /> IRuleAction action = GetAction(actionElement, match, ref ruleFlags); // <rule /> rule.Init(conditions, action, ruleFlags); return(rule); }