1 29 30 package org.apache.commons.httpclient.cookie; 31 32 import java.io.IOException ; 33 34 import junit.framework.Test; 35 import junit.framework.TestSuite; 36 37 import org.apache.commons.httpclient.Cookie; 38 import org.apache.commons.httpclient.Header; 39 import org.apache.commons.httpclient.HttpClientTestBase; 40 import org.apache.commons.httpclient.HttpStatus; 41 import org.apache.commons.httpclient.HttpVersion; 42 import org.apache.commons.httpclient.methods.GetMethod; 43 import org.apache.commons.httpclient.server.HttpService; 44 import org.apache.commons.httpclient.server.SimpleRequest; 45 import org.apache.commons.httpclient.server.SimpleResponse; 46 47 48 55 public class TestCookieIgnoreSpec extends HttpClientTestBase { 56 57 59 public TestCookieIgnoreSpec(final String testName) throws IOException { 60 super(testName); 61 } 62 63 65 public static Test suite() { 66 return new TestSuite(TestCookieIgnoreSpec.class); 67 } 68 69 private class BasicAuthService implements HttpService { 70 71 public BasicAuthService() { 72 super(); 73 } 74 75 public boolean process(final SimpleRequest request, final SimpleResponse response) 76 throws IOException 77 { 78 HttpVersion ver = request.getRequestLine().getHttpVersion(); 79 response.setStatusLine(ver, HttpStatus.SC_OK); 80 response.addHeader(new Header("Connection", "close")); 81 response.addHeader(new Header("Set-Cookie", 82 "custno = 12345; comment=test; version=1," + 83 " name=John; version=1; max-age=600; secure; domain=.apache.org")); 84 return true; 85 } 86 } 87 88 public void testIgnoreCookies() throws Exception { 89 this.server.setHttpService(new BasicAuthService()); 90 91 GetMethod httpget = new GetMethod("/"); 92 httpget.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES); 93 94 try { 95 this.client.executeMethod(httpget); 96 } finally { 97 httpget.releaseConnection(); 98 } 99 assertEquals("Cookie parsing should have been disabled", 100 0, this.client.getState().getCookies().length); 101 } 102 103 public void testKeepCloverHappy() throws Exception { 104 CookieSpec cookiespec = new IgnoreCookiesSpec(); 105 cookiespec.parseAttribute(null, null); 106 cookiespec.parse("host", 80, "/", false, (String )null); 107 cookiespec.parse("host", 80, "/", false, (Header)null); 108 cookiespec.validate("host", 80, "/", false, (Cookie)null); 109 cookiespec.match("host", 80, "/", false, (Cookie)null); 110 cookiespec.match("host", 80, "/", false, (Cookie [])null); 111 cookiespec.domainMatch(null, null); 112 cookiespec.pathMatch(null, null); 113 cookiespec.match("host", 80, "/", false, (Cookie [])null); 114 cookiespec.formatCookie(null); 115 cookiespec.formatCookies(null); 116 cookiespec.formatCookieHeader((Cookie)null); 117 cookiespec.formatCookieHeader((Cookie [])null); 118 } 119 } 120 121 | Popular Tags |