Exemplo n.º 1
0
        public void ApiLogic_Scan_NoKeyOrName_ResponseValid()
        {
            // Arrange
            ApiLogic logic = new ApiLogic(string.Empty, string.Empty, "notasafaweb.apphb.com");

            // Act
            logic.Scan();
        }
Exemplo n.º 2
0
        public void ApiLogic_Scan_NotAsafaWeb_ResponseValid()
        {
            // Arrange
            ApiLogic logic = new ApiLogic(NAME, KEY, "notasafaweb.apphb.com");
            // Act
            var result = logic.Scan();

            // Assert
            Assert.That(result.GetType(), Is.EqualTo(typeof(ApiScanResult)));
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            StatusLogic logic = LoadParams(args);
            ApiLogic    api   = new ApiLogic(_name, _key, _url);

            if (_validParams)
            {
                Console.Write("Selected failures: ");
                if (logic.FailOnFailure)
                {
                    Console.Write("Failures ");
                }
                if (logic.FailOnWarning)
                {
                    Console.Write("Warnings ");
                }
                if (logic.FailOnNotTested)
                {
                    Console.Write("Not Tested");
                }
                if (!logic.FailOnNotTested && !logic.FailOnWarning && !logic.FailOnFailure)
                {
                    Console.Write("None, this will always pass");
                }
                Console.WriteLine();
                if (logic.IgnoredTests.Count > 0)
                {
                    Console.WriteLine("Ignored Tests: {0}", logic.IgnoredTests.Aggregate((i, j) => i + ", " + j));
                }
                Console.WriteLine("Scanning {0}", _url);
                var results = logic.AnalyseResults(api.Scan());
                if (results.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("ERROR DETECTED:");
                    foreach (var asafaResult in results)
                    {
                        sb.AppendLine(string.Format("The {0} test has failed with the status {1}", asafaResult.Key, asafaResult.Value));
                    }
                    sb.AppendLine();
                    sb.AppendLine(string.Format("For more information visit https://asafaweb.com/Scan?Url={0}", HttpUtility.UrlEncode(_url)));
                    Console.WriteLine(sb.ToString());
                    if (_throwExceptionOnFail)
                    {
                        throw new Exception(sb.ToString());
                    }
                }
                Console.WriteLine("No errors found");
            }
        }