|
9 | 9 | import com.zimbra.cs.account.Account; |
10 | 10 | import com.zimbra.cs.account.AttributeInfo; |
11 | 11 | import com.zimbra.cs.account.AttributeManager; |
| 12 | +import com.zimbra.cs.account.DistributionList; |
12 | 13 | import com.zimbra.cs.account.Provisioning; |
| 14 | +import com.zimbra.soap.account.message.DistributionListActionRequest; |
13 | 15 | import com.zimbra.soap.account.message.GetInfoRequest; |
| 16 | + |
| 17 | +import java.util.HashMap; |
14 | 18 | import java.util.List; |
| 19 | + |
| 20 | +import com.zimbra.soap.account.type.DistributionListAction; |
| 21 | +import com.zimbra.soap.account.type.DistributionListGranteeSelector; |
| 22 | +import com.zimbra.soap.account.type.DistributionListRightSpec; |
| 23 | +import com.zimbra.soap.type.DistributionListBy; |
| 24 | +import com.zimbra.soap.type.DistributionListGranteeBy; |
| 25 | +import com.zimbra.soap.type.DistributionListSelector; |
| 26 | +import com.zimbra.soap.type.GranteeType; |
15 | 27 | import org.apache.http.HttpStatus; |
16 | 28 | import org.junit.jupiter.api.Assertions; |
17 | | - import org.junit.jupiter.api.BeforeEach; |
| 29 | +import org.junit.jupiter.api.BeforeEach; |
18 | 30 | import org.junit.jupiter.api.Tag; |
19 | 31 | import org.junit.jupiter.api.Test; |
20 | 32 | import org.junit.jupiter.params.ParameterizedTest; |
@@ -98,6 +110,11 @@ private SoapResponse getAttributesSection(Account account) throws Exception { |
98 | 110 | return getSoapClient().executeSoap(account, request); |
99 | 111 | } |
100 | 112 |
|
| 113 | + private SoapResponse getResponseIncludingRights(Account account) throws Exception { |
| 114 | + final var request = new GetInfoRequest().setRights("sendAs","sendAsDistList","viewFreeBusy","sendOnBehalfOf","sendOnBehalfOfDistList"); |
| 115 | + return getSoapClient().executeSoap(account, request); |
| 116 | + } |
| 117 | + |
101 | 118 | @Test |
102 | 119 | void attributesSectionProvidesAccountStatusAttribute() throws Exception { |
103 | 120 | final var account = |
@@ -125,6 +142,75 @@ void getInfo_shouldReturnAlsoDeprecatedAttributes() throws Exception { |
125 | 142 | final var body = response.body(); |
126 | 143 | assertTrue(body.contains("<attr name=\"zimbraFeatureMailEnabled\">FALSE</attr>")); |
127 | 144 | } |
| 145 | + |
| 146 | + @Test |
| 147 | + void getInfo_shouldContainRightsSection_sendAsDistList_singleAccount() throws Exception { |
| 148 | + final var admin = createAccount().asGlobalAdmin().create(); |
| 149 | + final var grantee = createAccount().create(); |
| 150 | + |
| 151 | + var dl = getProvisioning().createDistributionList("dl@test.com", new HashMap<>()); |
| 152 | + getSoapClient().executeSoap(admin, createGrantRightsDistributionListActionRequest("sendAsDistList", grantee.getName(), dl)); |
| 153 | + final var response = getResponseIncludingRights(grantee); |
| 154 | + |
| 155 | + assertEquals(HttpStatus.SC_OK, response.statusCode()); |
| 156 | + final var body = response.body(); |
| 157 | + |
| 158 | + assertTrue(body.contains(""" |
| 159 | + <rights><targets right="sendAsDistList"><target type="dl"><email addr="dl@test.com"/></target></targets></rights>""")); |
| 160 | + } |
| 161 | + |
| 162 | + @Test |
| 163 | + void getInfo_shouldContainRightsSection_sendAsDistList_distributionList() throws Exception { |
| 164 | + final var admin = createAccount().asGlobalAdmin().create(); |
| 165 | + final var member = createAccount().create(); |
| 166 | + |
| 167 | + var targetDl = getProvisioning().createDistributionList("target-dl@test.com", new HashMap<>()); |
| 168 | + var granteeDl = getProvisioning().createDistributionList("grantee-dl@test.com", new HashMap<>()); |
| 169 | + |
| 170 | + getProvisioning().addGroupMembers(granteeDl, new String[] { member.getName() }); |
| 171 | + getSoapClient().executeSoap(admin, createGrantRightsDistributionListActionRequest("sendAsDistList", granteeDl.getName(), targetDl)); |
| 172 | + |
| 173 | + final var response = getResponseIncludingRights(member); |
| 174 | + |
| 175 | + assertEquals(HttpStatus.SC_OK, response.statusCode()); |
| 176 | + final var body = response.body(); |
| 177 | + |
| 178 | + assertTrue(body.contains(""" |
| 179 | + <rights><targets right="sendAsDistList"><target type="dl"><email addr="target-dl@test.com"/></target></targets></rights>""")); |
| 180 | + } |
| 181 | + |
| 182 | + @Test |
| 183 | + void getInfo_shouldContainRightsSection_sendAsDistList_distributionLists() throws Exception { |
| 184 | + final var admin = createAccount().asGlobalAdmin().create(); |
| 185 | + final var member = createAccount().create(); |
| 186 | + |
| 187 | + var targetDl = getProvisioning().createDistributionList("target-1-dl@test.com", new HashMap<>()); |
| 188 | + var granteeDl = getProvisioning().createDistributionList("grantee-1-dl@test.com", new HashMap<>()); |
| 189 | + var otherGranteeDl = getProvisioning().createDistributionList("other-grantee-1-dl@test.com", new HashMap<>()); |
| 190 | + |
| 191 | + getProvisioning().addGroupMembers(granteeDl, new String[] { member.getName() }); |
| 192 | + |
| 193 | + getSoapClient().executeSoap(admin, createGrantRightsDistributionListActionRequest("sendAsDistList", granteeDl.getName(), targetDl)); |
| 194 | + getSoapClient().executeSoap(admin, createGrantRightsDistributionListActionRequest("sendOnBehalfOfDistList", otherGranteeDl.getName(), targetDl)); |
| 195 | + |
| 196 | + final var response = getResponseIncludingRights(member); |
| 197 | + |
| 198 | + assertEquals(HttpStatus.SC_OK, response.statusCode()); |
| 199 | + final var body = response.body(); |
| 200 | + |
| 201 | + assertTrue(body.contains(""" |
| 202 | + <rights><targets right="sendAsDistList"><target type="dl"><email addr="target-1-dl@test.com"/></target></targets></rights>""")); |
| 203 | + } |
| 204 | + |
| 205 | + private static DistributionListActionRequest createGrantRightsDistributionListActionRequest(String right, String granteeName, DistributionList targetDl) { |
| 206 | + DistributionListAction distributionListAction = new DistributionListAction(DistributionListAction.Operation.grantRights); |
| 207 | + DistributionListRightSpec distributionListRightSpec = new DistributionListRightSpec(right); |
| 208 | + distributionListRightSpec.addGrantee(new DistributionListGranteeSelector( |
| 209 | + GranteeType.email, DistributionListGranteeBy.name, granteeName |
| 210 | + )); |
| 211 | + distributionListAction.setRights(List.of(distributionListRightSpec)); |
| 212 | + return new DistributionListActionRequest(new DistributionListSelector(DistributionListBy.id, targetDl.getId()), distributionListAction); |
| 213 | + } |
128 | 214 | } |
129 | 215 |
|
130 | 216 |
|
|
0 commit comments