001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestMemoryLogout.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.authentication.elements;
009:
010: import com.meterware.httpunit.GetMethodWebRequest;
011: import com.meterware.httpunit.WebConversation;
012: import com.meterware.httpunit.WebForm;
013: import com.meterware.httpunit.WebRequest;
014: import com.meterware.httpunit.WebResponse;
015: import com.uwyn.rife.TestCaseServerside;
016:
017: public class TestMemoryLogout extends TestCaseServerside {
018: public TestMemoryLogout(int siteType, String name) {
019: super (siteType, name);
020: }
021:
022: public void testMemoryLogoutTemplateBasicInput() throws Exception {
023: setupSite("site/authentication_memory_input.xml");
024:
025: WebConversation conversation = new WebConversation();
026: WebRequest request = null;
027: WebResponse response = null;
028: WebForm form = null;
029:
030: request = new GetMethodWebRequest(
031: "http://localhost:8181/authentication/memory/basic");
032: response = conversation.getResponse(request);
033: form = response.getForms()[0];
034: form.setParameter("login", "guest");
035: form.setParameter("password", "guestpass");
036: response = form.submit();
037: assertEquals(0, response.getForms().length);
038:
039: response = response.getLinkWith("reload").click();
040: assertEquals(0, response.getForms().length);
041:
042: WebResponse response_logout = response.getLinkWith(
043: "logout template").click();
044: assertEquals("logged out memory", response_logout.getTitle());
045:
046: response = response.getLinkWith("reload").click();
047: assertEquals(1, response.getForms().length);
048: }
049:
050: public void testMemoryLogoutTemplateBasicCookie() throws Exception {
051: setupSite("site/authentication_memory_cookie.xml");
052:
053: WebConversation conversation = new WebConversation();
054: WebRequest request = null;
055: WebResponse response = null;
056: WebForm form = null;
057:
058: request = new GetMethodWebRequest(
059: "http://localhost:8181/authentication/memory/basic");
060: response = conversation.getResponse(request);
061: form = response.getForms()[0];
062: form.setParameter("login", "guest");
063: form.setParameter("password", "guestpass");
064: response = form.submit();
065: assertEquals("authid", response.getNewCookieNames()[0]);
066: assertFalse("".equals(conversation.getCookieValue("authid")));
067: assertEquals(0, response.getForms().length);
068:
069: response = response.getLinkWith("reload").click();
070: assertEquals(0, response.getForms().length);
071:
072: WebResponse response_logout = response.getLinkWith(
073: "logout template").click();
074: assertEquals("logged out memory", response_logout.getTitle());
075: assertEquals("", conversation.getCookieValue("authid"));
076:
077: response = response.getLinkWith("reload").click();
078: assertEquals(1, response.getForms().length);
079: }
080:
081: public void testMemoryLogoutTemplateXhtmlInput() throws Exception {
082: setupSite("site/authentication_memory_input.xml");
083:
084: WebConversation conversation = new WebConversation();
085: WebRequest request = null;
086: WebResponse response = null;
087: WebForm form = null;
088:
089: request = new GetMethodWebRequest(
090: "http://localhost:8181/authentication/memory/xhtml");
091: response = conversation.getResponse(request);
092: form = response.getForms()[0];
093: form.setParameter("login", "guest");
094: form.setParameter("password", "guestpass");
095: response = form.submit();
096: assertEquals(0, response.getForms().length);
097:
098: response = response.getLinkWith("reload").click();
099: assertEquals(0, response.getForms().length);
100:
101: WebResponse response_logout = response.getLinkWith(
102: "logout template").click();
103: assertEquals("logged out memory", response_logout.getTitle());
104: assertTrue(response_logout.getText().indexOf("This is XHtml") != -1);
105:
106: response = response.getLinkWith("reload").click();
107: assertEquals(1, response.getForms().length);
108: }
109:
110: public void testMemoryLogoutTemplateXhtmlCookie() throws Exception {
111: setupSite("site/authentication_memory_cookie.xml");
112:
113: WebConversation conversation = new WebConversation();
114: WebRequest request = null;
115: WebResponse response = null;
116: WebForm form = null;
117:
118: request = new GetMethodWebRequest(
119: "http://localhost:8181/authentication/memory/xhtml");
120: response = conversation.getResponse(request);
121: form = response.getForms()[0];
122: form.setParameter("login", "guest");
123: form.setParameter("password", "guestpass");
124: response = form.submit();
125: assertEquals("authid", response.getNewCookieNames()[0]);
126: assertFalse("".equals(conversation.getCookieValue("authid")));
127: assertEquals(0, response.getForms().length);
128:
129: response = response.getLinkWith("reload").click();
130: assertEquals(0, response.getForms().length);
131:
132: WebResponse response_logout = response.getLinkWith(
133: "logout template").click();
134: assertEquals("logged out memory", response_logout.getTitle());
135: assertEquals("", conversation.getCookieValue("authid"));
136: assertTrue(response_logout.getText().indexOf("This is XHtml") != -1);
137:
138: response = response.getLinkWith("reload").click();
139: assertEquals(1, response.getForms().length);
140: }
141:
142: public void testMemoryLogoutTemplateOtheridInput() throws Exception {
143: setupSite("site/authentication_memory_input.xml");
144:
145: WebConversation conversation = new WebConversation();
146: WebRequest request = null;
147: WebForm form = null;
148:
149: request = new GetMethodWebRequest(
150: "http://localhost:8181/authentication/memory/basic");
151: WebResponse response_basic = conversation.getResponse(request);
152: form = response_basic.getForms()[0];
153: form.setParameter("login", "guest");
154: form.setParameter("password", "guestpass");
155: response_basic = form.submit();
156: assertEquals(0, response_basic.getForms().length);
157:
158: response_basic = response_basic.getLinkWith("reload").click();
159: assertEquals(0, response_basic.getForms().length);
160:
161: request = new GetMethodWebRequest(
162: "http://localhost:8181/authentication/memory/otherid");
163: WebResponse response_otherid = conversation
164: .getResponse(request);
165: form = response_otherid.getForms()[0];
166: form.setParameter("login", "guest");
167: form.setParameter("password", "guestpass");
168: response_otherid = form.submit();
169: assertEquals(0, response_otherid.getForms().length);
170:
171: response_otherid = response_otherid.getLinkWith("reload")
172: .click();
173: assertEquals(0, response_otherid.getForms().length);
174:
175: WebResponse response_logout = null;
176: response_logout = response_basic.getLinkWith("logout template")
177: .click();
178: assertEquals("logged out memory", response_logout.getTitle());
179: response_basic = response_basic.getLinkWith("reload").click();
180: assertEquals(1, response_basic.getForms().length);
181: response_otherid = response_otherid.getLinkWith("reload")
182: .click();
183: assertEquals(0, response_otherid.getForms().length);
184:
185: response_logout = response_otherid.getLinkWith(
186: "logout template").click();
187: assertEquals("logged out memory", response_logout.getTitle());
188: response_otherid = response_otherid.getLinkWith("reload")
189: .click();
190: assertEquals(1, response_otherid.getForms().length);
191: }
192:
193: public void testMemoryLogoutTemplateOtheridCookie()
194: throws Exception {
195: setupSite("site/authentication_memory_cookie.xml");
196:
197: WebRequest request = null;
198: WebForm form = null;
199:
200: WebConversation conversation_basic = new WebConversation();
201: request = new GetMethodWebRequest(
202: "http://localhost:8181/authentication/memory/basic");
203: WebResponse response_basic = conversation_basic
204: .getResponse(request);
205: form = response_basic.getForms()[0];
206: form.setParameter("login", "guest");
207: form.setParameter("password", "guestpass");
208: response_basic = form.submit();
209: assertEquals("authid", response_basic.getNewCookieNames()[0]);
210: assertFalse("".equals(conversation_basic
211: .getCookieValue("authid")));
212: assertEquals(0, response_basic.getForms().length);
213:
214: response_basic = response_basic.getLinkWith("reload").click();
215: assertEquals(0, response_basic.getForms().length);
216:
217: WebConversation conversation_otherid = new WebConversation();
218: request = new GetMethodWebRequest(
219: "http://localhost:8181/authentication/memory/otherid");
220: WebResponse response_otherid = conversation_otherid
221: .getResponse(request);
222: form = response_otherid.getForms()[0];
223: form.setParameter("login", "guest");
224: form.setParameter("password", "guestpass");
225: response_otherid = form.submit();
226:
227: response_basic = response_basic.getLinkWith("reload").click();
228: assertEquals(0, response_otherid.getForms().length);
229:
230: response_otherid = response_otherid.getLinkWith("reload")
231: .click();
232: assertEquals(0, response_otherid.getForms().length);
233:
234: WebResponse response_logout = null;
235: response_logout = response_basic.getLinkWith("logout template")
236: .click();
237: assertEquals("logged out memory", response_logout.getTitle());
238: assertEquals("", conversation_basic.getCookieValue("authid"));
239: response_basic = response_basic.getLinkWith("reload").click();
240: assertEquals(1, response_basic.getForms().length);
241: response_otherid = response_otherid.getLinkWith("reload")
242: .click();
243: assertEquals(0, response_otherid.getForms().length);
244:
245: response_logout = response_otherid.getLinkWith(
246: "logout template").click();
247: assertEquals("logged out memory", response_logout.getTitle());
248: assertEquals("", conversation_otherid.getCookieValue("authid"));
249: response_otherid = response_otherid.getLinkWith("reload")
250: .click();
251: assertEquals(1, response_otherid.getForms().length);
252: }
253:
254: public void testMemoryLogoutPassthroughBasicInput()
255: throws Exception {
256: setupSite("site/authentication_memory_input.xml");
257:
258: WebConversation conversation = new WebConversation();
259: WebRequest request = null;
260: WebResponse response = null;
261: WebForm form = null;
262:
263: request = new GetMethodWebRequest(
264: "http://localhost:8181/authentication/memory/basic");
265: response = conversation.getResponse(request);
266: form = response.getForms()[0];
267: form.setParameter("login", "guest");
268: form.setParameter("password", "guestpass");
269: response = form.submit();
270: assertEquals(0, response.getForms().length);
271:
272: response = response.getLinkWith("reload").click();
273: assertEquals(0, response.getForms().length);
274:
275: response = response.getLinkWith("logout passthrough").click();
276: assertEquals(1, response.getForms().length);
277: form = response.getForms()[0];
278: form.setParameter("login", "guest");
279: form.setParameter("password", "guestpass");
280: response = form.submit();
281: assertEquals(0, response.getForms().length);
282: }
283:
284: public void testMemoryLogoutPassthroughBasicCookie()
285: throws Exception {
286: setupSite("site/authentication_memory_cookie.xml");
287:
288: WebConversation conversation = new WebConversation();
289: WebRequest request = null;
290: WebResponse response = null;
291: WebForm form = null;
292:
293: request = new GetMethodWebRequest(
294: "http://localhost:8181/authentication/memory/basic");
295: response = conversation.getResponse(request);
296: form = response.getForms()[0];
297: form.setParameter("login", "guest");
298: form.setParameter("password", "guestpass");
299: response = form.submit();
300: assertEquals("authid", response.getNewCookieNames()[0]);
301: assertFalse("".equals(conversation.getCookieValue("authid")));
302: assertEquals(0, response.getForms().length);
303:
304: response = response.getLinkWith("reload").click();
305: assertEquals(0, response.getForms().length);
306:
307: response = response.getLinkWith("logout passthrough").click();
308: assertEquals("", conversation.getCookieValue("authid"));
309: assertEquals(1, response.getForms().length);
310: form = response.getForms()[0];
311: form.setParameter("login", "guest");
312: form.setParameter("password", "guestpass");
313: response = form.submit();
314: assertEquals(0, response.getForms().length);
315: }
316:
317: public void testMemoryLogoutPrecedenceInput() throws Exception {
318: setupSite("site/authentication_memory_input.xml");
319:
320: WebConversation conversation = new WebConversation();
321: WebRequest request = null;
322: WebResponse response = null;
323: WebForm form = null;
324:
325: request = new GetMethodWebRequest(
326: "http://localhost:8181/authentication/memory/precedence");
327: response = conversation.getResponse(request);
328: form = response.getForms()[0];
329: form.setParameter("login", "guest");
330: form.setParameter("password", "guestpass");
331: response = form.submit();
332: assertEquals(0, response.getForms().length);
333:
334: response = response.getLinkWith("reload").click();
335: assertEquals(0, response.getForms().length);
336:
337: response = response.getLinkWith("logout").click();
338: assertEquals(1, response.getForms().length);
339: form = response.getForms()[0];
340: form.setParameter("login", "guest");
341: form.setParameter("password", "guestpass");
342: response = form.submit();
343: assertEquals(0, response.getForms().length);
344: }
345:
346: public void testMemoryLogoutPrecedenceCookie() throws Exception {
347: setupSite("site/authentication_memory_cookie.xml");
348:
349: WebConversation conversation = new WebConversation();
350: WebRequest request = null;
351: WebResponse response = null;
352: WebForm form = null;
353:
354: request = new GetMethodWebRequest(
355: "http://localhost:8181/authentication/memory/precedence");
356: response = conversation.getResponse(request);
357: form = response.getForms()[0];
358: form.setParameter("login", "guest");
359: form.setParameter("password", "guestpass");
360: response = form.submit();
361: assertEquals("authid", response.getNewCookieNames()[0]);
362: assertFalse("".equals(conversation.getCookieValue("authid")));
363: assertEquals(0, response.getForms().length);
364:
365: response = response.getLinkWith("reload").click();
366: assertEquals(0, response.getForms().length);
367:
368: response = response.getLinkWith("logout").click();
369: assertEquals("", conversation.getCookieValue("authid"));
370: assertEquals(1, response.getForms().length);
371: form = response.getForms()[0];
372: form.setParameter("login", "guest");
373: form.setParameter("password", "guestpass");
374: response = form.submit();
375: assertEquals(0, response.getForms().length);
376: }
377: }
|