Skip to content

Commit 9d2487b

Browse files
committed
Adding support for Api v2.1
1 parent 78af3bb commit 9d2487b

File tree

4 files changed

+37
-23
lines changed

4 files changed

+37
-23
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ public enum All
189189
}
190190
```
191191

192+
### Development ToDo List
193+
- Increase testing around ignoreMismatch parameter on Analyze call
194+
- Increase testing around maxAge parameter on Analyze call
195+
- Increase integration tests around positive and negative outcomes
196+
197+
192198
### Author
193199
Ashley Poole - www.ashleypoole.co.uk.
194200

SSLLabsApiWrapper.Tests/AnalyzeTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public static void Setup(TestContext testContext)
9898
mockedApiProvider.Setup(x => x.MakeGetRequest(It.IsAny<RequestModel>())).Returns(webResponseModel);
9999

100100
var ssllService = new SSLLabsApiService("https://api.dev.ssllabs.com/api/fa78d5a4/", mockedApiProvider.Object);
101-
Response = ssllService.Analyze(TestHost, SSLLabsApiService.Publish.On, SSLLabsApiService.ClearCache.On,
102-
SSLLabsApiService.FromCache.Ignore, SSLLabsApiService.All.Done);
101+
Response = ssllService.Analyze(TestHost, SSLLabsApiService.Publish.On, SSLLabsApiService.startNew.On,
102+
SSLLabsApiService.FromCache.Ignore, null, SSLLabsApiService.All.Done, SSLLabsApiService.ignoreMismatch.Off);
103103
}
104104

105105
[TestMethod]
@@ -130,8 +130,8 @@ public static void Setup(TestContext testContext)
130130
mockedApiProvider.Setup(x => x.MakeGetRequest(It.IsAny<RequestModel>())).Returns(webResponseModel);
131131

132132
var ssllService = new SSLLabsApiService("https://api.dev.ssllabs.com/api/fa78d5a4/", mockedApiProvider.Object);
133-
Response = ssllService.Analyze(TestHost, SSLLabsApiService.Publish.On, SSLLabsApiService.ClearCache.On,
134-
SSLLabsApiService.FromCache.Ignore, SSLLabsApiService.All.Done);
133+
Response = ssllService.Analyze(TestHost, SSLLabsApiService.Publish.On, SSLLabsApiService.startNew.On,
134+
SSLLabsApiService.FromCache.Ignore, null, SSLLabsApiService.All.Done, SSLLabsApiService.ignoreMismatch.Off);
135135
}
136136

137137
[TestMethod]
@@ -142,7 +142,7 @@ public void then_the_status_code_should_be_valid_for_response()
142142
}
143143

144144
[TestClass]
145-
public class when_a_invalid_request_is_made_with_both_clearCache_and_fromCache : NegativeTests
145+
public class when_a_invalid_request_is_made_with_both_startNew_and_fromCache : NegativeTests
146146
{
147147
[ClassInitialize]
148148
public static void Setup(TestContext testContext)
@@ -151,17 +151,17 @@ public static void Setup(TestContext testContext)
151151
TestHost = "https://www.ashleypoole.co.uk";
152152
var webResponseModel = new WebResponseModel()
153153
{
154-
Payloay = "{\"errors\":[{\"message\":\"Parameters \u0027fromCache\u0027 and \u0027clearCache\u0027 cannot be used at the same time\"}]}",
154+
Payloay = "{\"errors\":[{\"message\":\"Parameters \u0027fromCache\u0027 and \u0027startNew\u0027 cannot be used at the same time\"}]}",
155155
StatusCode = 400,
156156
StatusDescription = "Ok",
157-
Url = ("https://api.dev.ssllabs.com/api/fa78d5a4/analyze?host=" + TestHost + "&clearCache=on&fromCache=on&all=done")
157+
Url = ("https://api.dev.ssllabs.com/api/fa78d5a4/analyze?host=" + TestHost + "&startNew=on&fromCache=on&all=done")
158158
};
159159

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

162162
var ssllService = new SSLLabsApiService("https://api.dev.ssllabs.com/api/fa78d5a4/", mockedApiProvider.Object);
163-
Response = ssllService.Analyze(TestHost, SSLLabsApiService.Publish.On, SSLLabsApiService.ClearCache.On,
164-
SSLLabsApiService.FromCache.Ignore, SSLLabsApiService.All.Done);
163+
Response = ssllService.Analyze(TestHost, SSLLabsApiService.Publish.On, SSLLabsApiService.startNew.On,
164+
SSLLabsApiService.FromCache.Ignore, null, SSLLabsApiService.All.Done, SSLLabsApiService.ignoreMismatch.Off);
165165
}
166166
}
167167

SSLLabsApiWrapper/Domain/RequestModelFactory.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ public RequestModel NewInfoRequestModel(string apiBaseUrl, string action)
99
return new RequestModel() {ApiBaseUrl = apiBaseUrl, Action = action};
1010
}
1111

12-
public RequestModel NewAnalyzeRequestModel(string apiBaseUrl, string action, string host, string publish, string clearCache,
13-
string fromCache, string all)
12+
public RequestModel NewAnalyzeRequestModel(string apiBaseUrl, string action, string host, string publish, string startNew,
13+
string fromCache, int? maxHours, string all, string ignoreMismatch)
1414
{
1515
var requestModel = new RequestModel() { ApiBaseUrl = apiBaseUrl, Action = action};
1616

1717
requestModel.Parameters.Add("host", host);
1818
requestModel.Parameters.Add("publish", publish);
1919
requestModel.Parameters.Add("all", all);
2020

21-
if (clearCache != "ignore") { requestModel.Parameters.Add("clearCache", clearCache); }
21+
if (startNew != "ignore") { requestModel.Parameters.Add("startNew", startNew); }
2222
if (fromCache != "ignore") { requestModel.Parameters.Add("fromCache", fromCache); }
23+
if (maxHours != null) { requestModel.Parameters.Add("maxHours", maxHours.ToString()); }
24+
if (ignoreMismatch != "off") { requestModel.Parameters.Add("ignoreMismatch", ignoreMismatch); }
2325

2426
return requestModel;
2527
}

SSLLabsApiWrapper/SSLLabsApiService.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ public enum Publish
2424
Off
2525
}
2626

27-
public enum ClearCache
27+
public enum startNew
2828
{
2929
On,
30-
Off,
3130
Ignore
3231
}
3332

@@ -44,6 +43,12 @@ public enum All
4443
Done
4544
}
4645

46+
public enum ignoreMismatch
47+
{
48+
On,
49+
Off
50+
}
51+
4752
public SSLLabsApiService(string apiUrl) : this(apiUrl, new SSLLabsApi())
4853
{
4954
}
@@ -89,10 +94,10 @@ public Info Info()
8994
public Analyze Analyze(string host)
9095
{
9196
// overloaded method to provide a default set of options
92-
return Analyze(host, Publish.Off, ClearCache.On, FromCache.Ignore, All.On);
97+
return Analyze(host, Publish.Off, startNew.On, FromCache.Ignore, null, All.On, ignoreMismatch.Off);
9398
}
9499

95-
public Analyze Analyze(string host, Publish publish, ClearCache clearCache, FromCache fromCache, All all)
100+
public Analyze Analyze(string host, Publish publish, startNew startNew, FromCache fromCache, int? maxHours, All all, ignoreMismatch ignoreMismatch)
96101
{
97102
var analyzeModel = new Analyze();
98103

@@ -105,8 +110,8 @@ public Analyze Analyze(string host, Publish publish, ClearCache clearCache, From
105110
}
106111

107112
// Building request model
108-
var requestModel = _requestModelFactory.NewAnalyzeRequestModel(ApiUrl, "analyze", host, publish.ToString().ToLower(), clearCache.ToString().ToLower(),
109-
fromCache.ToString().ToLower(), all.ToString().ToLower());
113+
var requestModel = _requestModelFactory.NewAnalyzeRequestModel(ApiUrl, "analyze", host, publish.ToString().ToLower(), startNew.ToString().ToLower(),
114+
fromCache.ToString().ToLower(), maxHours, all.ToString().ToLower(), ignoreMismatch.ToString().ToLower());
110115

111116
try
112117
{
@@ -132,25 +137,26 @@ public Analyze AutomaticAnalyze(string host)
132137

133138
public Analyze AutomaticAnalyze(string host, int maxWaitInterval, int sleepInterval)
134139
{
135-
return AutomaticAnalyze(host, Publish.Off, ClearCache.On, FromCache.Ignore, All.On, maxWaitInterval, sleepInterval);
140+
return AutomaticAnalyze(host, Publish.Off, startNew.On, FromCache.Ignore, null, All.On, ignoreMismatch.Off, maxWaitInterval, sleepInterval);
136141
}
137142

138-
public Analyze AutomaticAnalyze(string host, Publish publish, ClearCache clearCache, FromCache fromCache, All all, int maxWaitInterval, int sleepInterval)
143+
public Analyze AutomaticAnalyze(string host, Publish publish, startNew startNew, FromCache fromCache, int? maxHours, All all, ignoreMismatch ignoreMismatch,
144+
int maxWaitInterval, int sleepInterval)
139145
{
140146
var startTime = DateTime.Now;
141147
var sleepIntervalMilliseconds = sleepInterval * 1000;
142148
var apiPassCount = 1;
143-
var analyzeModel = Analyze(host, publish, clearCache, fromCache, all);
149+
var analyzeModel = Analyze(host, publish, startNew, fromCache, maxHours, all, ignoreMismatch);
144150

145151
// Ignoring cache settings after first request to prevent loop
146-
clearCache = ClearCache.Ignore;
152+
startNew = startNew.Ignore;
147153

148154
// Shouldn't have to check status header as HasErrorOccurred should be enough
149155
while (analyzeModel.HasErrorOccurred == false && analyzeModel.status != "READY" && (DateTime.Now - startTime).TotalSeconds < maxWaitInterval)
150156
{
151157
Thread.Sleep(sleepIntervalMilliseconds);
152158
apiPassCount ++;
153-
analyzeModel = Analyze(host, publish, clearCache, fromCache, all);
159+
analyzeModel = Analyze(host, publish, startNew, fromCache, null, all, ignoreMismatch);
154160
}
155161

156162
analyzeModel.Wrapper.ApiPassCount = apiPassCount;

0 commit comments

Comments
 (0)