4040import static org .junit .jupiter .api .Assertions .assertFalse ;
4141import static org .junit .jupiter .api .Assertions .assertNotNull ;
4242import static org .junit .jupiter .api .Assertions .assertNotSame ;
43+ import static org .junit .jupiter .api .Assertions .assertNull ;
4344import static org .junit .jupiter .api .Assertions .assertTrue ;
4445
4546/**
@@ -183,8 +184,6 @@ public void doTest(RenewalVerifier verifier) throws Exception
183184 String contextPath = "" ;
184185 String servletMapping = "/server" ;
185186 WebAppContext context = _server .addWebAppContext ("." , contextPath );
186- TestHttpChannelCompleteListener scopeListener = new TestHttpChannelCompleteListener ();
187- _server .getServerConnector ().addBean (scopeListener );
188187 context .setParentLoaderPriority (true );
189188 context .addServlet (TestServlet .class , servletMapping );
190189 TestHttpSessionIdListener testListener = new TestHttpSessionIdListener ();
@@ -199,33 +198,29 @@ public void doTest(RenewalVerifier verifier) throws Exception
199198 client .start ();
200199
201200 //make a request to create a session
202- CountDownLatch synchronizer = new CountDownLatch (1 );
203- scopeListener .setExitSynchronizer (synchronizer );
204201 ContentResponse response = client .GET ("http://localhost:" + port + contextPath + servletMapping + "?action=create" );
205202 assertEquals (HttpServletResponse .SC_OK , response .getStatus ());
206-
207- //ensure request has finished being handled
208- synchronizer .await (5 , TimeUnit .SECONDS );
209203
210204 String sessionCookie = response .getHeaders ().get ("Set-Cookie" );
211205 assertTrue (sessionCookie != null );
212206 assertFalse (testListener .isCalled ());
213207
214208 //make a request to change the sessionid
215- synchronizer = new CountDownLatch (1 );
216- scopeListener .setExitSynchronizer (synchronizer );
217209 Request request = client .newRequest ("http://localhost:" + port + contextPath + servletMapping + "?action=renew" );
218210 ContentResponse renewResponse = request .send ();
219211 assertEquals (HttpServletResponse .SC_OK , renewResponse .getStatus ());
220-
221- //ensure request has finished being handled
222- synchronizer .await (5 , TimeUnit .SECONDS );
223212
224213 String renewSessionCookie = renewResponse .getHeaders ().get ("Set-Cookie" );
225214 assertNotNull (renewSessionCookie );
226215 assertNotSame (sessionCookie , renewSessionCookie );
227216 assertTrue (testListener .isCalled ());
228217
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+
229224 if (verifier != null )
230225 verifier .verify (context , TestServer .extractSessionId (sessionCookie ), TestServer .extractSessionId (renewSessionCookie ));
231226 }
@@ -315,10 +310,10 @@ else if ("renew".equals(action))
315310
316311 assertTrue (sessionIdManager .isIdInUse (afterSessionId )); //new session id should be in use
317312 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 );
322317 }
323318 }
324319 }
0 commit comments