27
27
import static org .mockito .Mockito .any ;
28
28
29
29
import java .io .IOException ;
30
+ import java .util .List ;
30
31
import java .util .Map ;
31
32
import org .apache .commons .httpclient .URI ;
32
33
import org .apache .commons .httpclient .URIException ;
33
34
import org .junit .jupiter .api .Test ;
34
35
import org .junit .jupiter .params .ParameterizedTest ;
36
+ import org .junit .jupiter .params .provider .CsvSource ;
35
37
import org .junit .jupiter .params .provider .ValueSource ;
38
+ import org .parosproxy .paros .core .scanner .Alert ;
36
39
import org .parosproxy .paros .network .HttpHeader ;
37
40
import org .parosproxy .paros .network .HttpMalformedHeaderException ;
38
41
import org .parosproxy .paros .network .HttpMessage ;
39
42
import org .parosproxy .paros .network .HttpRequestHeader ;
40
43
import org .zaproxy .addon .commonlib .CommonAlertTag ;
44
+ import org .zaproxy .addon .commonlib .http .HttpFieldsNames ;
41
45
import org .zaproxy .addon .retire .model .Repo ;
42
46
43
47
class RetireScanRuleUnitTest extends PassiveScannerTest <RetireScanRule > {
@@ -66,34 +70,22 @@ void shouldIgnoreNon200OkMessages() {
66
70
assertEquals (0 , alertsRaised .size ());
67
71
}
68
72
69
- @ Test
70
- void shouldIgnoreCssUrl () {
71
- // Given
72
- HttpMessage msg = createMessage ("https://www.example.com/assets/styles.css" , null );
73
- given (passiveScanData .isPage200 (any ())).willReturn (true );
74
- // When
75
- scanHttpResponseReceive (msg );
76
- // Then
77
- assertEquals (0 , alertsRaised .size ());
78
- }
79
-
80
- @ Test
81
- void shouldIgnoreCssResponse () {
82
- // Given
83
- HttpMessage msg = createMessage ("https://www.example.com/assets/styles.scss" , null );
84
- msg .getResponseHeader ().addHeader (HttpHeader .CONTENT_TYPE , "text/css" );
85
- given (passiveScanData .isPage200 (any ())).willReturn (true );
86
- // When
87
- scanHttpResponseReceive (msg );
88
- // Then
89
- assertEquals (0 , alertsRaised .size ());
90
- }
91
-
92
- @ Test
93
- void shouldIgnoreImageResponse () {
73
+ @ ParameterizedTest
74
+ @ CsvSource ({
75
+ "text/css, style.css" ,
76
+ "text/css, style.scss" ,
77
+ "'', style.css" ,
78
+ "text/css, ''" ,
79
+ "text/css, styles" ,
80
+ "video/mp4, foo.mp4" ,
81
+ "image/gif, ''" ,
82
+ "image/gif, foo.gif" ,
83
+ "'', image/gif"
84
+ })
85
+ void shouldIgnoreIrrelevantResponseContentTypes (String contentType , String file ) {
94
86
// Given
95
- HttpMessage msg = createMessage ("https://www.example.com/assets/image.gif" , null );
96
- msg .getResponseHeader ().addHeader (HttpHeader .CONTENT_TYPE , "image/gif" );
87
+ HttpMessage msg = createMessage ("https://www.example.com/assets/" + file , null );
88
+ msg .getResponseHeader ().setHeader (HttpHeader .CONTENT_TYPE , contentType );
97
89
given (passiveScanData .isPage200 (any ())).willReturn (true );
98
90
// When
99
91
scanHttpResponseReceive (msg );
@@ -106,6 +98,7 @@ void shouldRaiseAlertOnVulnerableUrl() {
106
98
// Given
107
99
HttpMessage msg =
108
100
createMessage ("http://example.com/ajax/libs/angularjs/1.2.19/angular.min.js" , null );
101
+ msg .getResponseHeader ().setHeader (HttpFieldsNames .CONTENT_TYPE , "text/javascript" );
109
102
given (passiveScanData .isPage200 (any ())).willReturn (true );
110
103
// When
111
104
scanHttpResponseReceive (msg );
@@ -122,6 +115,7 @@ void shouldRaiseAlertOnVulnerableUrl() {
122
115
void shouldRaiseAlertOnVulnerableFilename (String fileName ) {
123
116
// Given
124
117
HttpMessage msg = createMessage ("http://example.com/CommonElements/js/" + fileName , null );
118
+ msg .getResponseHeader ().setHeader (HttpFieldsNames .CONTENT_TYPE , "text/javascript" );
125
119
given (passiveScanData .isPage200 (any ())).willReturn (true );
126
120
// When
127
121
scanHttpResponseReceive (msg );
@@ -143,6 +137,7 @@ void shouldRaiseAlertOnVulnerableContent() {
143
137
+ " * Licensed under the MIT license\n "
144
138
+ " */" ;
145
139
HttpMessage msg = createMessage ("http://example.com/angular.min.js" , content );
140
+ msg .getResponseHeader ().setHeader (HttpFieldsNames .CONTENT_TYPE , "text/javascript" );
146
141
given (passiveScanData .isPage200 (any ())).willReturn (true );
147
142
// When
148
143
scanHttpResponseReceive (msg );
@@ -166,6 +161,7 @@ void shouldRaiseAlertOnHashOfVulnerableContent() {
166
161
+ " * Licensed under the MIT license\n "
167
162
+ " */" ;
168
163
HttpMessage msg = createMessage ("http://example.com/hash.js" , content );
164
+ msg .getResponseHeader ().setHeader (HttpFieldsNames .CONTENT_TYPE , "text/javascript" );
169
165
given (passiveScanData .isPage200 (any ())).willReturn (true );
170
166
// When
171
167
scanHttpResponseReceive (msg );
@@ -212,6 +208,20 @@ void shouldReturnExpectedMappings() {
212
208
is (equalTo (CommonAlertTag .OWASP_2017_A09_VULN_COMP .getValue ())));
213
209
}
214
210
211
+ @ Test
212
+ void shouldHaveExpectedExampleAlert () {
213
+ // Given / When
214
+ List <Alert > alerts = rule .getExampleAlerts ();
215
+ // Then
216
+ assertThat (alerts .size (), is (equalTo (1 )));
217
+ }
218
+
219
+ @ Test
220
+ @ Override
221
+ public void shouldHaveValidReferences () {
222
+ super .shouldHaveValidReferences ();
223
+ }
224
+
215
225
private HttpMessage createMessage (String url , String body ) {
216
226
HttpMessage msg = new HttpMessage ();
217
227
if (url == null ) {
@@ -233,6 +243,7 @@ private HttpMessage createMessage(String url, String body) {
233
243
} catch (HttpMalformedHeaderException e ) {
234
244
// Nothing to do
235
245
}
246
+ msg .getResponseHeader ().setHeader (HttpFieldsNames .CONTENT_TYPE , "text/html" );
236
247
msg .setResponseBody (body );
237
248
238
249
return msg ;
0 commit comments