Search in sources :

Example 6 with CreateAccountRequest

use of com.zimbra.soap.admin.message.CreateAccountRequest in project zm-mailbox by Zimbra.

the class TestCookieReuse method testForgedNonCSRFAdminPost.

/**
     * Verify that we CANNOT make an admin POST request with a non-CSRF-enabled auth token if
     * the auth token has an associated CSRF token
     */
@Test
public void testForgedNonCSRFAdminPost() throws Exception {
    AuthToken at = AuthProvider.getAdminAuthToken();
    at.setCsrfTokenEnabled(false);
    CsrfUtil.generateCsrfToken(at.getAccountId(), at.getExpires(), new Random().nextInt() + 1, at);
    SoapTransport transport = TestUtil.getAdminSoapTransport();
    transport.setAuthToken(at.getEncoded());
    Map<String, Object> attrs = null;
    CreateAccountRequest request = new CreateAccountRequest(UNAUTHORIZED_USER, "test123", attrs);
    try {
        transport.invoke(JaxbUtil.jaxbToElement(request));
    } catch (ServiceException e) {
        Assert.assertEquals("should be catching AUTH EXPIRED here", ServiceException.AUTH_REQUIRED, e.getCode());
        return;
    }
    Assert.fail("should have caught an exception");
}
Also used : CreateAccountRequest(com.zimbra.soap.admin.message.CreateAccountRequest) Random(java.util.Random) ServiceException(com.zimbra.common.service.ServiceException) AuthToken(com.zimbra.cs.account.AuthToken) ZAuthToken(com.zimbra.common.auth.ZAuthToken) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 7 with CreateAccountRequest

use of com.zimbra.soap.admin.message.CreateAccountRequest in project zm-mailbox by Zimbra.

the class JaxbToElementTest method jaxbSubclassFixupTest.

/**
     * Check that @{link JaxbUtil.elementToJaxb} will accept XML where
     * JAXB expects various attributes that have been specified as elements.
     * Ensure that attributes in elements of superclasses are handled
     * In this case:
     *                  <a><n>attrName1</n></a>
     * should be recognised as meaning:
     *                  <a n="attrName1"></a>
     * @throws Exception
     */
@Test
public void jaxbSubclassFixupTest() throws Exception {
    Element rootElem = Element.XMLElement.mFactory.createElement(AdminConstants.CREATE_ACCOUNT_REQUEST);
    // JAXB Attribute E_NAME
    rootElem.addNonUniqueElement(AdminConstants.E_NAME).addText("acctName");
    // JAXB Attribute E_PASSWORD
    rootElem.addNonUniqueElement(AdminConstants.E_PASSWORD).addText("AcctPassword");
    // JAXB Element E_A ---> Attr (actually a List)
    Element a1 = rootElem.addNonUniqueElement(AdminConstants.E_A);
    // JAXB Attribute A_N
    a1.addNonUniqueElement(AdminConstants.A_N).addText("attrName1");
    // value can't be set when we've specified an attribute as an element
    CreateAccountRequest req = JaxbUtil.elementToJaxb(rootElem);
    Assert.assertEquals("Account name", "acctName", req.getName());
    Assert.assertEquals("Account Password", "AcctPassword", req.getPassword());
    List<Attr> attrs = req.getAttrs();
    Assert.assertEquals("Number of attrs", 1, attrs.size());
    Assert.assertEquals("attr 1 name", "attrName1", attrs.get(0).getKey());
    Assert.assertEquals("attr 1 value", "", attrs.get(0).getValue());
}
Also used : CreateAccountRequest(com.zimbra.soap.admin.message.CreateAccountRequest) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) JAXBElement(javax.xml.bind.JAXBElement) Attr(com.zimbra.soap.admin.type.Attr) Test(org.junit.Test)

Aggregations

CreateAccountRequest (com.zimbra.soap.admin.message.CreateAccountRequest)7 Test (org.junit.Test)5 CreateAccountResponse (com.zimbra.soap.admin.message.CreateAccountResponse)3 Attr (com.zimbra.soap.admin.type.Attr)3 ZAuthToken (com.zimbra.common.auth.ZAuthToken)2 ServiceException (com.zimbra.common.service.ServiceException)2 Element (com.zimbra.common.soap.Element)2 SoapTransport (com.zimbra.common.soap.SoapTransport)2 AuthToken (com.zimbra.cs.account.AuthToken)2 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)2 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)2 JSONElement (com.zimbra.common.soap.Element.JSONElement)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 Account (com.zimbra.cs.account.Account)1 Provisioning (com.zimbra.cs.account.Provisioning)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 AddAccountAliasRequest (com.zimbra.soap.admin.message.AddAccountAliasRequest)1 AddAccountAliasResponse (com.zimbra.soap.admin.message.AddAccountAliasResponse)1 AddDistributionListMemberRequest (com.zimbra.soap.admin.message.AddDistributionListMemberRequest)1