@@ -3,19 +3,18 @@ import { getHintPath } from 'hint/dist/src/lib/utils/hint-helpers';
3
3
import { HintTest } from '@hint/utils-tests-helpers/dist/src/hint-test-type' ;
4
4
import * as hintRunner from '@hint/utils-tests-helpers/dist/src/hint-runner' ;
5
5
6
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7
-
8
6
// Page data.
9
7
10
8
const pageWithAlternateStylesheet = generateHTMLPage ( '<link rel=" alternate stylesheet " href="test.css">' ) ;
11
9
const pageWithScript = generateHTMLPage ( undefined , '<script src="test.js"></script>' ) ;
10
+ const pageWithScriptAndStylesheet = generateHTMLPage ( '<link rel="stylesheet" href="test.css">' , '<script src="test.js"></script>' ) ;
12
11
const pageWithStylesheet = generateHTMLPage ( '<link rel="stylesheet" href="test.css">' ) ;
13
12
13
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14
+
14
15
// Error messages.
15
16
16
17
const noHeaderErrorMessage = `Response should include 'x-content-type-options' header.` ;
17
- const unneededHeaderErrorMessage = `Response should not include unneeded 'x-content-type-options' header.` ;
18
-
19
18
const generateInvalidValueMessage = ( value : string = '' ) => {
20
19
return `'x-content-type-options' header value should be 'nosniff', not '${ value } '.` ;
21
20
} ;
@@ -27,48 +26,60 @@ const generateInvalidValueMessage = (value: string = '') => {
27
26
const tests : HintTest [ ] = [
28
27
{
29
28
name : `HTML page is served without 'X-Content-Type-Options' header` ,
30
- serverConfig : { '/' : '' }
29
+ reports : [ { message : noHeaderErrorMessage } ] ,
30
+ serverConfig : {
31
+ '/' : { content : generateHTMLPage ( ) } ,
32
+ '/favicon.ico' : { headers : { 'X-Content-Type-Options' : 'nosniff' } }
33
+ }
31
34
} ,
32
35
{
33
- name : `Script is served without 'X-Content-Type-Options' header` ,
36
+ name : `Favicon is served without 'X-Content-Type-Options' header` ,
34
37
reports : [ { message : noHeaderErrorMessage } ] ,
35
38
serverConfig : {
36
- '/' : pageWithScript ,
37
- '/test.js ' : ''
39
+ '/' : { content : generateHTMLPage ( ) , headers : { 'Content-Type' : 'text/html' , 'X-Content-Type-Options' : 'nosniff' } } ,
40
+ '/favicon.ico ' : ''
38
41
}
39
42
} ,
40
43
{
41
44
name : `Stylesheet is served without 'X-Content-Type-Options' header` ,
42
45
reports : [ { message : noHeaderErrorMessage } ] ,
43
46
serverConfig : {
44
- '/' : pageWithStylesheet ,
47
+ '/' : { content : pageWithStylesheet , headers : { 'Content-Type' : 'text/html' , 'X-Content-Type-Options' : 'nosniff' } } ,
48
+ '/favicon.ico' : { headers : { 'X-Content-Type-Options' : 'nosniff' } } ,
45
49
'/test.css' : ''
46
50
}
47
51
} ,
48
52
{
49
53
name : `Alternate stylesheet is served without 'X-Content-Type-Options' header` ,
50
54
reports : [ { message : noHeaderErrorMessage } ] ,
51
55
serverConfig : {
52
- '/' : pageWithAlternateStylesheet ,
56
+ '/' : { content : pageWithAlternateStylesheet , headers : { 'Content-Type' : 'text/html' , 'X-Content-Type-Options' : 'nosniff' } } ,
57
+ '/favicon.ico' : { headers : { 'X-Content-Type-Options' : 'nosniff' } } ,
53
58
'/test.css' : ''
54
59
}
55
60
} ,
56
61
{
57
62
name : `Resource is specified as a data URI` ,
58
- serverConfig : { '/' : generateHTMLPage ( undefined , '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==">' ) }
59
- } ,
60
- {
61
- name : `HTML page is served with the 'X-Content-Type-Options' header` ,
62
- reports : [ { message : unneededHeaderErrorMessage } ] ,
63
- serverConfig : { '/' : { headers : { 'X-Content-Type-Options' : 'nosniff' } } }
63
+ serverConfig : {
64
+ '/' : {
65
+ content : generateHTMLPage ( undefined , '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==">' ) ,
66
+ headers : { 'X-Content-Type-Options' : 'nosniff' }
67
+ } ,
68
+ '/favicon.ico' : { headers : { 'X-Content-Type-Options' : 'nosniff' } }
69
+ }
64
70
} ,
65
71
{
66
72
name : `Script is served with 'X-Content-Type-Options' header with invalid value` ,
67
73
reports : [ { message : generateInvalidValueMessage ( 'invalid' ) } ] ,
68
74
serverConfig : {
69
- '/' : pageWithScript ,
75
+ '/' : { content : pageWithScript , headers : { 'Content-Type' : 'text/html' , 'X-Content-Type-Options' : 'nosniff' } } ,
76
+ '/favicon.ico' : { headers : { 'X-Content-Type-Options' : 'nosniff' } } ,
70
77
'/test.js' : { headers : { 'X-Content-Type-Options' : 'invalid' } }
71
78
}
79
+ } ,
80
+ {
81
+ name : `All resources are served with 'X-Content-Type-Options' header` ,
82
+ serverConfig : { '*' : { content : pageWithScriptAndStylesheet , headers : { 'Content-Type' : 'text/html' , 'X-Content-Type-Options' : 'nosniff' } } }
72
83
}
73
84
] ;
74
85
0 commit comments