1
- using System . IO ;
2
- using System . Net ;
3
- using FluentAssertions ;
1
+ using FluentAssertions ;
4
2
using Microsoft . VisualStudio . TestTools . UnitTesting ;
5
3
using Moq ;
6
4
using SSLLWrapper ;
7
5
using SSLLWrapper . Interfaces ;
8
6
using SSLLWrapper . Models ;
9
7
using SSLLWrapper . Models . Response ;
10
- using SSLLWrapper . Tests . AnalyzeSharedTests ;
8
+ using SSLLWrapper . Tests ;
11
9
12
10
namespace given_that_I_make_a_analyze_request
13
11
{
14
12
[ 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
16
14
{
17
15
[ ClassInitialize ]
18
16
public static void Setup ( TestContext testContext )
19
17
{
20
18
var mockedApiProvider = new Mock < IApiProvider > ( ) ;
21
- TestHost = "www.ashleypoole.co.uk" ;
19
+ TestHost = "https:// www.ashleypoole.co.uk" ;
22
20
var webResponseModel = new WebResponseModel ( )
23
21
{
24
22
Payloay = "{\" host\" :\" www.ashleypoole.co.uk\" ,\" port\" :443,\" protocol\" :\" HTTPS\" ,\" isPublic\" :true,\" status\" :\" READY\" ,\" " +
@@ -35,13 +33,105 @@ public static void Setup(TestContext testContext)
35
33
mockedApiProvider . Setup ( x => x . MakeGetRequest ( It . IsAny < RequestModel > ( ) ) ) . Returns ( webResponseModel ) ;
36
34
37
35
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 ) ;
39
119
}
40
120
41
121
[ TestMethod ]
42
122
public void then_the_header_status_code_should_be_200 ( )
43
123
{
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 ) ;
45
131
}
46
132
}
133
+
134
+ public abstract class NegativeTests : GenericNegativeTests < Analyze >
135
+ {
136
+ }
47
137
}
0 commit comments