public static void Setup(TestContext testContext)
        {
            var mockedApiProvider = new Mock <IApiProvider>();

            TestHost = "www.ashleypoole.somereallybadurl";

            var ssllService = new SSLLabsApiService("https://api.ssllabs.com/api/v2/", mockedApiProvider.Object);

            Response = ssllService.Analyze(TestHost);
        }
        public static void Setup(TestContext testContext)
        {
            var mockedApiProvider = new Mock <IApiProvider>();

            TestHost = "https://www.ashleypoole.co.uk";
            var webResponseModel = new WebResponseModel()
            {
                Payloay           = "{\"errors\":[{\"message\":\"Parameters \u0027fromCache\u0027 and \u0027startNew\u0027 cannot be used at the same time\"}]}",
                StatusCode        = 400,
                StatusDescription = "Ok",
                Url = ("https://api.ssllabs.com/api/v2/analyze?host=" + TestHost + "&startNew=on&fromCache=on&all=done")
            };

            mockedApiProvider.Setup(x => x.MakeGetRequest(It.IsAny <RequestModel>())).Returns(webResponseModel);

            var ssllService = new SSLLabsApiService("https://api.ssllabs.com/api/v2/", mockedApiProvider.Object);

            Response = ssllService.Analyze(TestHost, SSLLabsApiService.Publish.On, SSLLabsApiService.StartNew.On,
                                           SSLLabsApiService.FromCache.Ignore, null, SSLLabsApiService.All.Done, SSLLabsApiService.IgnoreMismatch.Off);
        }
        public static void Setup(TestContext testContext)
        {
            var mockedApiProvider = new Mock <IApiProvider>();

            TestHost = "https://www.ashleypoole.co.uk";
            var webResponseModel = new WebResponseModel()
            {
                Payloay = "{\"host\":\"https://www.ashleypoole.co.uk\",\"port\":443,\"protocol\":\"HTTP\",\"isPublic\":false,\"status\":\"DNS\"" +
                          ",\"statusMessage\":\"Resolving domain names\",\"startTime\":1422475200798,\"engineVersion\":\"1.12.8\"," +
                          "\"criteriaVersion\":\"2009i\"}",
                StatusCode        = 200,
                StatusDescription = "Ok",
                Url = ("https://api.ssllabs.com/api/v2/analyze?host=" + TestHost)
            };

            mockedApiProvider.Setup(x => x.MakeGetRequest(It.IsAny <RequestModel>())).Returns(webResponseModel);

            var ssllService = new SSLLabsApiService("https://api.ssllabs.com/api/v2/", mockedApiProvider.Object);

            Response = ssllService.Analyze(TestHost);
        }
        public static void Setup(TestContext testContext)
        {
            var mockedApiProvider = new Mock <IApiProvider>();

            TestHost = "https://www2.ashleypoole.co.uk";
            var webResponseModel = new WebResponseModel()
            {
                Payloay = "{\"host\":\"https://www2.ashleypoole.co.uk\",\"port\":443,\"protocol\":\"HTTP\",\"isPublic\":false,\"status\":\"ERROR\"," +
                          "\"statusMessage\":\"Unable to resolve domain name\",\"startTime\":1422478797953,\"testTime\":1422478798017," +
                          "\"engineVersion\":\"1.12.8\",\"criteriaVersion\":\"2009i\",\"cacheExpiryTime\":1422478858017}",
                StatusCode        = 200,
                StatusDescription = "Ok",
                Url = ("https://api.ssllabs.com/api/v2/analyze?host=" + TestHost)
            };

            mockedApiProvider.Setup(x => x.MakeGetRequest(It.IsAny <RequestModel>())).Returns(webResponseModel);

            var ssllService = new SSLLabsApiService("https://api.ssllabs.com/api/v2/", mockedApiProvider.Object);

            Response = ssllService.Analyze(TestHost, SSLLabsApiService.Publish.On, SSLLabsApiService.StartNew.On,
                                           SSLLabsApiService.FromCache.Ignore, null, SSLLabsApiService.All.Done, SSLLabsApiService.IgnoreMismatch.Off);
        }
        public static void Setup(TestContext testContext)
        {
            var mockedApiProvider = new Mock <IApiProvider>();

            TestHost = "https://www.ashleypoole.co.uk";
            var webResponseModel = new WebResponseModel()
            {
                Payloay = "{\"host\":\"https://www.ashleypoole.co.uk\",\"port\":443,\"protocol\":\"HTTP\",\"isPublic\":true,\"" +
                          "status\":\"IN_PROGRESS\",\"startTime\":1422479488403,\"engineVersion\":\"1.12.8\",\"criteriaVersion\":\"2009i\"" +
                          ",\"endpoints\":[{\"ipAddress\":\"104.28.6.2\",\"statusMessage\":\"In progress\",\"statusDetails\":\"TESTING_HTTPS\"" +
                          ",\"statusDetailsMessage\":\"Sending one complete HTTPS request\",\"progress\":-1,\"eta\":-1,\"delegation\":3}," +
                          "{\"ipAddress\":\"104.28.7.2\",\"statusMessage\":\"Pending\",\"progress\":-1,\"eta\":-1,\"delegation\":3}]}",
                StatusCode        = 200,
                StatusDescription = "Ok",
                Url = ("https://api.ssllabs.com/api/v2/analyze?host=" + TestHost + "&publish=on&all=done")
            };

            mockedApiProvider.Setup(x => x.MakeGetRequest(It.IsAny <RequestModel>())).Returns(webResponseModel);

            var ssllService = new SSLLabsApiService("https://api.ssllabs.com/api/v2/", mockedApiProvider.Object);

            Response = ssllService.Analyze(TestHost, SSLLabsApiService.Publish.On, SSLLabsApiService.StartNew.On,
                                           SSLLabsApiService.FromCache.Ignore, null, SSLLabsApiService.All.Done, SSLLabsApiService.IgnoreMismatch.Off);
        }
        public static void Setup(TestContext testContext)
        {
            var mockedApiProvider = new Mock <IApiProvider>();

            TestHost = "https://www.ashleypoole.co.uk";
            var webResponseModel = new WebResponseModel()
            {
                Payloay = "{\"host\":\"https://www.ashleypoole.co.uk\",\"port\":443,\"protocol\":\"HTTPS\",\"isPublic\":false,\"status\":\"READY\",\"" +
                          "startTime\":1422115006431,\"testTime\":1422115131804,\"engineVersion\":\"1.12.8\",\"criteriaVersion\":\"2009i\",\"" +
                          "endpoints\":[{\"ipAddress\":\"104.28.6.2\",\"statusMessage\":\"Ready\",\"grade\":\"A\",\"hasWarnings\":false,\"" +
                          "isExceptional\":false,\"progress\":100,\"duration\":64286,\"eta\":2393,\"delegation\":3},{\"ipAddress\":\"104.28.7.2\"" +
                          ",\"statusMessage\":\"Ready\",\"grade\":\"A\",\"hasWarnings\":false,\"isExceptional\":false,\"progress\":100,\"duration\"" +
                          ":61046,\"eta\":2393,\"delegation\":3}]}",
                StatusCode        = 200,
                StatusDescription = "Ok",
                Url = ("https://api.ssllabs.com/api/v2/analyze?host=" + TestHost)
            };

            mockedApiProvider.Setup(x => x.MakeGetRequest(It.IsAny <RequestModel>())).Returns(webResponseModel);

            var ssllService = new SSLLabsApiService("https://api.ssllabs.com/api/v2/", mockedApiProvider.Object);

            Response = ssllService.Analyze(TestHost);
        }
 public static void Setup(TestContext testContext)
 {
     _host        = ConfigurationManager.AppSettings.Get("EndpointHost");
     _ssllService = new SSLLabsApiService(ConfigurationManager.AppSettings.Get("ApiUrl"));
     _analyze     = _ssllService.Analyze(_host);
 }
