Exemplo n.º 1
0
        internal static void RunExpression(string text, OWASP.Policy policy, int expectedErrorNumber, string[] expectedErrors)
        {
            OWASP.AntiSamy as1 = new OWASP.AntiSamy();
            OWASP.CleanResults cr = as1.scan(text, policy);

            if (expectedErrors == null)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < cr.getNumberOfErrors(); i++)
                {
                    sb.AppendLine(cr.getErrorMessages()[i].ToString());
                }
                if (sb.Length > 0)
                    Assert.Fail(sb.ToString());
                Assert.AreEqual(0, cr.getNumberOfErrors());
            }
            else
            {
                Assert.AreEqual(expectedErrors.Length, cr.getNumberOfErrors());
                for (int i = 0; i < cr.getNumberOfErrors(); i++)
                {
                    Assert.AreEqual(expectedErrors[i], cr.getErrorMessages()[i].ToString());
                }
            }

            Assert.AreEqual(expectedErrorNumber, cr.getNumberOfErrors());
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                System.Console.Error.WriteLine("Please specify a URL or file name to filter - thanks!");
                System.Console.ReadLine();
                return;
            }
            string filename;

            filename = args[0];
            try
            {
                string buff = "";
                if (!File.Exists(filename))
                {
                    WebClient client = new WebClient();
                    byte[]    bytes;
                    try
                    {
                        bytes = client.DownloadData(filename);
                    }
                    catch (WebException we)
                    {
                        Console.WriteLine("Encountered an IOException while reading URL: ");
                        Console.WriteLine(we.StackTrace);
                        return;
                    }
                    buff = Encoding.ASCII.GetString(bytes);
                }
                else
                {
                    FileStream   fileStream   = null;
                    StreamReader streamReader = null;
                    try
                    {
                        fileStream   = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None);
                        streamReader = new StreamReader(fileStream);
                        buff         = streamReader.ReadToEnd();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Please specify a valid file name to filter - thanks!");
                        Console.WriteLine(ex.StackTrace);
                    }
                    finally
                    {
                        if (fileStream != null)
                        {
                            fileStream.Close();
                        }
                        if (streamReader != null)
                        {
                            streamReader.Close();
                        }
                    }
                }

                AntiSamy     _as  = new AntiSamy();
                CleanResults test = _as.scan(buff);

                Console.WriteLine("[1] Finished scan [" + test.getCleanHTML().Length + " bytes] in " + test.getScanTime() + " seconds\n");
                Console.WriteLine("[2] Clean HTML fragment:\n" + test.getCleanHTML());
                Console.WriteLine("[3] Error Messages (" + test.getNumberOfErrors() + "):");


                for (int i = 0; i < test.getErrorMessages().Count; i++)
                {
                    string s = test.getErrorMessages()[i].ToString();
                    Console.WriteLine(s);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            Console.ReadLine();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {

            string filename;
            filename = args[0];

            if (args.Length == 0)
            {
                System.Console.Error.WriteLine("Please specify a URL or file name to filter - thanks!");
                System.Console.ReadLine();
                return;
            }
            
            try
            {

                string buff = "";
                if (!File.Exists(filename))
                {
                    WebClient client = new WebClient();
                    byte[] bytes;
                    try
                    {
                        bytes = client.DownloadData(filename);
                    }
                    catch (WebException we)
                    {
                        Console.WriteLine("Encountered an IOException while reading URL: ");
                        Console.WriteLine(we.StackTrace);
                        return;
                    }
                    buff = Encoding.ASCII.GetString(bytes);
                }
                else
                {
                    FileStream fileStream = null;
                    StreamReader streamReader = null;
                    try
                    {
                        fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None);
                        streamReader = new StreamReader(fileStream);
                        buff = streamReader.ReadToEnd();

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Please specify a valid file name to filter - thanks!");
                        Console.WriteLine(ex.StackTrace);
                    }
                    finally
                    {
                        if (fileStream != null) fileStream.Close();
                        if (streamReader != null) streamReader.Close();
                    }
                }

                AntiSamy _as = new AntiSamy();
                CleanResults test = _as.scan(buff);

                Console.WriteLine("[1] Finished scan [" + test.getCleanHTML().Length + " bytes] in " + test.getScanTime() + " seconds\n");
                Console.WriteLine("[2] Clean HTML fragment:\n" + test.getCleanHTML());
                Console.WriteLine("[3] Error Messages (" + test.getNumberOfErrors() + "):");


                for (int i = 0; i < test.getErrorMessages().Count; i++)
                {
                    string s = test.getErrorMessages()[i].ToString();
                    Console.WriteLine(s);
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            Console.ReadLine();
        }