use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.
the class TestLdapProvExternalLdapAuth method zimbraAuthNonSSHA.
@Test
public void zimbraAuthNonSSHA() throws Exception {
String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
Account acct = createAccount(ACCT_NAME_LOCALPART);
String PASSWORD = InMemoryLdapServer.Password.genNonSSHAPassword("not-ssha-blah");
// modify userPassword via modifyAccount, not changePassword
Map<String, Object> acctAttrs = new HashMap<String, Object>();
acctAttrs.put(Provisioning.A_userPassword, PASSWORD);
prov.modifyAttrs(acct, acctAttrs);
// good password
prov.authAccount(acct, PASSWORD, AuthContext.Protocol.test);
// bad password
boolean caughtException = false;
try {
prov.authAccount(acct, PASSWORD + "not", AuthContext.Protocol.test);
} catch (AccountServiceException e) {
if (AccountServiceException.AUTH_FAILED.equals(e.getCode())) {
caughtException = true;
}
}
assertTrue(caughtException);
provUtil.deleteAccount(acct);
}
use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.
the class TestLdapProvDistributionList method createDistributionListAlreadyExists.
@Test
public void createDistributionListAlreadyExists() throws Exception {
String DL_NAME_LOCALPART = Names.makeDLNameLocalPart(genGroupNameLocalPart());
DistributionList dl = createDistributionList(DL_NAME_LOCALPART);
boolean caughtException = false;
try {
prov.createDistributionList(dl.getName(), new HashMap<String, Object>());
} catch (AccountServiceException e) {
if (AccountServiceException.DISTRIBUTION_LIST_EXISTS.equals(e.getCode())) {
caughtException = true;
}
}
assertTrue(caughtException);
deleteDistributionList(dl);
}
use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.
the class TestProvAttr method testDurationAttr.
@Test
public void testDurationAttr() throws Exception {
Server server = getServer();
String attrName = Provisioning.A_zimbraHsmAge;
String strValue;
long msValue;
long secValue;
Map<String, Object> attrs = new HashMap<String, Object>();
// nnnnn([hmsd]|ms)
// d (day)
attrs.put(attrName, "1d");
prov.modifyAttrs(server, attrs);
strValue = server.getAttr(attrName);
assertEquals("1d", strValue);
msValue = server.getTimeInterval(attrName, 0);
assertEquals(Constants.MILLIS_PER_DAY, msValue);
secValue = server.getTimeIntervalSecs(attrName, 0);
assertEquals(Constants.SECONDS_PER_DAY, secValue);
// h (hour)
attrs.put(attrName, "1h");
prov.modifyAttrs(server, attrs);
strValue = server.getAttr(attrName);
assertEquals("1h", strValue);
msValue = server.getTimeInterval(attrName, 0);
assertEquals(Constants.MILLIS_PER_HOUR, msValue);
secValue = server.getTimeIntervalSecs(attrName, 0);
assertEquals(Constants.SECONDS_PER_HOUR, secValue);
// m (minute)
attrs.put(attrName, "1m");
prov.modifyAttrs(server, attrs);
strValue = server.getAttr(attrName);
assertEquals("1m", strValue);
msValue = server.getTimeInterval(attrName, 0);
assertEquals(Constants.MILLIS_PER_MINUTE, msValue);
secValue = server.getTimeIntervalSecs(attrName, 0);
assertEquals(Constants.SECONDS_PER_MINUTE, secValue);
// s (second)
attrs.put(attrName, "1s");
prov.modifyAttrs(server, attrs);
strValue = server.getAttr(attrName);
assertEquals("1s", strValue);
msValue = server.getTimeInterval(attrName, 0);
assertEquals(Constants.MILLIS_PER_SECOND, msValue);
secValue = server.getTimeIntervalSecs(attrName, 0);
assertEquals(1, secValue);
// default (== s)
attrs.put(attrName, "1");
prov.modifyAttrs(server, attrs);
strValue = server.getAttr(attrName);
assertEquals("1", strValue);
msValue = server.getTimeInterval(attrName, 0);
assertEquals(Constants.MILLIS_PER_SECOND, msValue);
secValue = server.getTimeIntervalSecs(attrName, 0);
assertEquals(1, secValue);
// ms (milli second)
attrs.put(attrName, "1ms");
prov.modifyAttrs(server, attrs);
strValue = server.getAttr(attrName);
assertEquals("1ms", strValue);
msValue = server.getTimeInterval(attrName, 0);
assertEquals(1, msValue);
secValue = server.getTimeIntervalSecs(attrName, 0);
assertEquals(0, secValue);
attrs.put(attrName, "500ms");
prov.modifyAttrs(server, attrs);
strValue = server.getAttr(attrName);
assertEquals("500ms", strValue);
msValue = server.getTimeInterval(attrName, 0);
assertEquals(500, msValue);
secValue = server.getTimeIntervalSecs(attrName, 0);
assertEquals(1, secValue);
attrs.put(attrName, "1000ms");
prov.modifyAttrs(server, attrs);
strValue = server.getAttr(attrName);
assertEquals("1000ms", strValue);
msValue = server.getTimeInterval(attrName, 0);
assertEquals(1000, msValue);
secValue = server.getTimeIntervalSecs(attrName, 0);
assertEquals(1, secValue);
attrs.put(attrName, "1001ms");
prov.modifyAttrs(server, attrs);
strValue = server.getAttr(attrName);
assertEquals("1001ms", strValue);
msValue = server.getTimeInterval(attrName, 0);
assertEquals(1001, msValue);
secValue = server.getTimeIntervalSecs(attrName, 0);
assertEquals(1, secValue);
attrs.put(attrName, "999ms");
prov.modifyAttrs(server, attrs);
strValue = server.getAttr(attrName);
assertEquals("999ms", strValue);
msValue = server.getTimeInterval(attrName, 0);
assertEquals(999, msValue);
secValue = server.getTimeIntervalSecs(attrName, 0);
assertEquals(1, secValue);
attrs.put(attrName, "0ms");
prov.modifyAttrs(server, attrs);
strValue = server.getAttr(attrName);
assertEquals("0ms", strValue);
msValue = server.getTimeInterval(attrName, 0);
assertEquals(0, msValue);
secValue = server.getTimeIntervalSecs(attrName, 0);
assertEquals(0, secValue);
// invalid unit
boolean good = false;
attrs.put(attrName, "1y");
try {
prov.modifyAttrs(server, attrs);
} catch (AccountServiceException e) {
if (AccountServiceException.INVALID_ATTR_VALUE.equals(e.getCode()))
good = true;
}
assertTrue(good);
good = false;
attrs.put(attrName, "1mm");
try {
prov.modifyAttrs(server, attrs);
} catch (AccountServiceException e) {
if (AccountServiceException.INVALID_ATTR_VALUE.equals(e.getCode()))
good = true;
}
assertTrue(good);
}
use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.
the class TestLdapProvZimlet method createZimletAlreadyExists.
@Test
public void createZimletAlreadyExists() throws Exception {
String ZIMLET_NAME = Names.makeZimletName(genZimletName());
Zimlet zimlet = createZimlet(ZIMLET_NAME);
boolean caughtException = false;
try {
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraZimletVersion, "1.0");
zimlet = prov.createZimlet(ZIMLET_NAME, attrs);
} catch (AccountServiceException e) {
if (AccountServiceException.ZIMLET_EXISTS.equals(e.getCode())) {
caughtException = true;
}
}
assertTrue(caughtException);
deleteZimlet(zimlet);
}
Aggregations