Beispiel #8
0
        public IActionResult GetSSLLabsReport(string id, [FromBody] SSLLabsRequestModel requestModel)
        {
            // check for null values
            if (requestModel == null && requestModel.Host == null)
            {
                return(BadRequest(new { Status = "Please enter a hostname or an ip address", Body = "" }));
            }

            var project = _projectsDbContext.Get(id);

            // Start the scan or get a already started scan.
            var ssllService = new SSLLabsApiService("https://api.ssllabs.com/api/v3");
            var analyze     = ssllService.Analyze(host: requestModel.Host, publish: Publish.Off, startNew: StartNew.Ignore,
                                                  fromCache: FromCache.Off, maxHours: 1, all: All.On, ignoreMismatch: IgnoreMismatch.Off);

            // Check every 8 seconds to see if the scan has completed.
            while (analyze.status != "READY" && analyze.status != null)
            {
                Thread.Sleep(8000);

                analyze = ssllService.Analyze(host: requestModel.Host, publish: Publish.Off, startNew: StartNew.Ignore,
                                              fromCache: FromCache.Off, maxHours: 1, all: All.On, ignoreMismatch: IgnoreMismatch.Off);
            }

            // If there are errors, return error status to notify the user.
            if (analyze.Errors.Any())
            {
                if (analyze.Errors.First().message.Contains("529"))
                {
                    return(StatusCode(529, new { Status = "Service Overloaded. Try again in a few minutes.", Body = "" }));
                }
                else if (analyze.Errors.First().message.Contains("503"))
                {
                    return(StatusCode(503, new { Status = "Service Unavailable. Try again in a few minutes.", Body = "" }));
                }
                else if (analyze.Errors.First().message.Contains("500"))
                {
                    return(StatusCode(500, new { Status = "Service Error", Body = "" }));
                }
                else if (analyze.Errors.First().message.Contains("429"))
                {
                    return(StatusCode(429, new { Status = "Too Many Requests. Try again in a few seconds.", Body = "" }));
                }
                else if (analyze.Errors.First().message.Contains("400"))
                {
                    return(StatusCode(400, new { Status = "Invalid Parameters", Body = "" }));
                }
                else if (analyze.Errors.First().message.Contains("preflight validation"))
                {
                    return(StatusCode(400, new { Status = "Incorrect format used. Use the format: 'http://www.example.com'", Body = "" }));
                }
                else if (analyze.Errors.First().message.Contains("System.Net.WebException"))
                {
                    return(StatusCode(500, new { Status = "No connection could be made. Try again in a few minutes.", Body = "" }));
                }
                else
                {
                    return(StatusCode(500, new { Status = "Something went wrong. Please try again", Body = "" }));
                }
            }

            // Save the api responsedata.
            project.SSLLabsDataTimeLastScan = DateTime.Now;
            project.SSLLabsData             = analyze.Wrapper.ApiRawResponse;
            _projectsDbContext.Put(id, project);

            // Return the raw response because the model in the wrapper is not up to date.
            return(Ok(analyze.Wrapper.ApiRawResponse));
        }