forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_spec.ts
More file actions
149 lines (126 loc) · 3.25 KB
/
session_spec.ts
File metadata and controls
149 lines (126 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import systemTests from '../lib/system-tests'
import parser from 'cookie-parser'
import BodyParser from 'body-parser'
const it = systemTests.it
const onServer = function (app) {
app.use(parser())
app.get('*', (req, res, next) => {
res.cookie(req.path, 'value', {
sameSite: 'None',
secure: true,
})
next()
})
app.use(BodyParser.urlencoded())
app.get('/link', (req, res) => {
res.send('<html><h1>link</h1><a href=\'https://www.foo.com:44665/cross_origin\'>second</a></html>')
})
app.get('/status/:code', (req, res) => {
res.sendStatus(+req.params.code)
})
app.get('/cross_origin', (req, res) => {
res.send('<html><h1>cross origin</h1></html>')
})
app.get('/cross_origin_iframe/:name', (req, res) => {
res.send(`<html><body><h1>cross_origin_iframe ${req.params.name}</h1><iframe src="https://127.0.0.2:44665/set-localStorage/${req.params.name}"</body></html>`)
})
app.get('/set-localStorage/:name', (req, res) => {
res.send(`<html><body><h1>set-localStorage ${req.params.name}</h1><script>window.localStorage.clear(); window.localStorage.name = "${req.params.name}"</script></body></html>`)
})
app.get('/make-reqs', (req, res) => {
res.send(`<body><script>(function() {
fetch('/keep_open')
req = new XMLHttpRequest()
req.open('GET', '/keep_open')
req.send()
})()</script></body>`)
})
app.get('/form', (req, res) => {
res.send(`\
<html>
<h1>form</h1>
<form method='POST' action='/submit'>
<input name='delay' />
</form>
</html>\
`)
})
app.post('/submit', (req, res) => {
if (req.body.delay) {
return setTimeout(() => {
res.redirect('/home')
}, +req.body.delay)
}
res.redirect('/home')
})
app.get('/home', (req, res) => {
res.send('<html><h1>home</h1></html>')
})
app.get('/redirect', (req, res) => {
res.redirect('/home')
})
app.get('/keep_open', (req, res) => {
// dont respond
})
app.get('/javascript', (req, res) => {
res.send(`\
<html>
<script type='text/javascript'>
window.redirect = function(){
window.location.href = 'https://www.foo.com:44665/cross_origin'
}
</script>
<h1>javascript</h1>
<button onclick='redirect()'>click me</button>
</html>\
`)
})
app.get('/cors', (req, res) => {
res.send(`<script>
fetch('https://127.0.0.2:44665/cross_origin')
.then((res) => res.text())
.then(text => {
if (text.includes('cross origin')) document.write('success!')
})
.catch(err => document.write(err.message))
</script>`)
})
}
describe('e2e sessions', () => {
systemTests.setup({
servers: [{
port: 4466,
https: true,
onServer,
}, {
port: 44665,
https: true,
onServer,
}, {
port: 4465,
// https: true,
onServer,
}],
settings: {
hosts: {
'*.foo.com': '127.0.0.1',
},
},
})
it('session tests', {
spec: 'session_spec.js',
snapshot: true,
config: {
experimentalSessionSupport: true,
video: false,
},
})
it('sessions persist on reload, and clear between specs', {
spec: 'session_persist_spec_1.js,session_persist_spec_2.js',
snapshot: true,
config: {
experimentalSessionSupport: true,
video: false,
},
})
})