use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestSearchGalGroups method testSearchGroup.
/*
* Verify isOwner and isMember flags are returned correctly.
*/
private void testSearchGroup(Account acct, Group group, Boolean needIsOwner, MemberOfSelector needIsMember, boolean actualIsOwner, boolean actualIsMember) throws Exception {
SoapTransport transport = authUser(acct.getName());
SearchGalRequest req = new SearchGalRequest();
req.setName(group.getName());
req.setNeedIsOwner(needIsOwner);
req.setNeedIsMember(needIsMember);
SearchGalResponse resp = invokeJaxb(transport, req);
List<String> result = Lists.newArrayList();
List<String> expected = Lists.newArrayList(Verify.makeResultStr(group.getName(), ContactConstants.TYPE_GROUP, needIsOwner == null ? null : actualIsOwner, needIsMember == null ? null : actualIsMember, ZAttrProvisioning.DistributionListSubscriptionPolicy.ACCEPT.name()));
List<ContactInfo> entries = resp.getContacts();
for (ContactInfo entry : entries) {
List<ContactAttr> attrs = entry.getAttrs();
String email = null;
String type = null;
String subsPolicy = null;
for (ContactAttr attr : attrs) {
String key = attr.getKey();
if (ContactConstants.A_email.equals(key)) {
email = attr.getValue();
} else if (ContactConstants.A_type.equals(key)) {
type = attr.getValue();
} else if (Provisioning.A_zimbraDistributionListSubscriptionPolicy.equals(key)) {
subsPolicy = attr.getValue();
}
}
Boolean isOwner = entry.isOwner();
Boolean isMember = entry.isMember();
result.add(Verify.makeResultStr(email, type, isOwner, isMember, subsPolicy));
}
Verify.verifyEquals(expected, result);
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestAuth method accountStatusMaintenanceAfterAuth.
@Test
public void accountStatusMaintenanceAfterAuth() throws Exception {
Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
SoapTransport transport = authUser(acct.getName());
/*
* change account status to maintenance
*/
prov.modifyAccountStatus(acct, AccountStatus.maintenance.name());
GetInfoRequest req = new GetInfoRequest();
String errorCode = null;
try {
GetInfoResponse resp = invokeJaxb(transport, req);
} catch (SoapFaultException e) {
errorCode = e.getCode();
}
assertEquals(AccountServiceException.AUTH_EXPIRED, errorCode);
provUtil.deleteAccount(acct);
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestAuth method accountStatusMaintenance.
@Test
public void accountStatusMaintenance() throws Exception {
Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain, Collections.singletonMap(Provisioning.A_zimbraAccountStatus, (Object) AccountStatus.maintenance.name()));
String errorCode = null;
try {
SoapTransport transport = authUser(acct.getName());
} catch (SoapFaultException e) {
errorCode = e.getCode();
}
assertEquals(AccountServiceException.MAINTENANCE_MODE, errorCode);
provUtil.deleteAccount(acct);
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestAuth method clearCookie.
@Test
public void clearCookie() throws Exception {
// 2 seconds
int authTokenLifetimeMSecs = 2000;
int waitMSecs = authTokenLifetimeMSecs + 1000;
Account acct = provUtil.createGlobalAdmin(genAcctNameLocalPart(), domain);
// set the account's auth token lifetime to a short period
acct.setAdminAuthTokenLifetime(String.valueOf(authTokenLifetimeMSecs) + "ms");
// String authToken = getAuthToken(acct.getName(), true);
SoapTransport transport = authAdmin(acct.getName());
// wait till the auto token expire
Thread.sleep(waitMSecs);
// make sure the auth token is indeed expired
boolean caughtAuthExpired = false;
try {
NoOpRequest noOpReq = new NoOpRequest();
NoOpResponse noOpResp = invokeJaxb(transport, noOpReq);
} catch (ServiceException e) {
if (AccountServiceException.AUTH_EXPIRED.equals(e.getCode())) {
caughtAuthExpired = true;
}
}
assertTrue(caughtAuthExpired);
List<CookieSpec> cookiesToClear = Lists.newArrayList(new CookieSpec(ZimbraCookie.COOKIE_ZM_ADMIN_AUTH_TOKEN));
ClearCookieRequest req = new ClearCookieRequest(cookiesToClear);
/*
* test the regular path when auto token control is not set
* (auth token in soap header)
*/
caughtAuthExpired = false;
try {
invokeJaxb(transport, req);
} catch (ServiceException e) {
if (AccountServiceException.AUTH_EXPIRED.equals(e.getCode())) {
caughtAuthExpired = true;
}
}
assertTrue(caughtAuthExpired);
/*
* test the regular path when auto token control is not set
* (auth token in cookie)
*/
String authToken = transport.getAuthToken().getValue();
SoapTransport authTokenInCookieTransport = new AuthTokenInCookieTransport(authToken, true);
caughtAuthExpired = false;
try {
invokeJaxb(authTokenInCookieTransport, req);
} catch (ServiceException e) {
if (AccountServiceException.AUTH_EXPIRED.equals(e.getCode())) {
caughtAuthExpired = true;
}
}
assertTrue(caughtAuthExpired);
/*
* test the path when auth token control voidOnExpired is true
*/
// debug listener to verify the cookie is cleared
SoapDebugListener verifyCookieClearedListener = new SoapDebugListener(Level.ALL) {
@Override
public void receiveSoapMessage(HttpPost postMethod, Element envelope) {
super.receiveSoapMessage(postMethod, envelope);
// verify cookies are cleared
Header[] headers = postMethod.getAllHeaders();
boolean cookieCleared = false;
for (Header header : headers) {
if (header.toString().trim().equals("Set-Cookie: ZM_ADMIN_AUTH_TOKEN=;Path=/;Expires=Thu, 01-Jan-1970 00:00:00 GMT")) {
cookieCleared = true;
}
// System.out.println(header.toString().trim()); // trim the ending crlf
}
assertTrue(cookieCleared);
}
};
authTokenInCookieTransport = new AuthTokenInCookieTransport(authToken, true, true, verifyCookieClearedListener);
// should NOT get AUTH_EXPIRED
ClearCookieResponse resp = invokeJaxb(authTokenInCookieTransport, req);
provUtil.deleteAccount(acct);
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestAuth method soapByCookieAdmin.
@Test
public void soapByCookieAdmin() throws Exception {
boolean isAdmin = true;
String USER_NAME = TestUtil.getAddress("admin");
String authToken = getAuthToken(USER_NAME, isAdmin);
Element req = Element.create(SoapProtocol.Soap12, AdminConstants.GET_CONFIG_REQUEST);
req.addElement(AdminConstants.E_A).addAttribute(AdminConstants.A_N, Provisioning.A_cn);
SoapTransport transport = new AuthTokenInCookieTransport(authToken, isAdmin);
Element resp = transport.invoke(req);
Element eA = resp.getElement(AdminConstants.E_A);
String value = eA.getText();
assertEquals("config", value);
}
Aggregations