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