Skip to content

Commit f240157

Browse files
committed
Adding positive Analyze tests
1 parent e67ecd7 commit f240157

File tree

4 files changed

+98
-63
lines changed

4 files changed

+98
-63
lines changed

SSLLWrapper.Tests/AnalyzeSharedTests/NegativeTests.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

SSLLWrapper.Tests/AnalyzeSharedTests/PositiveTests.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

SSLLWrapper.Tests/AnalyzeTests.cs

Lines changed: 98 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
using System.IO;
2-
using System.Net;
3-
using FluentAssertions;
1+
using FluentAssertions;
42
using Microsoft.VisualStudio.TestTools.UnitTesting;
53
using Moq;
64
using SSLLWrapper;
75
using SSLLWrapper.Interfaces;
86
using SSLLWrapper.Models;
97
using SSLLWrapper.Models.Response;
10-
using SSLLWrapper.Tests.AnalyzeSharedTests;
8+
using SSLLWrapper.Tests;
119

1210
namespace given_that_I_make_a_analyze_request
1311
{
1412
[TestClass]
15-
public class when_the_api_is_online_and_a_valid_request_is_made : PositiveTests
13+
public class when_a_valid_request_is_made_with_just_a_hostname_and_the_scan_has_completed : PositiveTests
1614
{
1715
[ClassInitialize]
1816
public static void Setup(TestContext testContext)
1917
{
2018
var mockedApiProvider = new Mock<IApiProvider>();
21-
TestHost = "www.ashleypoole.co.uk";
19+
TestHost = "https://www.ashleypoole.co.uk";
2220
var webResponseModel = new WebResponseModel()
2321
{
2422
Payloay = "{\"host\":\"www.ashleypoole.co.uk\",\"port\":443,\"protocol\":\"HTTPS\",\"isPublic\":true,\"status\":\"READY\",\"" +
@@ -35,13 +33,105 @@ public static void Setup(TestContext testContext)
3533
mockedApiProvider.Setup(x => x.MakeGetRequest(It.IsAny<RequestModel>())).Returns(webResponseModel);
3634

3735
var ssllService = new SSLLService("https://api.dev.ssllabs.com/api/fa78d5a4/", mockedApiProvider.Object);
38-
AnalyzeResponse = ssllService.Analyze(TestHost);
36+
Response = ssllService.Analyze(TestHost);
37+
}
38+
39+
[TestMethod]
40+
public void then_the_scan_results_should_not_be_public()
41+
{
42+
Response.isPublic.Should().BeFalse();
43+
}
44+
}
45+
46+
[TestClass]
47+
public class when_a_valid_request_is_made_with_just_a_hostname_and_the_scan_is_at_resolving_stage: PositiveTests
48+
{
49+
[ClassInitialize]
50+
public static void Setup(TestContext testContext)
51+
{
52+
var mockedApiProvider = new Mock<IApiProvider>();
53+
TestHost = "https://www.ashleypoole.co.uk";
54+
var webResponseModel = new WebResponseModel()
55+
{
56+
Payloay = "{\"host\":\"www.ashleypoole.co.uk\",\"port\":443,\"protocol\":\"HTTP\",\"isPublic\":false,\"status\":\"DNS\"" +
57+
",\"statusMessage\":\"Resolving domain names\",\"startTime\":1422475200798,\"engineVersion\":\"1.12.8\"," +
58+
"\"criteriaVersion\":\"2009i\"}",
59+
StatusCode = 200,
60+
StatusDescription = "Ok",
61+
Url = ("https://api.dev.ssllabs.com/api/fa78d5a4/analyze?host=" + TestHost)
62+
};
63+
64+
mockedApiProvider.Setup(x => x.MakeGetRequest(It.IsAny<RequestModel>())).Returns(webResponseModel);
65+
66+
var ssllService = new SSLLService("https://api.dev.ssllabs.com/api/fa78d5a4/", mockedApiProvider.Object);
67+
Response = ssllService.Analyze(TestHost);
68+
}
69+
70+
[TestMethod]
71+
public void then_the_scan_results_should_not_be_public()
72+
{
73+
Response.isPublic.Should().BeFalse();
74+
}
75+
}
76+
77+
[TestClass]
78+
public class when_a_valid_request_is_made_with_all_the_inputs_and_the_scan_is_at_endpoint_scanning_stage : PositiveTests
79+
{
80+
[ClassInitialize]
81+
public static void Setup(TestContext testContext)
82+
{
83+
var mockedApiProvider = new Mock<IApiProvider>();
84+
TestHost = "https://www.ashleypoole.co.uk";
85+
var webResponseModel = new WebResponseModel()
86+
{
87+
Payloay = " {\"host\":\"www.ashleypoole.co.uk\",\"port\":443,\"protocol\":\"HTTP\",\"isPublic\":false,\"" +
88+
"status\":\"IN_PROGRESS\",\"startTime\":1422479488403,\"engineVersion\":\"1.12.8\",\"criteriaVersion\":\"2009i\"" +
89+
",\"endpoints\":[{\"ipAddress\":\"104.28.6.2\",\"statusMessage\":\"In progress\",\"statusDetails\":\"TESTING_HTTPS\"" +
90+
",\"statusDetailsMessage\":\"Sending one complete HTTPS request\",\"progress\":-1,\"eta\":-1,\"delegation\":3}," +
91+
"{\"ipAddress\":\"104.28.7.2\",\"statusMessage\":\"Pending\",\"progress\":-1,\"eta\":-1,\"delegation\":3}]}",
92+
StatusCode = 200,
93+
StatusDescription = "Ok",
94+
Url = ("https://api.dev.ssllabs.com/api/fa78d5a4/analyze?host=" + TestHost)
95+
};
96+
97+
mockedApiProvider.Setup(x => x.MakeGetRequest(It.IsAny<RequestModel>())).Returns(webResponseModel);
98+
99+
var ssllService = new SSLLService("https://api.dev.ssllabs.com/api/fa78d5a4/", mockedApiProvider.Object);
100+
Response = ssllService.Analyze(TestHost, SSLLService.Publish.On, SSLLService.ClearCache.On,
101+
SSLLService.FromCache.Ignore, SSLLService.All.Done);
102+
}
103+
104+
[TestMethod]
105+
public void then_the_scan_results_should_be_public()
106+
{
107+
Response.isPublic.Should().BeTrue();
108+
}
109+
}
110+
111+
public abstract class PositiveTests : GenericPositiveTests<Analyze>
112+
{
113+
public static string TestHost;
114+
115+
[TestMethod]
116+
public void then_the_host_property_should_match_the_requested_hostname()
117+
{
118+
Response.host.Should().Be(TestHost);
39119
}
40120

41121
[TestMethod]
42122
public void then_the_header_status_code_should_be_200()
43123
{
44-
AnalyzeResponse.Header.statusCode.Should().Be(200);
124+
Response.Header.statusCode.Should().Be(200);
125+
}
126+
127+
[TestMethod]
128+
public void then_the_port_should_be_that_of_a_ssl_connection()
129+
{
130+
Response.port.Should().Be(443);
45131
}
46132
}
133+
134+
public abstract class NegativeTests : GenericNegativeTests<Analyze>
135+
{
136+
}
47137
}

SSLLWrapper.Tests/SSLLWrapper.Tests.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@
6767
</Otherwise>
6868
</Choose>
6969
<ItemGroup>
70-
<Compile Include="AnalyzeSharedTests\PositiveTests.cs" />
71-
<Compile Include="AnalyzeSharedTests\NegativeTests.cs" />
7270
<Compile Include="AnalyzeTests.cs" />
7371
<Compile Include="GenericPositiveTests.cs" />
7472
<Compile Include="GenericNegativeTests.cs" />

0 commit comments

Comments
 (0)