use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class TestDistListACL method testMilterExternalDomainSendToDL.
/**
* "edom" GranteeType testing. Check that a sender whose address has a domain which matches the
* external domain will be able to send to the DL
*/
@Test
public void testMilterExternalDomainSendToDL() throws Exception {
DistributionList dl = prov.createDistributionList(listAddress, new HashMap<String, Object>());
String user1email = TestUtil.getAddress(USER_NAME);
prov.grantRight("dl", TargetBy.name, listAddress, GranteeType.GT_EXT_DOMAIN.getCode(), GranteeBy.name, "example.test", null, /* secret */
RightConsts.RT_sendToDistList, (RightModifier) null);
ZimbraLog.test.info("DL name %s ID %s", dl.getName(), dl.getId());
Group group = prov.getGroupBasic(Key.DistributionListBy.name, listAddress);
Assert.assertNotNull("Unable to find Group object for DL by name", group);
Assert.assertTrue("pete@example.test should be able to send to DL (in domain example.test)", accessMgr.canDo("pete@example.test", group, User.R_sendToDistList, false));
Assert.assertFalse(String.format("%s should NOT be able to send to DL (in domain example.test)", user1email), accessMgr.canDo(user1email, group, User.R_sendToDistList, false));
}
use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class TestDistListACL method doCheckSentToDistListUserRight.
private void doCheckSentToDistListUserRight(DistributionList targetDl, String email, String user, boolean expected) throws ServiceException {
ZimbraLog.test.info("DL name %s ID %s", targetDl.getName(), targetDl.getId());
Group group = prov.getGroupBasic(Key.DistributionListBy.name, listAddress);
Assert.assertNotNull("Unable to find Group object for DL by name", group);
AccessManager.ViaGrant via = new AccessManager.ViaGrant();
// More permissive that GT_USER - want to test called functions
NamedEntry ne = GranteeType.lookupGrantee(prov, GranteeType.GT_EMAIL, GranteeBy.name, email);
MailTarget grantee = null;
if (ne instanceof MailTarget) {
grantee = (MailTarget) ne;
}
boolean result = RightCommand.checkRight(prov, "dl", /* targetType */
TargetBy.name, listAddress, grantee, RightConsts.RT_sendToDistList, null, /* attrs */
via);
if (expected) {
Assert.assertTrue(String.format("%s should be able to send to DL (as user %s)", email, user), accessMgr.canDo(email, group, User.R_sendToDistList, false));
Assert.assertTrue(String.format("%s should have right to send to DL (as user %s)", email, user), result);
ZimbraLog.test.info("Test for %s against dom %s Via=%s", email, user, via);
} else {
Assert.assertFalse(String.format("%s should NOT be able to send to DL (because not user %s)", email, user), accessMgr.canDo(email, group, User.R_sendToDistList, false));
Assert.assertFalse(String.format("%s should NOT have right to send to DL (because not user %s)", email, user), result);
}
}
use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class TestGetInfo method discoverRights.
@Test
public void discoverRights() throws Exception {
Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
Group group = provUtil.createGroup(genGroupNameLocalPart(), domain, false);
prov.grantRight(TargetType.domain.getCode(), TargetBy.name, domain.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, User.R_createDistList.getName(), null);
prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, User.R_sendToDistList.getName(), null);
SoapTransport transport = authUser(acct.getName());
GetInfoRequest req = new GetInfoRequest();
req.addRight(User.R_createDistList.getName());
req.addRight(User.R_sendToDistList.getName());
GetInfoResponse resp = invokeJaxb(transport, req);
List<DiscoverRightsInfo> rightsInfo = resp.getDiscoveredRights();
Set<String> result = Sets.newHashSet();
for (DiscoverRightsInfo rightInfo : rightsInfo) {
String right = rightInfo.getRight();
List<DiscoverRightsTarget> targets = rightInfo.getTargets();
for (DiscoverRightsTarget target : targets) {
String id = target.getId();
String name = target.getName();
String type = target.getType().toString();
result.add(Verify.makeResultStr(right, id, name, type));
}
}
Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(User.R_createDistList.getName(), domain.getId(), domain.getName(), TargetType.domain.getCode()), Verify.makeResultStr(User.R_sendToDistList.getName(), group.getId(), group.getName(), TargetType.dl.getCode())), result);
}
use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class TestDelegatedDL method ownerIsGroup.
/*
* owner of a group is a group
*/
@Test
public void ownerIsGroup() throws Exception {
Group ownedGroup = provUtil.createGroup(genGroupNameLocalPart("owned"), domain, DYNAMIC);
Group owningGroup = provUtil.createGroup(genGroupNameLocalPart("owning"), domain, DYNAMIC);
/*
* add members to owning group
*/
Account acctInOwningGroup = provUtil.createAccount("acctInOwningGroup", domain);
prov.addGroupMembers(owningGroup, new String[] { acctInOwningGroup.getName() });
/*
* grant ownDistList right to owningGroup on ownedGroup
*/
prov.grantRight(TargetType.dl.getCode(), TargetBy.name, ownedGroup.getName(), GranteeType.GT_GROUP.getCode(), GranteeBy.name, owningGroup.getName(), null, Group.GroupOwner.GROUP_OWNER_RIGHT.getName(), null);
/*
* auth as acctInOwningGroup
*/
SoapTransport transport = authUser(acctInOwningGroup.getName());
/*
* try to add member in ownedGroup
*/
// addMembers
DistributionListAction action = new DistributionListAction(Operation.addMembers);
DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(ownedGroup.getName()), action);
String MEMBER1 = "member1@test.com";
String MEMBER2 = "member2@test.com";
action.addMember(MEMBER1);
action.addMember(MEMBER2);
DistributionListActionResponse resp = invokeJaxb(transport, req);
Group group = prov.getGroup(Key.DistributionListBy.name, ownedGroup.getName());
Set<String> members = group.getAllMembersSet();
assertEquals(2, members.size());
assertTrue(members.contains(MEMBER1));
assertTrue(members.contains(MEMBER2));
provUtil.deleteAccount(acctInOwningGroup);
provUtil.deleteGroup(owningGroup);
provUtil.deleteGroup(ownedGroup);
}
use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class TestDelegatedDL method distributionListActionSetBadOwners.
@Test
@Bug(bug = 72791)
public void distributionListActionSetBadOwners() throws Exception {
String GROUP_NAME = getAddress(genGroupNameLocalPart());
Group group = createGroupAndAddOwner(GROUP_NAME);
Account owner1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
Account owner2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
Account owner3 = provUtil.createAccount(genAcctNameLocalPart("3"), domain);
SoapTransport transport = authUser(USER_OWNER);
//
// setOwners: some good owners an a bogus owner (not a user)
//
DistributionListAction action = new DistributionListAction(Operation.setOwners);
DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, USER_OWNER));
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner1.getName()));
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner2.getName()));
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner3.getName()));
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, "bogus@bogus.com"));
String errorCode = null;
try {
DistributionListActionResponse resp = invokeJaxb(transport, req);
} catch (ServiceException e) {
errorCode = e.getCode();
}
assertEquals(AccountServiceException.NO_SUCH_ACCOUNT, errorCode);
//
// verify owners are NOT replaced
//
GetDistributionListRequest getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.TRUE);
GetDistributionListResponse getDLResp = invokeJaxb(transport, getDLReq);
DistributionListInfo dlInfo = getDLResp.getDl();
List<? extends DistributionListGranteeInfoInterface> owners = dlInfo.getOwners();
Set<String> ownerNames = Sets.newHashSet();
for (DistributionListGranteeInfoInterface owner : owners) {
if (owner.getType() == com.zimbra.soap.type.GranteeType.usr) {
ownerNames.add(owner.getName());
}
}
assertEquals(1, owners.size());
Verify.verifyEquals(Sets.newHashSet(USER_OWNER), ownerNames);
}
Aggregations