Revision 8430
Added by Jing Tao about 11 years ago
test/edu/ucsb/nceas/metacat/authentication/AuthFileTest.java | ||
---|---|---|
61 | 61 |
suite.addTest(new AuthFileTest("testAddUser")); |
62 | 62 |
suite.addTest(new AuthFileTest("testAuthenticate")); |
63 | 63 |
suite.addTest(new AuthFileTest("testGetUsers")); |
64 |
suite.addTest(new AuthFileTest("testGetGroups")); |
|
65 |
suite.addTest(new AuthFileTest("testChangePassword")); |
|
64 | 66 |
return suite; |
65 | 67 |
} |
66 | 68 |
|
... | ... | |
130 | 132 |
userInGroup = authFile.getUsers(null, null, "group1"); |
131 | 133 |
assertTrue("There shouldn't have any users in the group1 ", userInGroup==null); |
132 | 134 |
} |
135 |
|
|
136 |
/** |
|
137 |
* Test the getGroups method |
|
138 |
* @throws Exception |
|
139 |
*/ |
|
140 |
public void testGetGroups() throws Exception { |
|
141 |
AuthFile authFile = AuthFile.getInstance(PASSWORDFILEPATH); |
|
142 |
String[][] groups = authFile.getGroups(null, null); |
|
143 |
assertTrue("The file should have one group associated with "+USERNAME, groups[0][0].equals(GROUPNAME)); |
|
144 |
String[][]groupForUser = authFile.getGroups(null, null, USERNAME); |
|
145 |
assertTrue("There should be at least one group for user "+USERNAME, groupForUser[0][0].equals(GROUPNAME)); |
|
146 |
groupForUser = authFile.getGroups(null, null, "user1"); |
|
147 |
assertTrue("There shouldn't have any groups assoicated with user1 ", groupForUser==null); |
|
148 |
} |
|
149 |
|
|
150 |
/** |
|
151 |
* Test the change password methods |
|
152 |
* @throws Exception |
|
153 |
*/ |
|
154 |
public void testChangePassword() throws Exception { |
|
155 |
AuthFile authFile = AuthFile.getInstance(PASSWORDFILEPATH); |
|
156 |
String password = authFile.resetPassword(USERNAME); |
|
157 |
String newPassword = "hello"; |
|
158 |
authFile.modifyPassword(USERNAME, password, newPassword); |
|
159 |
|
|
160 |
try { |
|
161 |
authFile.resetPassword("user1"); |
|
162 |
assertTrue("Can't reach here since we tried to reset the password for an unexisting user ", false); |
|
163 |
} catch (AuthenticationException e) { |
|
164 |
|
|
165 |
} |
|
166 |
try { |
|
167 |
authFile.modifyPassword("user1", "old", "new"); |
|
168 |
assertTrue("Can't reach here since we tried to change the password for an unexisting user ", false); |
|
169 |
} catch (AuthenticationException e) { |
|
170 |
|
|
171 |
} |
|
172 |
} |
|
133 | 173 |
} |
Also available in: Unified diff
Add test methods for changing passwords.