use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class SharedFolderTest method adminGrant.
@Test
public void adminGrant() throws Exception {
Account owner, grantee, virtualGrantee;
Provisioning prov = Provisioning.getInstance();
owner = prov.get(Key.AccountBy.name, "owner@zimbra.com");
grantee = prov.get(Key.AccountBy.name, "grantee1@zimbra.com");
virtualGrantee = prov.get(Key.AccountBy.name, "virtual_grantee1@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(owner.getId());
Folder.FolderOptions fopt = new Folder.FolderOptions();
fopt.setDefaultView(MailItem.Type.MESSAGE);
Folder f1 = mbox.createFolder(null, "/Inbox/f1", fopt);
String exception;
// allow granting admin right to internal user
try {
exception = null;
mbox.grantAccess(null, f1.getId(), grantee.getId(), ACL.GRANTEE_USER, ACL.stringToRights("rwidxa"), null);
} catch (ServiceException e) {
exception = e.getCode();
}
Assert.assertEquals("got wrong exception", null, exception);
// don't allow granting admin right to virtual account
try {
exception = null;
mbox.grantAccess(null, f1.getId(), virtualGrantee.getId(), ACL.GRANTEE_USER, ACL.stringToRights("rwidxa"), null);
} catch (ServiceException e) {
exception = e.getCode();
}
Assert.assertEquals("got wrong exception", MailServiceException.CANNOT_GRANT, exception);
// don't allow granting admin right to public
try {
exception = null;
mbox.grantAccess(null, f1.getId(), null, ACL.GRANTEE_PUBLIC, ACL.stringToRights("rwidxa"), null);
} catch (ServiceException e) {
exception = e.getCode();
}
Assert.assertEquals("got wrong exception", MailServiceException.CANNOT_GRANT, exception);
// allow granting non-admin rights to virtual account
try {
exception = null;
mbox.grantAccess(null, f1.getId(), virtualGrantee.getId(), ACL.GRANTEE_USER, ACL.stringToRights("rwidx"), null);
} catch (ServiceException e) {
exception = e.getCode();
}
Assert.assertEquals("got wrong exception", null, exception);
// allow granting non-admin rights to public
try {
exception = null;
mbox.grantAccess(null, f1.getId(), null, ACL.GRANTEE_PUBLIC, ACL.stringToRights("rwidx"), null);
} catch (ServiceException e) {
exception = e.getCode();
}
Assert.assertEquals("got wrong exception", null, exception);
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class ModifyFilterRulesTest method testBug71036_MultiNestedIfSingleRule.
@Test
public void testBug71036_MultiNestedIfSingleRule() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Element request = new Element.XMLElement(MailConstants.MODIFY_FILTER_RULES_REQUEST);
Element rules = request.addElement(MailConstants.E_FILTER_RULES);
Element rule = rules.addElement(MailConstants.E_FILTER_RULE);
rule.addAttribute(MailConstants.A_ACTIVE, true);
rule.addAttribute(MailConstants.A_NAME, "Test1");
Element filterTests = rule.addElement(MailConstants.E_FILTER_TESTS);
filterTests.addAttribute(MailConstants.A_CONDITION, "anyof");
Element headerTest = filterTests.addElement(MailConstants.E_HEADER_TEST);
headerTest.addAttribute(MailConstants.A_HEADER, "subject");
headerTest.addAttribute(MailConstants.A_STRING_COMPARISON, "contains");
headerTest.addAttribute(MailConstants.A_VALUE, "important");
Element nestedRule = rule.addElement(MailConstants.E_NESTED_RULE);
Element childFilterTests = nestedRule.addElement(MailConstants.E_FILTER_TESTS);
childFilterTests.addAttribute(MailConstants.A_CONDITION, "anyof");
Element childheaderTest2 = childFilterTests.addElement(MailConstants.E_HEADER_TEST);
childheaderTest2.addAttribute(MailConstants.A_HEADER, "subject");
childheaderTest2.addAttribute(MailConstants.A_STRING_COMPARISON, "is");
childheaderTest2.addAttribute(MailConstants.A_VALUE, "confifential");
Element nestedRule2 = nestedRule.addElement(MailConstants.E_NESTED_RULE);
Element child2FilterTests = nestedRule2.addElement(MailConstants.E_FILTER_TESTS);
child2FilterTests.addAttribute(MailConstants.A_CONDITION, "anyof");
Element child2headerTest2 = child2FilterTests.addElement(MailConstants.E_HEADER_TEST);
child2headerTest2.addAttribute(MailConstants.A_HEADER, "from");
child2headerTest2.addAttribute(MailConstants.A_STRING_COMPARISON, "contains");
child2headerTest2.addAttribute(MailConstants.A_VALUE, "test");
Element filteraction = nestedRule2.addElement(MailConstants.E_FILTER_ACTIONS);
Element actionInto = filteraction.addElement(MailConstants.E_ACTION_FILE_INTO);
actionInto.addAttribute(MailConstants.A_FOLDER_PATH, "Junk");
filteraction.addElement(MailConstants.E_ACTION_STOP);
try {
new ModifyFilterRules().handle(request, ServiceTestUtil.getRequestContext(acct));
} catch (ServiceException e) {
fail("This test is expected not to throw exception. ");
}
String expectedScript = "require [\"fileinto\", \"reject\", \"tag\", \"flag\", \"variables\", \"log\", \"enotify\"];\n\n";
expectedScript += "# Test1\n";
expectedScript += "if anyof (header :contains [\"subject\"] \"important\") {\n";
expectedScript += " if anyof (header :is [\"subject\"] \"confifential\") {\n";
expectedScript += " if anyof (header :contains [\"from\"] \"test\") {\n";
expectedScript += " fileinto \"Junk\";\n";
expectedScript += " stop;\n";
expectedScript += " }\n";
expectedScript += " }\n";
expectedScript += "}\n";
//ZimbraLog.filter.info(acct.getMailSieveScript());
//ZimbraLog.filter.info(expectedScript);
assertEquals(expectedScript, acct.getMailSieveScript());
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class ModifyFilterRulesTest method testFilterVariablesWithNoName.
@Test
public void testFilterVariablesWithNoName() {
try {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
String xml = "<ModifyFilterRulesRequest xmlns=\"urn:zimbraMail\">\n" + " <filterRules>\n" + " <filterRule name=\"t60\" active=\"1\">\n" + " <filterVariables index=\"0\">\n" + " <filterVariable name=\"var\" value=\"testTag\" index=\"0\"/>\n" + " <filterVariable value=\"${var}\" index=\"1\"/>\n" + " </filterVariables>\n" + " <filterTests condition=\"anyof\" index=\"1\">\n" + " <headerTest stringComparison=\"matches\" header=\"subject\" value=\"test\"/>\n" + " </filterTests>\n" + " <filterActions index=\"2\">\n" + " <actionTag tagName=\"${var_new}\" index=\"0\"/>\n" + " <filterVariables index=\"1\">\n" + " <filterVariable name=\"v1\" value=\"blah blah\" index=\"0\"/>\n" + " <filterVariable name=\"v2\" value=\"${1}\" index=\"1\"/>\n" + " <filterVariable name=\"v3\" value=\"${2}\" index=\"1\"/>\n" + " </filterVariables>\n" + " </filterActions>\n" + " </filterRule>\n" + " </filterRules>\n" + "</ModifyFilterRulesRequest>";
Element request = Element.parseXML(xml);
new ModifyFilterRules().handle(request, ServiceTestUtil.getRequestContext(account));
fail("Should not reach here. Exception is expected");
} catch (ServiceException e) {
assertTrue("parse error: Filter variable should have a name".equals(e.getMessage()));
} catch (Exception e) {
fail("No exception should be thrown" + e);
}
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class SendShareNotificationTest method generateShareNotification.
@Override
protected MimeMessage generateShareNotification(Account authAccount, Account ownerAccount, ShareInfoData sid, String notes, SendShareNotificationRequest.Action action, Collection<String> internalRecipients, String externalRecipient) throws ServiceException, MessagingException {
MimeMessage mm = super.generateShareNotification(authAccount, ownerAccount, sid, notes, action, internalRecipients, externalRecipient);
try {
MimeMultipart mmp = (MimeMultipart) mm.getContent();
BodyPart bp = mmp.getBodyPart(2);
Assert.assertTrue(bp.getContentType().startsWith(MimeConstants.CT_XML_ZIMBRA_SHARE));
Element share = Element.parseXML(bp.getInputStream());
if (revoke) {
Assert.assertEquals(share.getQName().getName(), MailConstants.ShareConstants.E_REVOKE);
} else {
Assert.assertEquals(share.getQName().getName(), MailConstants.ShareConstants.E_SHARE);
}
} catch (Exception e) {
Assert.fail(e.getMessage());
}
return mm;
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class ModifyFilterRulesTest method testBug82649_BlankFilter.
@Test
public void testBug82649_BlankFilter() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Element request = new Element.XMLElement(MailConstants.MODIFY_FILTER_RULES_REQUEST);
Element rules = request.addElement(MailConstants.E_FILTER_RULES);
Element rule = rules.addElement(MailConstants.E_FILTER_RULE);
rule.addAttribute(MailConstants.A_ACTIVE, true);
rule.addAttribute(MailConstants.A_NAME, "Test1");
Element filteraction = rule.addElement(MailConstants.E_FILTER_ACTIONS);
Element actionInto = filteraction.addElement(MailConstants.E_ACTION_FILE_INTO);
actionInto.addAttribute(MailConstants.A_FOLDER_PATH, "Junk");
filteraction.addElement(MailConstants.E_ACTION_STOP);
Element filterTests = rule.addElement(MailConstants.E_FILTER_TESTS);
filterTests.addAttribute(MailConstants.A_CONDITION, "anyof");
Element headerTest = filterTests.addElement(MailConstants.E_HEADER_TEST);
headerTest.addAttribute(MailConstants.A_HEADER, "subject");
headerTest.addAttribute(MailConstants.A_STRING_COMPARISON, "contains");
try {
new ModifyFilterRules().handle(request, ServiceTestUtil.getRequestContext(acct));
fail("This test is expected to throw exception. ");
} catch (ServiceException e) {
String expected = "invalid request: missing required attribute: value";
assertTrue(e.getMessage().indexOf(expected) != -1);
assertNotNull(e);
}
}
Aggregations