Skip to content

Commit 10b33f5

Browse files
committed
Merge pull request #4 from AshleyPoole/just-automatic-analyzer
Adding automatic analyzer
2 parents 0d67731 + 0cb0ac1 commit 10b33f5

File tree

6 files changed

+119
-2
lines changed

6 files changed

+119
-2
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 AshleyPoole - www.ashleypoole.co.uk
3+
Copyright (c) 2015 AshleyPoole - www.ashleypoole.co.uk
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ The wrapper also contains an overloaded Analyze method which only requires the h
4747
public Analyze Analyze(string host)
4848
```
4949

50+
##### AutomaticAnalyze()
51+
52+
The Analyze method is used to initiate and wait for an assessment to complete before retrieving results. Compared to the normal Analyze() method this method keeps checking the Api and only when a scan has finished does it return. This saves the comsumer from having to write their own logic for handling an assessment in progress.
53+
Another call to GetEndpointDetails() may be needed to view the whole result set for a given endpoint.
54+
55+
```C#
56+
public Analyze AutomaticAnalyze(string host, Publish publish, ClearCache clearCache, FromCache fromCache, All all)
57+
```
58+
59+
The wrapper also contains an overloaded AutomaticAnalyze method which only requires the host parameter. Internal is uses the following parameter options - Publish.Off, ClearCache.On, FromCache.Ignore, All.On.
60+
```C#
61+
public Analyze AutomaticAnalyze(string host)
62+
```
63+
5064
##### GetEndpointData()
5165

5266
The GetEndpointData method is used to retrieve a fully results set.

SSLLWrapper.IntegrationTests/AnalyzeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void then_should_not_trigger_an_api_invocation_error()
5252
}
5353

5454
[TestMethod]
55-
public void then_should_analyze_status_should_not_be_null()
55+
public void then_analyze_status_should_not_be_null()
5656
{
5757
_analyze.status.Should().NotBeNullOrEmpty();
5858
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Configuration;
2+
using FluentAssertions;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using SSLLWrapper;
5+
using SSLLWrapper.Models.Response;
6+
7+
namespace given_that_I_make_a_automaticanalyze_request
8+
{
9+
[TestClass]
10+
public class when_i_expect_a_successful_result
11+
{
12+
private static SSLLService _ssllService;
13+
private static Analyze _analyze;
14+
private static string _host;
15+
16+
[ClassInitialize]
17+
public static void Setup(TestContext testContext)
18+
{
19+
_host = ConfigurationManager.AppSettings.Get("EndpointHost");
20+
_ssllService = new SSLLService(ConfigurationManager.AppSettings.Get("ApiUrl"));
21+
_analyze = _ssllService.AutomaticAnalyze(_host);
22+
}
23+
24+
[TestMethod]
25+
public void then_the_error_count_should_be_zero()
26+
{
27+
_analyze.Errors.Count.Should().Be(0);
28+
}
29+
30+
[TestMethod]
31+
public void then_HasErrorOccurred_should_be_false()
32+
{
33+
_analyze.HasErrorOccurred.Should().BeFalse();
34+
}
35+
36+
[TestMethod]
37+
public void then_status_code_header_should_be_greater_than_zero()
38+
{
39+
_analyze.Header.statusCode.Should().BeGreaterThan(0);
40+
}
41+
42+
[TestMethod]
43+
public void then_status_code_header_should_not_be_404()
44+
{
45+
_analyze.Header.statusCode.Should().NotBe(404);
46+
}
47+
48+
[TestMethod]
49+
public void then_should_not_trigger_an_api_invocation_error()
50+
{
51+
_analyze.Header.statusCode.Should().NotBe(400);
52+
}
53+
54+
[TestMethod]
55+
public void then_should_analyze_status_should_not_be_null()
56+
{
57+
_analyze.status.Should().NotBeNullOrEmpty();
58+
}
59+
60+
[TestMethod]
61+
public void then_start_time_should_be_greater_than_zero()
62+
{
63+
_analyze.startTime.Should().BeGreaterThan(0);
64+
}
65+
66+
[TestMethod]
67+
public void then_the_host_in_the_response_should_match_the_request()
68+
{
69+
_analyze.host.Should().Match(_host);
70+
}
71+
}
72+
}

SSLLWrapper.IntegrationTests/SSLLWrapper.IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
</Otherwise>
6565
</Choose>
6666
<ItemGroup>
67+
<Compile Include="AutomaticAnalyzeTests.cs" />
6768
<Compile Include="AnalyzeTests.cs" />
6869
<Compile Include="GetEndpointDetails.cs" />
6970
<Compile Include="GetStatusCodesTests.cs" />

SSLLWrapper/SSLLService.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading;
23
using SSLLWrapper.Domain;
34
using SSLLWrapper.External;
45
using SSLLWrapper.Interfaces;
@@ -124,6 +125,35 @@ public Analyze Analyze(string host, Publish publish, ClearCache clearCache, From
124125
return analyzeModel;
125126
}
126127

128+
public Analyze AutomaticAnalyze(string host)
129+
{
130+
return AutomaticAnalyze(host, 300, 15);
131+
}
132+
133+
public Analyze AutomaticAnalyze(string host, int maxWaitInterval, int sleepInterval)
134+
{
135+
return AutomaticAnalyze(host, Publish.Off, ClearCache.On, FromCache.Ignore, All.On, maxWaitInterval, sleepInterval);
136+
}
137+
138+
public Analyze AutomaticAnalyze(string host, Publish publish, ClearCache clearCache, FromCache fromCache, All all, int maxWaitInterval, int sleepInterval)
139+
{
140+
var startTime = DateTime.Now;
141+
var sleepIntervalMilliseconds = sleepInterval * 1000;
142+
var analyzeModel = Analyze(host, publish, clearCache, fromCache, all);
143+
144+
// Ignoring cache settings after first request to prevent loop
145+
clearCache = ClearCache.Ignore;
146+
147+
// Shouldn't have to check status header as HasErrorOccurred should be enough
148+
while (analyzeModel.HasErrorOccurred == false && analyzeModel.status != "READY" && (DateTime.Now - startTime).TotalSeconds < maxWaitInterval)
149+
{
150+
Thread.Sleep(sleepIntervalMilliseconds);
151+
analyzeModel = Analyze(host, publish, clearCache, fromCache, all);
152+
}
153+
154+
return analyzeModel;
155+
}
156+
127157
public Endpoint GetEndpointData(string host, string s)
128158
{
129159
return GetEndpointData(host, s, FromCache.Off);

0 commit comments

Comments
 (0)