File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+
4
+ < head >
5
+ < meta charset ="UTF-8 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
7
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
8
+ < title > HTTPS Upgrade tests</ title >
9
+ </ head >
10
+
11
+
12
+ < body >
13
+
14
+ < script >
15
+ function sleep ( ms ) {
16
+ return new Promise ( resolve => setTimeout ( ( ) => resolve ( ) , ms ) ) ;
17
+ }
18
+
19
+ async function upgrade_test ( ) {
20
+ let urlParams = new URLSearchParams ( decodeURIComponent ( window . location . search ) ) ;
21
+ // Set HSTS
22
+ await fetch ( `https://${ location . host } /_hp/common/empty.html?pipe=header(strict-transport-security,max-age=60)|status(200)` , { mode : "no-cors" } ) . catch ( ( ) => reject ( new Error ( "Cleanup failed" ) ) )
23
+ // Sleep for `sleep` ms.
24
+ let = sleep_time = urlParams . get ( 'sleep' ) | 0 ;
25
+ await sleep ( sleep_time ) ;
26
+ // Request URL
27
+ r1 = await fetch ( `http://${ location . host } /_hp/common/empty.html` , { "method" : "GET" } ) ;
28
+ // Request URL again
29
+ r2 = await fetch ( `http://${ location . host } /_hp/common/empty.html` , { "method" : "GET" } ) ;
30
+ // Clean HSTS
31
+ await fetch ( `https://${ location . host } /_hp/common/empty.html?pipe=header(strict-transport-security,max-age=0)|status(200)` , { mode : "no-cors" } ) . catch ( ( ) => reject ( new Error ( "Cleanup failed" ) ) )
32
+ // Report results
33
+ alert ( `Sleep: ${ sleep_time } ms, R1 redirected: ${ r1 . redirected } , R2 redirected: ${ r2 . redirected } ` ) ;
34
+ }
35
+
36
+ if ( location . protocol == "http:" ) {
37
+ upgrade_test ( ) ;
38
+ } else {
39
+ // Due to mixed content blocking we cannot fetch http on https
40
+ // These tests only are meaningful if we visit the test site on http
41
+ alert ( "Only works from HTTP!" ) ;
42
+ }
43
+
44
+ </ script >
45
+ </ body >
46
+
47
+ </ html >
You can’t perform that action at this time.
0 commit comments