[Httpunit-commit] CVS: httpunit/test/com/meterware/servletunit HttpServletRequestTest.java,1.21,1.22
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2004-03-15 02:51:19
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22771/test/com/meterware/servletunit Modified Files: HttpServletRequestTest.java Log Message: bug #872129: Cookie header set on a web request was ignored in servletunit Index: HttpServletRequestTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- HttpServletRequestTest.java 14 Mar 2004 22:59:49 -0000 1.21 +++ HttpServletRequestTest.java 15 Mar 2004 02:42:16 -0000 1.22 @@ -236,10 +236,10 @@ } - public void testSetCookies() throws Exception { + public void testSetCookieViaRequestHeader() throws Exception { WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); + wr.setHeaderField( "Cookie", "flavor=vanilla"); ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); - request.addCookie( new Cookie( "flavor", "vanilla" ) ); Cookie[] cookies = request.getCookies(); assertNotNull( "No cookies found", cookies ); @@ -273,13 +273,14 @@ * will cause a session to be made available. */ public void testRetrieveSession() throws Exception { - WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); ServletUnitContext context = new ServletUnitContext(); - - ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY ); final ServletUnitHttpSession session = context.newSession(); final String sessionID = session.getId(); - request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, sessionID ) ); + + WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); + wr.setHeaderField( "Cookie", ServletUnitHttpSession.SESSION_COOKIE_NAME + '=' + sessionID); + + ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY ); assertEquals( "Requested session ID defined in request", sessionID, request.getRequestedSessionId() ); assertSame( "Session returned when creation not requested", session, request.getSession( /* create */ false ) ); @@ -318,14 +319,14 @@ * Obtains a new session, invalidates it, and verifies that */ public void testSessionInvalidation() throws Exception { - WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); ServletUnitContext context = new ServletUnitContext(); - HttpSession originalSession = context.newSession(); String originalID = originalSession.getId(); + WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); + wr.setHeaderField( "Cookie", ServletUnitHttpSession.SESSION_COOKIE_NAME + '=' + originalID); + ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY ); - request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, originalID ) ); originalSession.setAttribute( "Initial", new Integer( 1 ) ); Enumeration attributeNames = originalSession.getAttributeNames(); assertTrue( attributeNames.hasMoreElements() ); @@ -347,18 +348,18 @@ * Verifies that a request with a bad session ID causes a new session to be generated only when explicitly requested. */ public void testGetSessionWithBadCookie() throws Exception { - WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); ServletUnitContext context = new ServletUnitContext(); - ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY ); - HttpSession originalSession = context.newSession(); String originalID = originalSession.getId(); - request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, originalID ) ); + + WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); + wr.setHeaderField( "Cookie", ServletUnitHttpSession.SESSION_COOKIE_NAME + '=' + originalID); + + ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY ); request.getSession(); - String badID = originalID + "BAD"; + wr.setHeaderField( "Cookie", ServletUnitHttpSession.SESSION_COOKIE_NAME + '=' + (originalID + "BAD")); request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY ); - request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, badID ) ); assertNull( "Unexpected session returned for bad cookie", request.getSession( false ) ); assertNotNull( "Should have returned session when asked", request.getSession( true )); |