-
Notifications
You must be signed in to change notification settings - Fork 78
/
HttpSessionxTests.java
336 lines (303 loc) · 12.1 KB
/
HttpSessionxTests.java
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/*
* Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
/*
* $Id: URLClient.java 52425 2007-01-18 19:31:04Z djiao $
*/
/**
* Tests that focus on cross-context
*/
package servlet.tck.api.jakarta_servlet_http.httpsessionx;
import servlet.tck.common.client.AbstractUrlClient;
import servlet.tck.common.servlets.CommonServlets;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class HttpSessionxTests extends AbstractUrlClient {
@BeforeEach
public void setupServletName() throws Exception {
setServletName("TestServlet");
}
/**
* Deployment for the test
*/
@Deployment(testable = false)
public static WebArchive getTestArchive() throws Exception {
return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsessionx_web.war")
.addAsLibraries(CommonServlets.getCommonServletsArchive())
.addClasses(TestServlet.class)
.setWebXML(HttpSessionxTests.class.getResource("servlet_jsh_httpsessionx_web.xml"));
}
@Deployment(testable = false, name = "servlet_jsh_httpsession2x_web")
public static WebArchive getTestArchive2() throws Exception {
return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsessionx2_web.war")
.addAsLibraries(CommonServlets.getCommonServletsArchive())
.addClasses(ExpireHttpSession.class, GetNewSession.class,
InvalidateHttpSession.class, SetMaxInterval.class)
.setWebXML(HttpSessionxTests.class.getResource("servlet_jsh_httpsessionx2_web.xml"));
}
/*
* @class.setup_props: webServerHost; webServerPort; ts_home;
*/
/*
* @testName: getMaxInactiveIntervalTest
*
* @assertion_ids: Servlet:JAVADOC:473; Servlet:JAVADOC:474; Servlet:SPEC:202;
* Servlet:SPEC:66; Servlet:JAVADOC:565; Servlet:JAVADOC:566;
*
* @test_Strategy: 1. Client sends request to TestServlet which - create a new
* HttpSession using request.getSession(true); - set the session's
* maxInactiveInterval to 10 secs. Client captures the JSESSIONID returned in
* the response. 2. Within maxInactiveInterval, client sends a request that
* contains the JSESSIONID in a request cookie to the servlet again, verify
* that MaxInactiveInterval is set correctly
*/
@Test
public void getMaxInactiveIntervalTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getNewSession");
TEST_PROPS.setProperty(SAVE_STATE, "true");
invoke();
TEST_PROPS.setProperty(APITEST, "setMaxInactiveIntervalTest");
TEST_PROPS.setProperty(SAVE_STATE, "true");
TEST_PROPS.setProperty(USE_SAVED_STATE, "true");
invoke();
TEST_PROPS.setProperty(APITEST, "getMaxInactiveIntervalTest");
TEST_PROPS.setProperty(USE_SAVED_STATE, "true");
invoke();
}
/*
* @testName: expireHttpSessionTest
*
* @assertion_ids: Servlet:JAVADOC:473; Servlet:JAVADOC:474; Servlet:SPEC:202;
* Servlet:SPEC:66; Servlet:JAVADOC:565; Servlet:JAVADOC:566;
*
* @test_Strategy: 1. Client sends request to TestServlet which - creates a
* session using request.getSession() - and sets the session's
* maxInactiveInterval to 10 secs. Client captures the JSESSIONID returned in
* the response.
*
* 2. Client waits for longer than maxInactiveInterval, and sends a
* request(including JSESSIONID) to the servlet. The servlet tries to resume
* the session by calling request.getSession(false). Verify that no session is
* returned this time
*/
@Test
public void expireHttpSessionTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getNewSession");
TEST_PROPS.setProperty(SAVE_STATE, "true");
invoke();
TEST_PROPS.setProperty(APITEST, "setMaxInactiveIntervalTest");
TEST_PROPS.setProperty(SAVE_STATE, "true");
TEST_PROPS.setProperty(USE_SAVED_STATE, "true");
invoke();
try {
Thread.sleep(11000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
TEST_PROPS.setProperty(APITEST, "expireHttpSessionTest");
TEST_PROPS.setProperty(USE_SAVED_STATE, "true");
invoke();
}
/*
* @testName: expireHttpSessionxTest
*
* @assertion_ids: Servlet:JAVADOC:473; Servlet:JAVADOC:474; Servlet:SPEC:202;
* Servlet:SPEC:66; Servlet:JAVADOC:565; Servlet:JAVADOC:566;
*
* @test_Strategy: 1. Client sends request to TestServlet which - creates a
* session using request.getSession() - and sets the session's
* maxInactiveInterval to 10 secs. Client captures the JSESSIONID returned in
* the response.
*
* 2. Client waits for longer than maxInactiveInterval, sends a request with
* JSESSIONID to a servlet with different context. The servlet tries to resume
* the session by calling request.getSession(false). Verify that no session is
* returned this time
*/
@Test
public void expireHttpSessionxTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getNewSession");
TEST_PROPS.setProperty(SAVE_STATE, "true");
invoke();
TEST_PROPS.setProperty(APITEST, "setMaxInactiveIntervalTest");
TEST_PROPS.setProperty(SAVE_STATE, "true");
TEST_PROPS.setProperty(USE_SAVED_STATE, "true");
invoke();
try {
Thread.sleep(11000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
TEST_PROPS.setProperty(REQUEST, "GET " + "/servlet_jsh_httpsessionx2_web"
+ "/expireHttpSession" + " HTTP/1.1");
TEST_PROPS.setProperty(USE_SAVED_STATE, "true");
TEST_PROPS.setProperty(SEARCH_STRING, "Session expired as expected.");
invoke();
}
/*
* @testName: expireHttpSessionxriTest
*
* @assertion_ids: Servlet:JAVADOC:473; Servlet:JAVADOC:474; Servlet:SPEC:202;
* Servlet:SPEC:66; Servlet:JAVADOC:565; Servlet:JAVADOC:566;
*
* @test_Strategy: 1. Client sends request to TestServlet which - creates a
* session using request.getSession() - and sets the session's
* maxInactiveInterval to 10 secs. Client captures the JSESSIONID returned in
* the response.
*
* 2. Client waits for longer than maxInactiveInterval, sends a request with
* JSESSIONID to the servlet. The servlet send request to second servlet using
* RequestDispatcher. Then the second servlet tries to resume the session by
* calling request.getSession(false). Verify that no session is returned this
* time
*/
@Test
public void expireHttpSessionxriTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getNewSession");
TEST_PROPS.setProperty(SAVE_STATE, "true");
invoke();
TEST_PROPS.setProperty(APITEST, "setMaxInactiveIntervalTest");
TEST_PROPS.setProperty(SAVE_STATE, "true");
TEST_PROPS.setProperty(USE_SAVED_STATE, "true");
invoke();
try {
Thread.sleep(11000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
TEST_PROPS.setProperty(APITEST, "expireHttpSessionxriTest");
TEST_PROPS.setProperty(USE_SAVED_STATE, "true");
invoke();
}
/*
* @testName: expireHttpSessionxri1Test
*
* @assertion_ids: Servlet:JAVADOC:473; Servlet:JAVADOC:474; Servlet:SPEC:202;
* Servlet:SPEC:66; Servlet:JAVADOC:565; Servlet:JAVADOC:566;
*
* @test_Strategy: 1. Client sends request to TestServlet which The servlet
* send request to second servlet using RequestDispatcher.include.
*
* 2. The second servlet tries to - creates a session using
* request.getSession() - and sets the session's maxInactiveInterval to 10
* secs. Client captures the JSESSIONID returned in the response.
*
* 3. Client waits for longer than maxInactiveInterval, sends a request with
* JSESSIONID to the first servlet. Which again send request to second servlet
* using RequestDispatcher.
*
* 4. The second servlet tries to resume the session by calling
* request.getSession(false). Verify that no session is returned this time
*/
@Test
public void expireHttpSessionxri1Test() throws Exception {
TEST_PROPS.setProperty(APITEST, "setMaxInactiveIntervalxiTest");
TEST_PROPS.setProperty(SAVE_STATE, "true");
invoke();
try {
Thread.sleep(11000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
TEST_PROPS.setProperty(APITEST, "expireHttpSessionxriTest");
TEST_PROPS.setProperty(USE_SAVED_STATE, "true");
invoke();
}
/*
* @testName: expireHttpSessionxrfTest
*
* @assertion_ids: Servlet:JAVADOC:473; Servlet:JAVADOC:474; Servlet:SPEC:202;
* Servlet:SPEC:66; Servlet:JAVADOC:565; Servlet:JAVADOC:566;
*
* @test_Strategy: 1. Client sends request to TestServlet which The servlet
* send request to second servlet using RequestDispatcher.forward.
*
* 2. The second servlet tries to - creates a session using
* request.getSession() - and sets the session's maxInactiveInterval to 10
* secs. Client captures the JSESSIONID returned in the response.
*
* 3. Client waits for longer than maxInactiveInterval, sends a request with
* JSESSIONID to the first servlet. Which again send request to second servlet
* using RequestDispatcher.forward.
*
* 4. The second servlet tries to resume the session by calling
* request.getSession(false). Verify that no session is returned this time
*/
@Test
public void expireHttpSessionxrfTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "setMaxInactiveIntervalxfTest");
TEST_PROPS.setProperty(SAVE_STATE, "true");
invoke();
try {
Thread.sleep(11000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
TEST_PROPS.setProperty(APITEST, "expireHttpSessionxrfTest");
TEST_PROPS.setProperty(USE_SAVED_STATE, "true");
invoke();
}
/*
* @testName: invalidateHttpSessionTest
*
* @assertion_ids: Servlet:JAVADOC:566; Servlet:JAVADOC:565; Servlet:SPEC:202;
* Servlet:JAVADOC:496; Servlet:JAVADOC:568;
*
* @test_Strategy: 1. Client sends request to TestServlet which - creates a
* session using request.getSession(true) Client captures the JSESSIONID
* returned in the response.
*
* 2. Client sends a request(including JSESSIONID) to the servlet. The servlet
* tries to resume the session, then invalidate the session by calling
* Session.invalidate(). Verify that session is invalidated
*/
@Test
public void invalidateHttpSessionTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getNewSession");
TEST_PROPS.setProperty(SAVE_STATE, "true");
invoke();
TEST_PROPS.setProperty(APITEST, "invalidateSessionTest");
TEST_PROPS.setProperty(USE_SAVED_STATE, "true");
invoke();
}
/*
* @testName: invalidateHttpSessionxTest
*
* @assertion_ids: Servlet:JAVADOC:566; Servlet:JAVADOC:565; Servlet:SPEC:202;
* Servlet:JAVADOC:496; Servlet:JAVADOC:568;
*
* @test_Strategy: 1. Client sends request to TestServlet which - send request
* to a second servlet using RequestDispatcher - which creates a session using
* request.getSession(true) Client captures the JSESSIONID returned in the
* response.
*
* 2. Client sends a request with JSESSIONID to the first servlet. The first
* servlet invoke the second servlet using RequestDispatcher, The second
* servlet invalidate the session by calling Session.invalidate(). Verify that
* session is invalidated
*/
@Test
public void invalidateHttpSessionxTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getNewSessionx");
TEST_PROPS.setProperty(SAVE_STATE, "true");
invoke();
TEST_PROPS.setProperty(APITEST, "invalidateSessionxTest");
TEST_PROPS.setProperty(USE_SAVED_STATE, "true");
invoke();
}
}