diff --git a/store/src/main/java/com/zimbra/cs/account/ZAttrAccount.java b/store/src/main/java/com/zimbra/cs/account/ZAttrAccount.java index 6864c70435d..371268e71d0 100644 --- a/store/src/main/java/com/zimbra/cs/account/ZAttrAccount.java +++ b/store/src/main/java/com/zimbra/cs/account/ZAttrAccount.java @@ -31,120 +31,6 @@ protected ZAttrAccount( ///// BEGIN-AUTO-GEN-REPLACE - /** - * - * @return amavisBlacklistSender, or null if unset - */ - @ZAttr(id=-1) - public String getAmavisBlacklistSender() { - return getAttr(ZAttrProvisioning.A_amavisBlacklistSender, null, true); - } - - /** - * - * @param amavisBlacklistSender new value - * @throws com.zimbra.common.service.ServiceException if error during update - */ - @ZAttr(id=-1) - public void setAmavisBlacklistSender(String amavisBlacklistSender) throws com.zimbra.common.service.ServiceException { - HashMap attrs = new HashMap<>(); - attrs.put(ZAttrProvisioning.A_amavisBlacklistSender, amavisBlacklistSender); - getProvisioning().modifyAttrs(this, attrs); - } - - /** - * - * @param amavisBlacklistSender new value - * @param attrs existing map to populate, or null to create a new map - * @return populated map to pass into Provisioning.modifyAttrs - */ - @ZAttr(id=-1) - public Map setAmavisBlacklistSender(String amavisBlacklistSender, Map attrs) { - if (attrs == null) attrs = new HashMap<>(); - attrs.put(ZAttrProvisioning.A_amavisBlacklistSender, amavisBlacklistSender); - return attrs; - } - - /** - * - * @throws com.zimbra.common.service.ServiceException if error during update - */ - @ZAttr(id=-1) - public void unsetAmavisBlacklistSender() throws com.zimbra.common.service.ServiceException { - HashMap attrs = new HashMap<>(); - attrs.put(ZAttrProvisioning.A_amavisBlacklistSender, ""); - getProvisioning().modifyAttrs(this, attrs); - } - - /** - * - * @param attrs existing map to populate, or null to create a new map - * @return populated map to pass into Provisioning.modifyAttrs - */ - @ZAttr(id=-1) - public Map unsetAmavisBlacklistSender(Map attrs) { - if (attrs == null) attrs = new HashMap<>(); - attrs.put(ZAttrProvisioning.A_amavisBlacklistSender, ""); - return attrs; - } - - /** - * - * @return amavisWhitelistSender, or null if unset - */ - @ZAttr(id=-1) - public String getAmavisWhitelistSender() { - return getAttr(ZAttrProvisioning.A_amavisWhitelistSender, null, true); - } - - /** - * - * @param amavisWhitelistSender new value - * @throws com.zimbra.common.service.ServiceException if error during update - */ - @ZAttr(id=-1) - public void setAmavisWhitelistSender(String amavisWhitelistSender) throws com.zimbra.common.service.ServiceException { - HashMap attrs = new HashMap<>(); - attrs.put(ZAttrProvisioning.A_amavisWhitelistSender, amavisWhitelistSender); - getProvisioning().modifyAttrs(this, attrs); - } - - /** - * - * @param amavisWhitelistSender new value - * @param attrs existing map to populate, or null to create a new map - * @return populated map to pass into Provisioning.modifyAttrs - */ - @ZAttr(id=-1) - public Map setAmavisWhitelistSender(String amavisWhitelistSender, Map attrs) { - if (attrs == null) attrs = new HashMap<>(); - attrs.put(ZAttrProvisioning.A_amavisWhitelistSender, amavisWhitelistSender); - return attrs; - } - - /** - * - * @throws com.zimbra.common.service.ServiceException if error during update - */ - @ZAttr(id=-1) - public void unsetAmavisWhitelistSender() throws com.zimbra.common.service.ServiceException { - HashMap attrs = new HashMap<>(); - attrs.put(ZAttrProvisioning.A_amavisWhitelistSender, ""); - getProvisioning().modifyAttrs(this, attrs); - } - - /** - * - * @param attrs existing map to populate, or null to create a new map - * @return populated map to pass into Provisioning.modifyAttrs - */ - @ZAttr(id=-1) - public Map unsetAmavisWhitelistSender(Map attrs) { - if (attrs == null) attrs = new HashMap<>(); - attrs.put(ZAttrProvisioning.A_amavisWhitelistSender, ""); - return attrs; - } - /** * RFC2256: ISO-3166 country 2-letter code * diff --git a/store/src/main/resources/conf/attrs/amavisd-new-attrs.xml b/store/src/main/resources/conf/attrs/amavisd-new-attrs.xml index 3eac70627e8..f8f03855f1b 100644 --- a/store/src/main/resources/conf/attrs/amavisd-new-attrs.xml +++ b/store/src/main/resources/conf/attrs/amavisd-new-attrs.xml @@ -22,9 +22,9 @@ - + - + diff --git a/store/src/test/java/com/zextras/mailbox/soap/SoapUtils.java b/store/src/test/java/com/zextras/mailbox/soap/SoapUtils.java index daf9a84b1ed..d20dec2a5ab 100644 --- a/store/src/test/java/com/zextras/mailbox/soap/SoapUtils.java +++ b/store/src/test/java/com/zextras/mailbox/soap/SoapUtils.java @@ -5,10 +5,11 @@ package com.zextras.mailbox.soap; import org.apache.http.HttpResponse; +import org.apache.http.util.EntityUtils; public class SoapUtils { public static String getResponse(HttpResponse response) throws Exception { - return new String (response.getEntity().getContent().readAllBytes()); + return EntityUtils.toString(response.getEntity()); } } diff --git a/store/src/test/java/com/zextras/mailbox/util/SoapClient.java b/store/src/test/java/com/zextras/mailbox/util/SoapClient.java index 7bd4158d840..a84e8975652 100644 --- a/store/src/test/java/com/zextras/mailbox/util/SoapClient.java +++ b/store/src/test/java/com/zextras/mailbox/util/SoapClient.java @@ -10,27 +10,23 @@ import com.zimbra.common.util.ZimbraCookie; import com.zimbra.cs.account.Account; import com.zimbra.cs.account.AuthToken; +import com.zimbra.cs.account.AuthTokenException; import com.zimbra.cs.service.AuthProvider; import com.zimbra.soap.JaxbUtil; import java.net.URI; import java.util.Objects; import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.BasicCookieStore; -import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.cookie.BasicClientCookie; -/** - * A SoapClient that wraps the Body in an Envelope. - * - */ +/** A SoapClient that wraps the Body in an Envelope. */ public class SoapClient { - /** - * Endpoint in form of http://:/ - */ + /** Endpoint in form of http://:/ */ private String endpoint; public SoapClient(String endpoint) { @@ -70,6 +66,26 @@ public Request setRequestedAccount(Account requestedAccount) { private String url = "/"; public HttpResponse execute() throws Exception { + final var cookieStore = createCookieAuthToken(); + HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build(); + final HttpPost httpPost = new HttpPost(); + Element envelope; + if (Objects.isNull(requestedAccount)) { + envelope = SoapProtocol.Soap12.soapEnvelope(soapBody); + } else { + final Element headerXml = + Element.parseXML( + String.format( + "%s", + requestedAccount.getId())); + envelope = SoapProtocol.Soap12.soapEnvelope(soapBody, headerXml); + } + httpPost.setURI(URI.create(this.url)); + httpPost.setEntity(new StringEntity(envelope.toString())); + return client.execute(httpPost); + } + + private BasicCookieStore createCookieAuthToken() throws AuthTokenException, ServiceException { AuthToken authToken = AuthProvider.getAuthToken(caller, isAdminAccount()); BasicCookieStore cookieStore = new BasicCookieStore(); BasicClientCookie cookie = @@ -77,22 +93,7 @@ public HttpResponse execute() throws Exception { cookie.setDomain(caller.getServerName()); cookie.setPath("/"); cookieStore.addCookie(cookie); - try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore) - .build()) { - final HttpPost httpPost = new HttpPost(); - Element envelope; - if (Objects.isNull(requestedAccount)) { - envelope = SoapProtocol.Soap12.soapEnvelope(soapBody); - } else { - final Element headerXml = Element.parseXML(String.format( - "%s", - requestedAccount.getId())); - envelope = SoapProtocol.Soap12.soapEnvelope(soapBody, headerXml); - } - httpPost.setURI(URI.create(this.url)); - httpPost.setEntity(new StringEntity(envelope.toString())); - return client.execute(httpPost); - } + return cookieStore; } private boolean isAdminAccount() { @@ -113,7 +114,7 @@ public Request newRequest() { * @throws Exception */ public HttpResponse executeSoap(Account account, Element soapBody) throws Exception { - return newRequest().setCaller(account).setSoapBody(soapBody).execute(); + return newRequest().setCaller(account).setSoapBody(soapBody).execute(); } /** @@ -125,6 +126,4 @@ public HttpResponse executeSoap(Account account, Element soapBody) throws Except public HttpResponse executeSoap(Account account, Object soapBodyPOJO) throws Exception { return executeSoap(account, JaxbUtil.jaxbToElement(soapBodyPOJO)); } - - } diff --git a/store/src/test/java/com/zimbra/cs/service/account/GetInfoTest.java b/store/src/test/java/com/zimbra/cs/service/account/GetInfoTest.java new file mode 100644 index 00000000000..efd4cb9e48c --- /dev/null +++ b/store/src/test/java/com/zimbra/cs/service/account/GetInfoTest.java @@ -0,0 +1,85 @@ +package com.zimbra.cs.service.account; + +import static org.junit.jupiter.api.Assertions.*; + +import com.zextras.mailbox.soap.SoapTestSuite; +import com.zextras.mailbox.util.MailboxTestUtil; +import com.zimbra.common.account.ZAttrProvisioning; +import com.zimbra.cs.account.Account; +import com.zimbra.cs.account.Provisioning; +import com.zimbra.soap.account.message.GetInfoRequest; +import org.apache.http.HttpStatus; +import org.apache.http.util.EntityUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +@Tag("api") +class GetInfoTest extends SoapTestSuite { + + private static MailboxTestUtil.AccountCreator.Factory accountCreatorFactory; + private static Provisioning provisioning; + private Account account; + + @BeforeAll + static void init() throws Exception { + provisioning = Provisioning.getInstance(); + accountCreatorFactory = new MailboxTestUtil.AccountCreator.Factory(provisioning); + } + + @BeforeEach + void setUp() throws Exception { + account = accountCreatorFactory.get().create(); + } + + @Test + void getAllSections() throws Exception { + final var request = new GetInfoRequest(); + + final var response = getSoapClient().executeSoap(account, request); + + assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); + } + + @ParameterizedTest + @ValueSource( + strings = { + "mbox", + "prefs", + "attrs", + "zimlets", + "props", + "idents", + "sigs", + "dsrcs", + "children" + }) + void getSpecificSection(String section) throws Exception { + final var request = new GetInfoRequest().addSection(section); + + final var response = getSoapClient().executeSoap(account, request); + + assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); + } + + @Test + void attributesSectionProvidesAmavisLists() throws Exception { + final var account = + accountCreatorFactory + .get() + .withAttribute(ZAttrProvisioning.A_amavisWhitelistSender, "foo1@bar.com") + .withAttribute(ZAttrProvisioning.A_amavisBlacklistSender, "foo2@bar.com") + .create(); + final var request = new GetInfoRequest().addSection("attrs"); + + final var response = getSoapClient().executeSoap(account, request); + + assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); + final var body = EntityUtils.toString(response.getEntity()); + assertTrue(body.contains("amavisWhitelistSender")); + assertTrue(body.contains("amavisBlacklistSender")); + } +}