40
40
import static org .junit .jupiter .api .Assertions .assertFalse ;
41
41
import static org .junit .jupiter .api .Assertions .assertNotNull ;
42
42
import static org .junit .jupiter .api .Assertions .assertNotSame ;
43
+ import static org .junit .jupiter .api .Assertions .assertNull ;
43
44
import static org .junit .jupiter .api .Assertions .assertTrue ;
44
45
45
46
/**
@@ -183,8 +184,6 @@ public void doTest(RenewalVerifier verifier) throws Exception
183
184
String contextPath = "" ;
184
185
String servletMapping = "/server" ;
185
186
WebAppContext context = _server .addWebAppContext ("." , contextPath );
186
- TestHttpChannelCompleteListener scopeListener = new TestHttpChannelCompleteListener ();
187
- _server .getServerConnector ().addBean (scopeListener );
188
187
context .setParentLoaderPriority (true );
189
188
context .addServlet (TestServlet .class , servletMapping );
190
189
TestHttpSessionIdListener testListener = new TestHttpSessionIdListener ();
@@ -199,33 +198,29 @@ public void doTest(RenewalVerifier verifier) throws Exception
199
198
client .start ();
200
199
201
200
//make a request to create a session
202
- CountDownLatch synchronizer = new CountDownLatch (1 );
203
- scopeListener .setExitSynchronizer (synchronizer );
204
201
ContentResponse response = client .GET ("http://localhost:" + port + contextPath + servletMapping + "?action=create" );
205
202
assertEquals (HttpServletResponse .SC_OK , response .getStatus ());
206
-
207
- //ensure request has finished being handled
208
- synchronizer .await (5 , TimeUnit .SECONDS );
209
203
210
204
String sessionCookie = response .getHeaders ().get ("Set-Cookie" );
211
205
assertTrue (sessionCookie != null );
212
206
assertFalse (testListener .isCalled ());
213
207
214
208
//make a request to change the sessionid
215
- synchronizer = new CountDownLatch (1 );
216
- scopeListener .setExitSynchronizer (synchronizer );
217
209
Request request = client .newRequest ("http://localhost:" + port + contextPath + servletMapping + "?action=renew" );
218
210
ContentResponse renewResponse = request .send ();
219
211
assertEquals (HttpServletResponse .SC_OK , renewResponse .getStatus ());
220
-
221
- //ensure request has finished being handled
222
- synchronizer .await (5 , TimeUnit .SECONDS );
223
212
224
213
String renewSessionCookie = renewResponse .getHeaders ().get ("Set-Cookie" );
225
214
assertNotNull (renewSessionCookie );
226
215
assertNotSame (sessionCookie , renewSessionCookie );
227
216
assertTrue (testListener .isCalled ());
228
217
218
+ //make another request and check the cookie isn't set again
219
+ request = client .newRequest ("http://localhost:" + port + contextPath + servletMapping + "?action=check" );
220
+ ContentResponse checkResponse = request .send ();
221
+ assertEquals (HttpServletResponse .SC_OK , checkResponse .getStatus ());
222
+ assertNull (checkResponse .getHeaders ().get ("Set-Cookie" ));
223
+
229
224
if (verifier != null )
230
225
verifier .verify (context , TestServer .extractSessionId (sessionCookie ), TestServer .extractSessionId (renewSessionCookie ));
231
226
}
@@ -315,10 +310,10 @@ else if ("renew".equals(action))
315
310
316
311
assertTrue (sessionIdManager .isIdInUse (afterSessionId )); //new session id should be in use
317
312
assertFalse (sessionIdManager .isIdInUse (beforeSessionId ));
318
-
319
-
320
- if ((( Session ) afterSession ). isIdChanged ())
321
- (( org . eclipse . jetty . server . Response ) response ). replaceCookie ( sessionManager . getSessionCookie ( afterSession , request .getContextPath (), request . isSecure ()) );
313
+ }
314
+ else
315
+ {
316
+ request .getSession ( false );
322
317
}
323
318
}
324
319
}
0 commit comments