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