Search in sources :

Example 1 with Provisioning

use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.

the class MigrateAttributesTest method testMigrateAlreadyMigratedAccount.

@Test
public void testMigrateAlreadyMigratedAccount() throws Exception {
    Provisioning prov = Provisioning.getInstance();
    //create a new account that will not have any data to migrate
    Account acct = prov.createAccount("user2", "test123", new HashMap<String, Object>());
    EntrySource source = new DummyEntrySource(acct);
    Multimap<String, Object> deletedAttrs = LinkedListMultimap.create();
    List<EphemeralInput> results = new LinkedList<EphemeralInput>();
    List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
    DummyMigrationCallback callback = new DummyMigrationCallback(results, deletedAttrs);
    callback.throwErrorDuringMigration = false;
    AttributeMigration migration = new AttributeMigration(attrsToMigrate, source, callback, null);
    migration.migrateAllAccounts();
    assertTrue(results.isEmpty());
}
Also used : Account(com.zimbra.cs.account.Account) EphemeralInput(com.zimbra.cs.ephemeral.EphemeralInput) Provisioning(com.zimbra.cs.account.Provisioning) LinkedList(java.util.LinkedList) EntrySource(com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource) Test(org.junit.Test)

Example 2 with Provisioning

use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.

the class DbSearchTest method init.

@BeforeClass
public static void init() throws Exception {
    MailboxTestUtil.initServer();
    Provisioning prov = Provisioning.getInstance();
    prov.createAccount("test@zimbra.com", "secret", new HashMap<String, Object>());
}
Also used : MockProvisioning(com.zimbra.cs.account.MockProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) BeforeClass(org.junit.BeforeClass)

Example 3 with Provisioning

use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.

the class EnvelopeTest method testInvalidHeaderName2.

@Test
public void testInvalidHeaderName2() {
    String filterScript = "require  \"envelope\";\n" + "if anyof envelope :matches \"from123\" \"t1@zimbra.com\" {\n" + "    fileinto \"Junk\";\n" + "}\n";
    LmtpEnvelope env = new LmtpEnvelope();
    LmtpAddress sender = new LmtpAddress("<t1@zimbra.com>", new String[] { "BODY", "SIZE" }, null);
    LmtpAddress recipient = new LmtpAddress("<xyz@zimbra.com>", null, null);
    env.setSender(sender);
    env.addLocalRecipient(recipient);
    try {
        Provisioning prov = Provisioning.getInstance();
        Account account = prov.createAccount("xyz@zimbra.com", "secret", new HashMap<String, Object>());
        account.setMail("xyz@zimbra.com");
        RuleManager.clearCachedRules(account);
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        account.setMailSieveScript(filterScript);
        List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(sampleMsg.getBytes(), false), 0, account.getName(), env, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
        Assert.assertEquals(1, ids.size());
        Message msg = mbox.getMessageById(null, ids.get(0).getId());
        Assert.assertEquals(Mailbox.ID_FOLDER_INBOX, msg.getFolderId());
    } catch (Exception e) {
        fail("No exception should be thrown");
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ItemId(com.zimbra.cs.service.util.ItemId) MockProvisioning(com.zimbra.cs.account.MockProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) Mailbox(com.zimbra.cs.mailbox.Mailbox) LmtpAddress(com.zimbra.cs.lmtpserver.LmtpAddress) LmtpEnvelope(com.zimbra.cs.lmtpserver.LmtpEnvelope) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) Test(org.junit.Test)

Example 4 with Provisioning

use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.

the class EnvelopeTest method testHeaderNameWithLeadingAndTrailingSpace.

@Test
public void testHeaderNameWithLeadingAndTrailingSpace() {
    String filterScript = "require \"envelope\";\n" + "if envelope :matches \" TO \" \"*@zimbra.com\" {\n" + "    tag \"t1\";\n" + "}\n";
    LmtpEnvelope env = new LmtpEnvelope();
    LmtpAddress sender = new LmtpAddress("<>", new String[] { "BODY", "SIZE" }, null);
    LmtpAddress recipient = new LmtpAddress("<xyz@zimbra.com>", null, null);
    env.setSender(sender);
    env.addLocalRecipient(recipient);
    try {
        Provisioning prov = Provisioning.getInstance();
        Account account = prov.createAccount("xyz@zimbra.com", "secret", new HashMap<String, Object>());
        RuleManager.clearCachedRules(account);
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        account.setMailSieveScript(filterScript);
        List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(sampleMsg.getBytes(), false), 0, account.getName(), env, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
        Assert.assertEquals(1, ids.size());
        Message msg = mbox.getMessageById(null, ids.get(0).getId());
        Assert.assertEquals(0, msg.getTags().length);
    } catch (Exception e) {
        fail("No exception should be thrown");
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ItemId(com.zimbra.cs.service.util.ItemId) MockProvisioning(com.zimbra.cs.account.MockProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) Mailbox(com.zimbra.cs.mailbox.Mailbox) LmtpAddress(com.zimbra.cs.lmtpserver.LmtpAddress) LmtpEnvelope(com.zimbra.cs.lmtpserver.LmtpEnvelope) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) Test(org.junit.Test)

Example 5 with Provisioning

use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.

the class EnvelopeTest method testTo_Alias.

@Test
public void testTo_Alias() {
    String filterScript = "require \"envelope\";\n" + "set \"rcptto\" \"unknown\";\n" + "if envelope :all :matches \"to\" \"*\" {\n" + "  set \"rcptto\" \"${1}\";\n" + "  tag \"${rcptto}\";\n" + "}\n" + "if envelope :all :matches \"to\" \"alias1*\" {\n" + "  tag \"${1}\";\n" + "}\n" + "if envelope :all :matches \"to\" \"alias2*\" {\n" + "  tag \"bad\";\n" + "}\n" + "if envelope :count \"eq\" :comparator \"i;ascii-numeric\" \"to\" \"1\" {" + "  tag \"1\";\n" + "}";
    LmtpEnvelope env = new LmtpEnvelope();
    LmtpAddress sender = new LmtpAddress("<tim@example.com>", new String[] { "BODY", "SIZE" }, null);
    LmtpAddress recipient = new LmtpAddress("<alias1@zimbra.com>", null, null);
    env.setSender(sender);
    env.addLocalRecipient(recipient);
    try {
        Provisioning prov = Provisioning.getInstance();
        Account account = prov.createAccount("original1@zimbra.com", "secret", new HashMap<String, Object>());
        RuleManager.clearCachedRules(account);
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        account.setAdminSieveScriptBefore(filterScript);
        account.setMail("original1@zimbra.com");
        String[] alias = { "alias1@zimbra.com", "alias2@zimbra.com" };
        account.setMailAlias(alias);
        List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(sampleMsg.getBytes(), false), 0, account.getName(), env, new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
        Assert.assertEquals(1, ids.size());
        Message msg = mbox.getMessageById(null, ids.get(0).getId());
        String[] tags = msg.getTags();
        Assert.assertTrue(tags != null);
        Assert.assertEquals(3, tags.length);
        Assert.assertEquals("alias1@zimbra.com", tags[0]);
        Assert.assertEquals("@zimbra.com", tags[1]);
        Assert.assertEquals("1", tags[2]);
    } catch (Exception e) {
        fail("No exception should be thrown:" + e);
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ItemId(com.zimbra.cs.service.util.ItemId) MockProvisioning(com.zimbra.cs.account.MockProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) Mailbox(com.zimbra.cs.mailbox.Mailbox) LmtpAddress(com.zimbra.cs.lmtpserver.LmtpAddress) LmtpEnvelope(com.zimbra.cs.lmtpserver.LmtpEnvelope) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) Test(org.junit.Test)

Aggregations

Provisioning (com.zimbra.cs.account.Provisioning)532 Account (com.zimbra.cs.account.Account)216 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)158 Element (com.zimbra.common.soap.Element)144 ServiceException (com.zimbra.common.service.ServiceException)96 BeforeClass (org.junit.BeforeClass)93 MockProvisioning (com.zimbra.cs.account.MockProvisioning)89 Server (com.zimbra.cs.account.Server)83 HashMap (java.util.HashMap)76 Domain (com.zimbra.cs.account.Domain)70 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)53 Mailbox (com.zimbra.cs.mailbox.Mailbox)50 Cos (com.zimbra.cs.account.Cos)32 Test (org.junit.Test)30 NamedEntry (com.zimbra.cs.account.NamedEntry)25 AuthToken (com.zimbra.cs.account.AuthToken)23 Group (com.zimbra.cs.account.Group)23 ArrayList (java.util.ArrayList)23 AccountServiceException (com.zimbra.cs.account.AccountServiceException)22 DistributionList (com.zimbra.cs.account.DistributionList)22