@@ -44,6 +44,33 @@ describe('hsts header missing analyzer', () => {
44
44
expect ( vulnerabilities [ 0 ] . hash ) . to . be . equals ( analyzer . _createHash ( 'HSTS_HEADER_MISSING:mocha' ) )
45
45
} , makeRequestWithXFordwardedProtoHeader )
46
46
47
+ testThatRequestHasVulnerability ( ( req , res ) => {
48
+ res . setHeader ( 'content-type' , 'text/html' )
49
+ res . setHeader ( 'Strict-Transport-Security' , 'max-age=-100' )
50
+ res . end ( '<html><body><h1>Test</h1></body></html>' )
51
+ } , HSTS_HEADER_MISSING , 1 , function ( vulnerabilities ) {
52
+ expect ( vulnerabilities [ 0 ] . evidence . value ) . to . be . equal ( 'max-age=-100' )
53
+ expect ( vulnerabilities [ 0 ] . hash ) . to . be . equals ( analyzer . _createHash ( 'HSTS_HEADER_MISSING:mocha' ) )
54
+ } , makeRequestWithXFordwardedProtoHeader )
55
+
56
+ testThatRequestHasVulnerability ( ( req , res ) => {
57
+ res . setHeader ( 'content-type' , 'text/html' )
58
+ res . setHeader ( 'Strict-Transport-Security' , 'max-age=-100; includeSubDomains' )
59
+ res . end ( '<html><body><h1>Test</h1></body></html>' )
60
+ } , HSTS_HEADER_MISSING , 1 , function ( vulnerabilities ) {
61
+ expect ( vulnerabilities [ 0 ] . evidence . value ) . to . be . equal ( 'max-age=-100; includeSubDomains' )
62
+ expect ( vulnerabilities [ 0 ] . hash ) . to . be . equals ( analyzer . _createHash ( 'HSTS_HEADER_MISSING:mocha' ) )
63
+ } , makeRequestWithXFordwardedProtoHeader )
64
+
65
+ testThatRequestHasVulnerability ( ( req , res ) => {
66
+ res . setHeader ( 'content-type' , 'text/html' )
67
+ res . setHeader ( 'Strict-Transport-Security' , 'invalid' )
68
+ res . end ( '<html><body><h1>Test</h1></body></html>' )
69
+ } , HSTS_HEADER_MISSING , 1 , function ( vulnerabilities ) {
70
+ expect ( vulnerabilities [ 0 ] . evidence . value ) . to . be . equal ( 'invalid' )
71
+ expect ( vulnerabilities [ 0 ] . hash ) . to . be . equals ( analyzer . _createHash ( 'HSTS_HEADER_MISSING:mocha' ) )
72
+ } , makeRequestWithXFordwardedProtoHeader )
73
+
47
74
testThatRequestHasNoVulnerability ( ( req , res ) => {
48
75
res . setHeader ( 'content-type' , 'application/json' )
49
76
res . end ( '{"key": "test}' )
@@ -54,5 +81,23 @@ describe('hsts header missing analyzer', () => {
54
81
res . setHeader ( 'Strict-Transport-Security' , 'max-age=100' )
55
82
res . end ( '{"key": "test}' )
56
83
} , HSTS_HEADER_MISSING , makeRequestWithXFordwardedProtoHeader )
84
+
85
+ testThatRequestHasNoVulnerability ( ( req , res ) => {
86
+ res . setHeader ( 'content-type' , 'text/html' )
87
+ res . setHeader ( 'Strict-Transport-Security' , ' max-age=100 ' )
88
+ res . end ( '{"key": "test}' )
89
+ } , HSTS_HEADER_MISSING , makeRequestWithXFordwardedProtoHeader )
90
+
91
+ testThatRequestHasNoVulnerability ( ( req , res ) => {
92
+ res . setHeader ( 'content-type' , 'text/html' )
93
+ res . setHeader ( 'Strict-Transport-Security' , 'max-age=100;includeSubDomains' )
94
+ res . end ( '{"key": "test}' )
95
+ } , HSTS_HEADER_MISSING , makeRequestWithXFordwardedProtoHeader )
96
+
97
+ testThatRequestHasNoVulnerability ( ( req , res ) => {
98
+ res . setHeader ( 'content-type' , 'text/html' )
99
+ res . setHeader ( 'Strict-Transport-Security' , 'max-age=100 ;includeSubDomains' )
100
+ res . end ( '{"key": "test}' )
101
+ } , HSTS_HEADER_MISSING , makeRequestWithXFordwardedProtoHeader )
57
102
} )
58
103
} )
0 commit comments