001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.reg;
022:
023: import java.util.*;
024: import java.io.*;
025: import java.sql.*;
026: import junit.framework.*;
027: import org.apache.log4j.*;
028: import com.methodhead.persistable.*;
029: import com.methodhead.test.*;
030: import com.methodhead.sitecontext.*;
031: import com.methodhead.auth.*;
032: import com.methodhead.*;
033: import servletunit.struts.*;
034: import org.apache.struts.action.*;
035: import org.apache.struts.util.*;
036: import org.apache.cactus.*;
037:
038: public class PasswordFormTest extends CactusStrutsTestCase {
039:
040: List list = null;
041: LabelValueBean labelValue = null;
042: DynaActionForm form = null;
043: User user = null;
044:
045: static {
046: TestUtils.initLogger();
047: }
048:
049: public PasswordFormTest(String name) {
050: super (name);
051: }
052:
053: public void setUp() throws Exception {
054: super .setUp();
055:
056: ConnectionSingleton.runBatchUpdate(new FileReader(
057: "webapp/WEB-INF/db/transfer-reset.sql"));
058:
059: TestData.createUsers();
060: AuthUtil.setUser(request, TestData.user1);
061: }
062:
063: public void tearDown() throws Exception {
064: super .tearDown();
065: }
066:
067: public void testValidatePasswordMissingPassword() throws Exception {
068: setRequestPathInfo("/password");
069: addRequestParameter("oldpassword", "");
070: addRequestParameter("password", "");
071: addRequestParameter("verifypassword", "");
072: actionPerform();
073:
074: verifyActionErrors(new String[] {
075: "reg.password.missingpassword",
076: "reg.password.missingoldpassword",
077: "reg.password.missingverifypassword" });
078: }
079:
080: public void testValidatePasswordIncorrectOldPassword()
081: throws Exception {
082: setRequestPathInfo("/password");
083: addRequestParameter("oldpassword", "incorrectpassword");
084: addRequestParameter("password", "newpassword");
085: addRequestParameter("verifypassword", "newpassword");
086: actionPerform();
087:
088: verifyActionErrors(new String[] { "reg.password.incorrectoldpassword" });
089: }
090:
091: public void testValidatePasswordMismatchedPassword()
092: throws Exception {
093: setRequestPathInfo("/password");
094: addRequestParameter("oldpassword", "password");
095: addRequestParameter("password", "newpassword");
096: addRequestParameter("verifypassword", "mismatchedpassword");
097: actionPerform();
098:
099: verifyActionErrors(new String[] { "reg.password.verifypasswordmismatch" });
100: }
101:
102: public void testValidatePasswordEncryptedMissingPassword()
103: throws Exception {
104: setRequestPathInfo("/password");
105: addRequestParameter("oldpassword", "");
106: addRequestParameter("password", "");
107: addRequestParameter("verifypassword", "");
108: actionPerform();
109:
110: verifyActionErrors(new String[] {
111: "reg.password.missingpassword",
112: "reg.password.missingoldpassword",
113: "reg.password.missingverifypassword" });
114: }
115:
116: public void testValidatePasswordEncryptedIncorrectOldPassword()
117: throws Exception {
118: setRequestPathInfo("/password");
119: addRequestParameter("oldpassword", "incorrectpassword");
120: addRequestParameter("password", "newpassword");
121: addRequestParameter("verifypassword", "newpassword");
122: actionPerform();
123:
124: verifyActionErrors(new String[] { "reg.password.incorrectoldpassword" });
125: }
126:
127: public void testValidatePasswordEncryptedMismatchedPassword()
128: throws Exception {
129: setRequestPathInfo("/password");
130: addRequestParameter("oldpassword", "password");
131: addRequestParameter("password", "newpassword");
132: addRequestParameter("verifypassword", "mismatchedpassword");
133: actionPerform();
134:
135: verifyActionErrors(new String[] { "reg.password.verifypasswordmismatch" });
136: }
137:
138: public void testValidatePasswordEncrypted() throws Exception {
139: setRequestPathInfo("/password");
140: addRequestParameter("oldpassword", "password");
141: addRequestParameter("password", "newpassword");
142: addRequestParameter("verifypassword", "newpassword");
143: actionPerform();
144:
145: verifyNoActionErrors();
146: }
147: }
|