Ejemplo n.º 1
0
        public void Test_LoadCustomAddinAssembly()
        {
            MockRepository mocks = new MockRepository();

            // Set new
            EsapiConfig.Instance.Validator.Type = typeof(SurrogateValidator).AssemblyQualifiedName;

            // Set assemblies to load
            AddinAssemblyElement addinAssembly = new AddinAssemblyElement();
            addinAssembly.Name = typeof(Esapi).Assembly.FullName;
            EsapiConfig.Instance.Validator.Rules.Assemblies.Add(addinAssembly);

            // Set mock expectations
            IValidator mockValidator = mocks.StrictMock<IValidator>();

            // Load default
            Expect.Call(delegate { mockValidator.AddRule(BuiltinValidationRules.CreditCard, null); }).Constraints(Is.Equal(BuiltinValidationRules.CreditCard), Is.Anything());
            Expect.Call(delegate { mockValidator.AddRule(BuiltinValidationRules.Date, null); }).Constraints(Is.Equal(BuiltinValidationRules.Date), Is.Anything());
            Expect.Call(delegate { mockValidator.AddRule(BuiltinValidationRules.Double, null); }).Constraints(Is.Equal(BuiltinValidationRules.Double), Is.Anything());
            Expect.Call(delegate { mockValidator.AddRule(BuiltinValidationRules.Integer, null); }).Constraints(Is.Equal(BuiltinValidationRules.Integer), Is.Anything());
            Expect.Call(delegate { mockValidator.AddRule(BuiltinValidationRules.Printable, null); }).Constraints(Is.Equal(BuiltinValidationRules.Printable), Is.Anything());
            mocks.ReplayAll();

            // Create and test
            SurrogateValidator.DefaultValidator = mockValidator;
            IValidator validator = Esapi.Validator;

            Assert.IsTrue(validator.GetType().Equals(typeof(SurrogateValidator)));
            mocks.VerifyAll();
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Removes the specified <see cref="AddinAssemblyElement" />.
 /// </summary>
 /// <param name="assembly">The <see cref="AddinAssemblyElement" /> to remove.</param>
 public void Remove(AddinAssemblyElement assembly)
 {
     this.BaseRemove(assembly);
 }
Ejemplo n.º 3
0
 /// <summary>
 ///     Adds the specified <see cref="AddinAssemblyElement" />.
 /// </summary>
 /// <param name="assembly">The <see cref="AddinAssemblyElement" /> to add.</param>
 public void Add(AddinAssemblyElement assembly)
 {
     this.BaseAdd(assembly);
 }
Ejemplo n.º 4
0
        public void Test_LoadCustomAddinAssembly()
        {
            MockRepository mocks = new MockRepository();

            // Set new
            EsapiConfig.Instance.Encoder.Type = typeof(SurrogateEncoder).AssemblyQualifiedName;

            // Set assemblies to load
            AddinAssemblyElement addinAssembly = new AddinAssemblyElement();
            addinAssembly.Name =  typeof(Esapi).Assembly.FullName;
            EsapiConfig.Instance.Encoder.Codecs.Assemblies.Add(addinAssembly);
            
            // Set mock expectations
            IEncoder mockEncoder = mocks.StrictMock<IEncoder>();
            
            // Load default
            Expect.Call(delegate { mockEncoder.AddCodec(BuiltinCodecs.Base64, null); }).Constraints(Is.Equal(BuiltinCodecs.Base64), Is.Anything());
            Expect.Call(delegate { mockEncoder.AddCodec(BuiltinCodecs.Html, null); }).Constraints(Is.Equal(BuiltinCodecs.Html), Is.Anything());
            Expect.Call(delegate { mockEncoder.AddCodec(BuiltinCodecs.HtmlAttribute, null); }).Constraints(Is.Equal(BuiltinCodecs.HtmlAttribute), Is.Anything());
            Expect.Call(delegate { mockEncoder.AddCodec(BuiltinCodecs.JavaScript, null); }).Constraints(Is.Equal(BuiltinCodecs.JavaScript), Is.Anything());
            Expect.Call(delegate { mockEncoder.AddCodec(BuiltinCodecs.Url, null); }).Constraints(Is.Equal(BuiltinCodecs.Url), Is.Anything());
            Expect.Call(delegate { mockEncoder.AddCodec(BuiltinCodecs.VbScript, null); }).Constraints(Is.Equal(BuiltinCodecs.VbScript), Is.Anything());
            Expect.Call(delegate { mockEncoder.AddCodec(BuiltinCodecs.Xml, null); }).Constraints(Is.Equal(BuiltinCodecs.Xml), Is.Anything());
            Expect.Call(delegate { mockEncoder.AddCodec(BuiltinCodecs.XmlAttribute, null); }).Constraints(Is.Equal(BuiltinCodecs.XmlAttribute), Is.Anything());
            mocks.ReplayAll();

            // Create and test
            SurrogateEncoder.DefaultEncoder = mockEncoder;
            IEncoder encoder = Esapi.Encoder;

            Assert.IsTrue(encoder.GetType().Equals(typeof(SurrogateEncoder)));
            mocks.VerifyAll();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Removes the specified <see cref="AddinAssemblyElement"/>.
 /// </summary>
 /// <param name="assembly">The <see cref="AddinAssemblyElement"/> to remove.</param>
 public void Remove(AddinAssemblyElement assembly)
 {
     base.BaseRemove(assembly);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Adds the specified <see cref="AddinAssemblyElement"/>.
 /// </summary>
 /// <param name="assembly">The <see cref="AddinAssemblyElement"/> to add.</param>
 public void Add(AddinAssemblyElement assembly)
 {
     base.BaseAdd(assembly);
 }