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");
}
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());
}
Aggregations