1
1
'use strict' ;
2
2
3
- require ( 'should-http' ) ;
4
-
5
3
const express = require ( '../support/express' ) ;
6
4
7
5
const app = express ( ) ;
8
6
const request = require ( '../support/client' ) ;
9
7
const assert = require ( 'assert' ) ;
10
- const should = require ( 'should' ) ;
11
8
const cookieParser = require ( 'cookie-parser' ) ;
12
9
const cookiejar = require ( 'cookiejar' ) ;
13
10
const session = require ( 'express-session' ) ;
@@ -90,38 +87,38 @@ describe('request', () => {
90
87
91
88
it ( 'should gain a session on POST' , ( ) =>
92
89
agent3 . post ( `${ base } /signin` ) . then ( ( res ) => {
93
- res . should . have . status ( 200 ) ;
94
- should . not . exist ( res . headers [ 'set-cookie' ] ) ;
95
- res . text . should . containEql ( 'dashboard' ) ;
90
+ assert . equal ( res . status , 200 ) ;
91
+ assert . ok ( 'set-cookie' in res . headers === false ) ;
92
+ assert . equal ( res . text , 'dashboard' ) ;
96
93
} ) ) ;
97
94
98
95
it ( 'should start with empty session (set cookies)' , ( done ) => {
99
96
agent1 . get ( `${ base } /dashboard` ) . end ( ( error , res ) => {
100
- should . exist ( error ) ;
101
- res . should . have . status ( 401 ) ;
102
- should . exist ( res . headers [ 'set-cookie' ] ) ;
97
+ assert . ok ( error instanceof Error ) ;
98
+ assert . equal ( res . status , 401 ) ;
99
+ assert . ok ( 'set-cookie' in res . headers ) ;
103
100
done ( ) ;
104
101
} ) ;
105
102
} ) ;
106
103
107
104
it ( 'should gain a session (cookies already set)' , ( ) =>
108
105
agent1 . post ( `${ base } /signin` ) . then ( ( res ) => {
109
- res . should . have . status ( 200 ) ;
110
- should . not . exist ( res . headers [ 'set-cookie' ] ) ;
111
- res . text . should . containEql ( 'dashboard' ) ;
106
+ assert . equal ( res . status , 200 ) ;
107
+ assert . ok ( 'set-cookie' in res . headers === false ) ;
108
+ assert . equal ( 'dashboard' , res . text ) ;
112
109
} ) ) ;
113
110
114
111
it ( 'should persist cookies across requests' , ( ) =>
115
112
agent1 . get ( `${ base } /dashboard` ) . then ( ( res ) => {
116
- res . should . have . status ( 200 ) ;
113
+ assert . equal ( res . status , 200 ) ;
117
114
} ) ) ;
118
115
119
116
it ( 'should have the cookie set in the end callback' , ( ) =>
120
117
agent4
121
118
. post ( `${ base } /setcookie` )
122
119
. then ( ( ) => agent4 . get ( `${ base } /getcookie` ) )
123
120
. then ( ( res ) => {
124
- res . should . have . status ( 200 ) ;
121
+ assert . equal ( res . status , 200 ) ;
125
122
assert . strictEqual ( res . text , 'jar' ) ;
126
123
} ) ) ;
127
124
@@ -147,62 +144,62 @@ describe('request', () => {
147
144
it ( 'should send cookies to allowed domain with a different path' , ( ) => {
148
145
const postRequest = agent4 . post ( `${ base } /x/y/z` )
149
146
const cookiesNames = postRequest . cookies . split ( ';' ) . map ( cookie => cookie . split ( '=' ) [ 0 ] )
150
- cookiesNames . should . eql ( [ 'cookie' , ' connect.sid' ] ) ;
147
+ assert . deepStrictEqual ( cookiesNames , [ 'cookie' , ' connect.sid' ] ) ;
151
148
} ) ;
152
149
153
150
it ( 'should not share cookies' , ( done ) => {
154
151
agent2 . get ( `${ base } /dashboard` ) . end ( ( error , res ) => {
155
- should . exist ( error ) ;
156
- res . should . have . status ( 401 ) ;
152
+ assert . ok ( error instanceof Error ) ;
153
+ assert . equal ( res . status , 401 ) ;
157
154
done ( ) ;
158
155
} ) ;
159
156
} ) ;
160
157
161
158
it ( 'should not lose cookies between agents' , ( ) =>
162
159
agent1 . get ( `${ base } /dashboard` ) . then ( ( res ) => {
163
- res . should . have . status ( 200 ) ;
160
+ assert . equal ( res . status , 200 ) ;
164
161
} ) ) ;
165
162
166
163
it ( 'should be able to follow redirects' , ( ) =>
167
164
agent1 . get ( base ) . then ( ( res ) => {
168
- res . should . have . status ( 200 ) ;
169
- res . text . should . containEql ( 'dashboard' ) ;
165
+ assert . equal ( res . status , 200 ) ;
166
+ assert . equal ( res . text , 'dashboard' ) ;
170
167
} ) ) ;
171
168
172
169
it ( 'should be able to post redirects' , ( ) =>
173
170
agent1
174
171
. post ( `${ base } /redirect` )
175
172
. send ( { foo : 'bar' , baz : 'blaaah' } )
176
173
. then ( ( res ) => {
177
- res . should . have . status ( 200 ) ;
178
- res . text . should . containEql ( 'simple' ) ;
179
- res . redirects . should . eql ( [ `${ base } /simple` ] ) ;
174
+ assert . equal ( res . status , 200 ) ;
175
+ assert . equal ( res . text , 'simple' ) ;
176
+ assert . deepStrictEqual ( res . redirects , [ `${ base } /simple` ] ) ;
180
177
} ) ) ;
181
178
182
179
it ( 'should be able to limit redirects' , ( done ) => {
183
180
agent1
184
181
. get ( base )
185
182
. redirects ( 0 )
186
183
. end ( ( error , res ) => {
187
- should . exist ( error ) ;
188
- res . should . have . status ( 302 ) ;
189
- res . redirects . should . eql ( [ ] ) ;
190
- res . header . location . should . equal ( '/dashboard' ) ;
184
+ assert . ok ( error instanceof Error ) ;
185
+ assert . equal ( res . status , 302 ) ;
186
+ assert . deepEqual ( res . redirects , [ ] ) ;
187
+ assert . equal ( res . header . location , '/dashboard' ) ;
191
188
done ( ) ;
192
189
} ) ;
193
190
} ) ;
194
191
195
192
it ( 'should be able to create a new session (clear cookie)' , ( ) =>
196
193
agent1 . post ( `${ base } /signout` ) . then ( ( res ) => {
197
- res . should . have . status ( 200 ) ;
198
- should . exist ( res . headers [ 'set-cookie' ] ) ;
194
+ assert . equal ( res . status , 200 ) ;
195
+ assert . ok ( 'set-cookie' in res . headers ) ;
199
196
} ) ) ;
200
197
201
198
it ( 'should regenerate with an empty session' , ( done ) => {
202
199
agent1 . get ( `${ base } /dashboard` ) . end ( ( error , res ) => {
203
- should . exist ( error ) ;
204
- res . should . have . status ( 401 ) ;
205
- should . not . exist ( res . headers [ 'set-cookie' ] ) ;
200
+ assert . ok ( error instanceof Error ) ;
201
+ assert . equal ( res . status , 401 ) ;
202
+ assert . ok ( 'set-cookie' in res . headers === false ) ;
206
203
done ( ) ;
207
204
} ) ;
208
205
} ) ;
0 commit comments