use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestLdapProvRenameDomain method verifyEntries.
/*
* verify all expected entries are in the domain and the domain only contains these entries
*/
private void verifyEntries(int domainIdx, Domain domain) throws Exception {
// get all the entries reside in the domain
SearchDirectoryOptions options = new SearchDirectoryOptions();
options.setTypes(SearchDirectoryOptions.ObjectType.accounts, SearchDirectoryOptions.ObjectType.distributionlists, SearchDirectoryOptions.ObjectType.dynamicgroups);
options.setDomain(domain);
options.setFilterString(FilterId.UNITTEST, null);
List<NamedEntry> list = prov.searchDirectory(options);
// come up with all expected entries
Set<String> expectedEntries = new HashSet<String>();
for (int a = 0; a < NUM_ACCOUNTS; a++) {
Names.IDNName name = new Names.IDNName(ACCOUNT_NAME(a, domainIdx));
Account entry = prov.get(Key.AccountBy.name, name.uName());
assertNotNull(entry);
expectedEntries.add(name.uName());
}
for (int nd = 0; nd < NUM_DLS_NESTED; nd++) {
Names.IDNName name = new Names.IDNName(NESTED_DL_NAME(nd, domainIdx));
DistributionList entry = prov.get(Key.DistributionListBy.name, name.uName());
assertNotNull(entry);
expectedEntries.add(name.uName());
}
for (int td = 0; td < NUM_DLS_TOP; td++) {
Names.IDNName name = new Names.IDNName(TOP_DL_NAME(td, domainIdx));
DistributionList entry = prov.get(Key.DistributionListBy.name, name.uName());
assertNotNull(entry);
expectedEntries.add(name.uName());
}
for (int td = 0; td < NUM_DYNAMIC_GROUPS; td++) {
Names.IDNName name = new Names.IDNName(DYNAMIC_GROUP_NAME(td, domainIdx));
DynamicGroup entry = (DynamicGroup) prov.getGroup(Key.DistributionListBy.name, name.uName());
assertNotNull(entry);
expectedEntries.add(name.uName());
}
// verify all our aliases are there
Set<String> actualEntries = namedEntryListToNameSet(list, UnicodeOrACE.UNICODE);
dumpStrings("expectedEntries", expectedEntries);
dumpStrings("actualEntries", actualEntries);
Verify.verifyEquals(expectedEntries, actualEntries);
verifyEntryAttrs(list, domain);
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestLdapProvRenameDomain method verifyAliasesOfEntriesInDomain.
/*
* verify aliases of entries in a domain
*/
private void verifyAliasesOfEntriesInDomain(int objType, Domain domain) throws Exception {
/*
* verify the account aliases
*/
for (int i = 0; i < NUM_OBJS(objType); i++) {
// get the the entry by main name
String entryName = OBJ_NAME(objType, i, NEW_DOMAIN);
NamedEntry entry = getEntryByName(objType, entryName);
assertNotNull(entry);
// get the entry by its aliases
for (int d = 0; d < NUM_DOMAINS; d++) {
int aliasDomainIdx = DOMAIN_INDEX_AFTER_RENAME(d);
String aliasName = GET_ALIAS_NAME(objType, i, OLD_DOMAIN, aliasDomainIdx);
NamedEntry entryByAlias = getEntryByName(objType, aliasName);
assertNotNull(entryByAlias);
Verify.verifySameEntry(entry, entryByAlias);
}
}
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestLdapProvRenameDomain method verifyDomainAliases.
/*
* verify all aliases in the domain
*/
private void verifyDomainAliases(int domainIdx, Domain domain) throws Exception {
// get all the aliases reside in the domain
SearchDirectoryOptions options = new SearchDirectoryOptions();
options.setTypes(SearchDirectoryOptions.ObjectType.aliases);
options.setDomain(domain);
options.setFilterString(FilterId.UNITTEST, null);
List<NamedEntry> list = prov.searchDirectory(options);
// come up with all expected aliases
Set<String> expectedAliases = new HashSet<String>();
for (int d = 0; d < NUM_DOMAINS; d++) {
for (int a = 0; a < NUM_ACCOUNTS; a++) expectedAliases.add(new Names.IDNName(ACCOUNT_ALIAS_NAME(a, d, domainIdx)).uName());
for (int nd = 0; nd < NUM_DLS_NESTED; nd++) expectedAliases.add(new Names.IDNName(NESTED_DL_ALIAS_NAME(nd, d, domainIdx)).uName());
for (int td = 0; td < NUM_DLS_TOP; td++) expectedAliases.add(new Names.IDNName(TOP_DL_ALIAS_NAME(td, d, domainIdx)).uName());
for (int dg = 0; dg < NUM_DYNAMIC_GROUPS; dg++) expectedAliases.add(new Names.IDNName(DYNAMIC_GROUP_ALIAS_NAME(dg, d, domainIdx)).uName());
}
// verify all our aliases are there
Set<String> actualAliases = namedEntryListToNameSet(list, UnicodeOrACE.UNICODE);
// dumpStrings(expectedAliases);
// dumpStrings(actualAliases);
Verify.verifyEquals(expectedAliases, actualAliases);
// verify the target of each alias can be found
for (NamedEntry entry : list) {
assertTrue(entry instanceof Alias);
NamedEntry target = prov.searchAliasTarget((Alias) entry, true);
assertNotNull(target);
}
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestProvAlias method testRemoveAlias_entryNotExist_aliasExist_aliasPointToOtherEntry.
//
// C - alias points to other existing entry
//
@Test
public void testRemoveAlias_entryNotExist_aliasExist_aliasPointToOtherEntry() throws Exception {
String testName = getTestName();
// create the domain
String domainName = "EN-AE-aliasPointToOtherEntry" + "." + BASE_DOMAIN_NAME;
domainName = domainName.toLowerCase();
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraDomainType, Provisioning.DomainType.local.name());
Domain domain = prov.createDomain(domainName, attrs);
// create the account the alias points to
String acctName = getEmail("acct-1", domainName);
Account acct = prov.createAccount(acctName, PASSWORD, new HashMap<String, Object>());
// add an alias to the account
String aliasName = getEmail("alias-1", domainName);
prov.addAlias(acct, aliasName);
// create 2 DLs
String dl1Name = getEmail("dl-1", domainName);
DistributionList dl1 = prov.createDistributionList(dl1Name, new HashMap<String, Object>());
String dl2Name = getEmail("dl-2", domainName);
DistributionList dl2 = prov.createDistributionList(dl2Name, new HashMap<String, Object>());
// add the alias to the two DLs
prov.addMembers(dl1, new String[] { aliasName });
prov.addMembers(dl2, new String[] { aliasName });
// non-existing entry account
Account nonExistingAcct = null;
// remove the alias, on a "not found" account, and the alias is pointing to another existing target
// we should *not* get the NO_SUCH_ALIAS exception
prov.removeAlias(nonExistingAcct, aliasName);
// reload all entries
prov.reload(acct);
prov.reload(dl1);
prov.reload(dl2);
Set<String> values;
// ensure the alias is still on the account
values = acct.getMultiAttrSet(Provisioning.A_mail);
assertTrue(values.contains(aliasName));
values = acct.getMultiAttrSet(Provisioning.A_zimbraMailAlias);
assertTrue(values.contains(aliasName));
// ensure the alias is *not* removed from any the DLs
values = dl1.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
assertTrue(values.contains(aliasName));
values = dl2.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
assertTrue(values.contains(aliasName));
// ensure the alias entry is *not* removed
List<NamedEntry> aliases = searchAliasesInDomain(domain);
assertEquals(aliases.size(), 1);
assertTrue(aliases.get(0).getName().equals(aliasName));
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestProvAlias method testRemoveAlias_entryExist_aliasExist_aliasPointToEntry.
/*
* test removing alias
*
* 1. remove alias from mail and zimbraMailAlias attributes of the entry
* 2. remove alias from all distribution lists
* 3. delete the alias entry
*
* A. entry exists, alias exists
* - if alias points to the entry: do 1, 2, 3
* - if alias points to other existing entry: do 1, and then throw NO_SUCH_ALIAS
* - if alias points to a non-existing entry: do 1, 2, 3, and then throw NO_SUCH_ALIAS
*
* B. entry exists, alias does not exist: do 1, 2, and then throw NO_SUCH_ALIAS
*
* C. entry does not exist, alias exists:
* - if alias points to other existing entry: do nothing (and then throw NO_SUCH_ACCOUNT/NO_SUCH_DISTRIBUTION_LIST in ProvUtil)
* - if alias points to a non-existing entry: do 2, 3 (and then throw NO_SUCH_ACCOUNT/NO_SUCH_DISTRIBUTION_LIST in ProvUtil)
*
* D. entry does not exist, alias does not exist: do 2 (and then throw NO_SUCH_ACCOUNT/NO_SUCH_DISTRIBUTION_LIST in ProvUtil)
*
*
*/
//
// A - alias points to the entry
//
@Test
public void testRemoveAlias_entryExist_aliasExist_aliasPointToEntry() throws Exception {
// getTestName retusn all lower case. This avoids the bug that we don't convert
// an address to lower case when it is added as a DL member, and later the address
// can't be removed from the DL because case does not match.
String testName = getTestName();
// create the domain
String domainName = "EE-AE-aliasPointToEntry" + "." + BASE_DOMAIN_NAME;
domainName = domainName.toLowerCase();
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraDomainType, Provisioning.DomainType.local.name());
Domain domain = prov.createDomain(domainName, attrs);
// create the account
String acctName = getEmail("acct-1", domainName);
Account acct = prov.createAccount(acctName, PASSWORD, new HashMap<String, Object>());
// add an alias to the account
String aliasName = getEmail("alias-1", domainName);
prov.addAlias(acct, aliasName);
// create 2 DLs
String dl1Name = getEmail("dl-1", domainName);
DistributionList dl1 = prov.createDistributionList(dl1Name, new HashMap<String, Object>());
String dl2Name = getEmail("dl-2", domainName);
DistributionList dl2 = prov.createDistributionList(dl2Name, new HashMap<String, Object>());
// add the alias to the two DLs
prov.addMembers(dl1, new String[] { aliasName });
prov.addMembers(dl2, new String[] { aliasName });
// remove the alias
prov.removeAlias(acct, aliasName);
// reload all entries
prov.reload(acct);
prov.reload(dl1);
prov.reload(dl2);
Set<String> values;
// ensure the alias is removed from the account's mail/zimbraMailAlias attrs
values = acct.getMultiAttrSet(Provisioning.A_mail);
assertFalse(values.contains(aliasName));
values = acct.getMultiAttrSet(Provisioning.A_zimbraMailAlias);
assertFalse(values.contains(aliasName));
// ensure the alias is removed from all the DLs
values = dl1.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
assertFalse(values.contains(aliasName));
values = dl2.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
assertFalse(values.contains(aliasName));
// ensure the alias entry is removed
List<NamedEntry> aliases = searchAliasesInDomain(domain);
assertEquals(aliases.size(), 0);
}
Aggregations