-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZCS-15588: Updated ChangePasswordRequest to support zimbraPasswordMus…
…tChange flow
- Loading branch information
1 parent
9e1d24c
commit d533e6e
Showing
6 changed files
with
122 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,9 @@ | |
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException; | ||
import com.zimbra.cs.account.AuthToken; | ||
import com.zimbra.cs.service.AuthProvider; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
|
@@ -32,13 +35,16 @@ | |
public class ChangePasswordTest { | ||
private static final String USERNAME_1 = "[email protected]"; | ||
private static final String USERNAME_2 = "[email protected]"; | ||
private static final String USERNAME_3 = "[email protected]"; | ||
private static final String PASSWORD_1 = "H3@pBigPassw0rd"; | ||
private static final String PASSWORD_2 = "An0therP@$$w0rd"; | ||
private static final String PASSWORD_3 = "An0therP@1$$w0rd"; | ||
|
||
private static final MockProvisioning prov = new MockProvisioning(); | ||
|
||
private Account account1; | ||
private Account account2; | ||
private Account account3; | ||
|
||
@BeforeClass | ||
public static void init() throws Exception { | ||
|
@@ -57,6 +63,11 @@ public void setUp() throws Exception { | |
final Map<String,Object> attrs2 = new HashMap<>(1); | ||
attrs2.put(Provisioning.A_zimbraId, LdapUtil.generateUUID()); | ||
account2 = prov.createAccount(USERNAME_2, PASSWORD_2, attrs2); | ||
|
||
final Map<String,Object> attrs3 = new HashMap<>(1); | ||
attrs3.put(Provisioning.A_zimbraId, LdapUtil.generateUUID()); | ||
attrs3.put(Provisioning.A_zimbraPasswordMustChange, "TRUE"); | ||
account3 = prov.createAccount(USERNAME_3, PASSWORD_3, attrs3); | ||
} | ||
|
||
@Test | ||
|
@@ -97,18 +108,38 @@ public void testBasicHandlerWrongAuth() throws Exception { | |
} | ||
|
||
@Test | ||
public void testNeedsAuth() throws Exception { | ||
public void testNeedsAuth() { | ||
final ChangePassword handler = new ChangePassword(); | ||
final Map<String,Object> context = Collections.emptyMap(); | ||
|
||
Assert.assertTrue("handler.needsAuth()", handler.needsAuth(context)); | ||
Assert.assertFalse("handler.needsAuth()", handler.needsAuth(context)); | ||
} | ||
|
||
@Test | ||
public void testBasicHandlerWithResetPasswordAuthTokenUsageIfMustChangePasswordIsEnabled() throws Exception { | ||
AuthToken authToken = AuthProvider.getAuthToken(account3, AuthToken.Usage.RESET_PASSWORD , AuthToken.TokenType.AUTH); | ||
final ChangePasswordRequest request = new ChangePasswordRequest() | ||
.setAccount(AccountSelector.fromName(USERNAME_3)) // Not the authed user from context below | ||
.setOldPassword(PASSWORD_3) | ||
.setPassword(PASSWORD_3) | ||
.setAuthToken(new com.zimbra.soap.account.type.AuthToken(authToken.getEncoded(), false)); | ||
|
||
final ChangePassword handler = new ChangePassword(); | ||
final Map<String,Object> context = ServiceTestUtil.getRequestContext(account3); | ||
|
||
final Element response = handler.handle(JaxbUtil.jaxbToElement(request), context); | ||
Assert.assertNotNull("response", response); | ||
|
||
String at = response.getAttribute(AccountConstants.E_AUTH_TOKEN); | ||
Assert.assertNotNull("authtoken", at); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
MailboxTestUtil.clearData(); | ||
prov.deleteAccount(account1.getId()); | ||
prov.deleteAccount(account1.getId()); | ||
prov.deleteAccount(account2.getId()); | ||
prov.deleteAccount(account3.getId()); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters