Search in sources :

Example 6 with EphemeralInput

use of com.zimbra.cs.ephemeral.EphemeralInput in project zm-mailbox by Zimbra.

the class MigrateAttributesTest method testErrorDuringMigration.

@Test
public void testErrorDuringMigration() throws Exception {
    List<EphemeralInput> results = new LinkedList<EphemeralInput>();
    EntrySource source = new DummyEntrySource(acct, acct, acct);
    Multimap<String, Object> deletedAttrs = LinkedListMultimap.create();
    List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
    DummyMigrationCallback callback = new DummyMigrationCallback(results, deletedAttrs);
    callback.throwErrorDuringMigration = true;
    AttributeMigration migration = new AttributeMigration(attrsToMigrate, source, callback, null);
    try {
        migration.migrateAllAccounts();
        fail("synchronous migration should throw an exception");
    } catch (ServiceException e) {
        //make sure the root exception got thrown
        assertTrue(e.getMessage().contains("Failure during migration"));
    }
    //make sure nothing got migrated
    assertEquals(0, results.size());
    migration = new AttributeMigration(attrsToMigrate, source, callback, 3);
    try {
        migration.migrateAllAccounts();
        fail("async migration should throw an exception");
    } catch (ServiceException e) {
        assertTrue(e.getMessage().contains("Failure during migration"));
    }
    assertEquals(0, results.size());
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) EphemeralInput(com.zimbra.cs.ephemeral.EphemeralInput) LinkedList(java.util.LinkedList) EntrySource(com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource) Test(org.junit.Test)

Example 7 with EphemeralInput

use of com.zimbra.cs.ephemeral.EphemeralInput in project zm-mailbox by Zimbra.

the class MigrateAttributesTest method testLastLogonTimestampMigrationTask.

/*
     * Test MigrationTask for last login timestamp
     */
@Test
public void testLastLogonTimestampMigrationTask() throws ServiceException {
    List<EphemeralInput> results = new LinkedList<EphemeralInput>();
    Map<String, AttributeConverter> converters = new HashMap<String, AttributeConverter>();
    converters.put(Provisioning.A_zimbraLastLogonTimestamp, new StringAttributeConverter());
    Multimap<String, Object> deletedAttrs = LinkedListMultimap.create();
    MigrationTask task = new MigrationTask(acct, converters, new DummyMigrationCallback(results, deletedAttrs), true);
    task.migrateAttributes();
    assertEquals(1, results.size());
    verifyLastLogonTimestampEphemeralInput(results.get(0), "currentdate");
    Collection<Object> deleted = deletedAttrs.asMap().get(Provisioning.A_zimbraLastLogonTimestamp);
    assertEquals(1, deleted.size());
    assertTrue(deleted.contains("currentdate"));
}
Also used : HashMap(java.util.HashMap) EphemeralInput(com.zimbra.cs.ephemeral.EphemeralInput) LinkedList(java.util.LinkedList) MigrationTask(com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationTask) Test(org.junit.Test)

Example 8 with EphemeralInput

use of com.zimbra.cs.ephemeral.EphemeralInput in project zm-mailbox by Zimbra.

the class AuthTokenConverter method convert.

@Override
public EphemeralInput convert(String attrName, Object ldapValue) {
    String ldapValueStr = (String) ldapValue;
    String[] parts = ldapValueStr.split("\\|");
    if (parts.length != 3) {
        ZimbraLog.ephemeral.warn("LDAP auth token %s cannot be parsed", ldapValueStr);
        return null;
    }
    String token = parts[0];
    Long expirationMillis;
    try {
        expirationMillis = Long.parseLong(parts[1]);
    } catch (NumberFormatException e) {
        ZimbraLog.ephemeral.warn("LDAP auth token %s does not have a valid expiration value", ldapValueStr);
        return null;
    }
    String serverVersion = parts[2];
    EphemeralKey key = new EphemeralKey(attrName, token);
    EphemeralInput input = new EphemeralInput(key, serverVersion);
    Expiration expiration = new AbsoluteExpiration(expirationMillis);
    input.setExpiration(expiration);
    return input;
}
Also used : EphemeralInput(com.zimbra.cs.ephemeral.EphemeralInput) AbsoluteExpiration(com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration) Expiration(com.zimbra.cs.ephemeral.EphemeralInput.Expiration) AbsoluteExpiration(com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration) EphemeralKey(com.zimbra.cs.ephemeral.EphemeralKey)

Aggregations

EphemeralInput (com.zimbra.cs.ephemeral.EphemeralInput)8 Test (org.junit.Test)6 LinkedList (java.util.LinkedList)5 MigrationTask (com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationTask)3 HashMap (java.util.HashMap)3 AbsoluteExpiration (com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration)2 Expiration (com.zimbra.cs.ephemeral.EphemeralInput.Expiration)2 EphemeralKey (com.zimbra.cs.ephemeral.EphemeralKey)2 EntrySource (com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource)2 ServiceException (com.zimbra.common.service.ServiceException)1 Account (com.zimbra.cs.account.Account)1 Provisioning (com.zimbra.cs.account.Provisioning)1