use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestCookieReuse method setUp.
@Before
public void setUp() throws Exception {
currentSupportedAuthVersion = Provisioning.getInstance().getLocalServer().getLowestSupportedAuthVersion();
String prefix = NAME_PREFIX + "-" + testInfo.getMethodName().toLowerCase() + "-";
USER_NAME = prefix + "user1";
UNAUTHORIZED_USER = AccountTestUtil.getAddress(prefix + "unauthorized");
cleanUp();
TestUtil.createAccount(USER_NAME);
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
// Add a test message, to make sure the account isn't empty
TestUtil.addMessage(mbox, NAME_PREFIX);
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestCookieReuse method testInvalidSearchRequest.
/**
* Verify that we canNOT RE-use the cookie taken from a legitimate HTTP session for a SOAP request after
* ending the original session
*/
@Test
public void testInvalidSearchRequest() throws ServiceException, IOException, HttpException {
// establish legitimate connection
TestUtil.setAccountAttr(USER_NAME, Provisioning.A_zimbraForceClearCookies, "FALSE");
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
URI uri = mbox.getRestURI("Inbox?fmt=rss");
mbox.getHttpClient(uri);
ZAuthToken authT = mbox.getAuthToken();
// create evesdropper's SOAP client
SoapHttpTransport transport = new HttpCookieSoapTransport(TestUtil.getSoapUrl());
transport.setAuthToken(authT);
// check that search returns something
SearchRequest searchReq = new SearchRequest();
searchReq.setSearchTypes(MailItem.Type.MESSAGE.toString());
searchReq.setQuery("in:inbox");
Element req = JaxbUtil.jaxbToElement(searchReq, SoapProtocol.SoapJS.getFactory());
Element res = transport.invoke(req);
SearchResponse searchResp = JaxbUtil.elementToJaxb(res);
List<SearchHit> searchHits = searchResp.getSearchHits();
Assert.assertFalse("this search request should return some conversations", searchHits.isEmpty());
// explicitely end cookie session
Account a = TestUtil.getAccount(USER_NAME);
a.setForceClearCookies(false);
EndSessionRequest esr = new EndSessionRequest();
esr.setLogOff(true);
mbox.invokeJaxb(esr);
// check that search returns nothing
transport = new HttpCookieSoapTransport(TestUtil.getSoapUrl());
transport.setAuthToken(authT);
searchReq = new SearchRequest();
searchReq.setSearchTypes(MailItem.Type.MESSAGE.toString());
searchReq.setQuery("in:inbox");
try {
req = JaxbUtil.jaxbToElement(searchReq, SoapProtocol.SoapJS.getFactory());
res = transport.invoke(req);
searchResp = JaxbUtil.elementToJaxb(res);
searchHits = searchResp.getSearchHits();
Assert.assertTrue("this search request should fail", searchHits.isEmpty());
} catch (SoapFaultException ex) {
Assert.assertEquals("Should be getting 'auth required' exception", ServiceException.AUTH_EXPIRED, ex.getCode());
}
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestCookieReuse method testAutoEndSession.
/**
* Verify that we canNOT RE-use the cookie for REST session if the session is valid
* @throws HttpException
*/
@Test
public void testAutoEndSession() throws ServiceException, IOException, HttpException {
// establish legitimate connection
TestUtil.setAccountAttr(USER_NAME, Provisioning.A_zimbraForceClearCookies, "TRUE");
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
URI uri = mbox.getRestURI("Inbox?fmt=rss");
HttpClientContext context = HttpClientContext.create();
HttpClient alice = mbox.getHttpClient(uri);
// create evesdropper's connection
HttpClientBuilder eve = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
List<Cookie> cookies = context.getCookieStore().getCookies();
BasicCookieStore cookieStore = new BasicCookieStore();
for (Cookie cookie : cookies) {
BasicClientCookie basicCookie = new BasicClientCookie(cookie.getName(), cookie.getValue());
basicCookie.setDomain(uri.getHost());
basicCookie.setPath("/");
basicCookie.setSecure(false);
cookieStore.addCookie(cookie);
}
eve.setDefaultCookieStore(cookieStore);
Account a = TestUtil.getAccount(USER_NAME);
a.setForceClearCookies(true);
EndSessionRequest esr = new EndSessionRequest();
mbox.invokeJaxb(esr);
HttpGet get = new HttpGet(uri.toString());
HttpResponse response = HttpClientUtil.executeMethod(eve.build(), get, context);
int statusCode = response.getStatusLine().getStatusCode();
Assert.assertEquals("This request should not succeed. Getting status code " + statusCode, HttpStatus.SC_UNAUTHORIZED, statusCode);
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestCookieReuse method testForceEndSession.
/**
* Verify that we canNOT RE-use the cookie taken from a legitimate HTTP session for a REST request
* after ending the original session
* @throws HttpException
*/
@Test
public void testForceEndSession() throws ServiceException, IOException, HttpException {
// establish legitimate connection
TestUtil.setAccountAttr(USER_NAME, Provisioning.A_zimbraForceClearCookies, "FALSE");
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
URI uri = mbox.getRestURI("Inbox?fmt=rss");
HttpClient alice = mbox.getHttpClient(uri);
HttpClientContext context = HttpClientContext.create();
// create evesdropper's connection
HttpClientBuilder eve = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
List<Cookie> cookies = context.getCookieStore().getCookies();
BasicCookieStore cookieStore = new BasicCookieStore();
for (Cookie cookie : cookies) {
BasicClientCookie basicCookie = new BasicClientCookie(cookie.getName(), cookie.getValue());
basicCookie.setDomain(uri.getHost());
basicCookie.setPath("/");
basicCookie.setSecure(false);
cookieStore.addCookie(cookie);
}
eve.setDefaultCookieStore(cookieStore);
Account a = TestUtil.getAccount(USER_NAME);
a.setForceClearCookies(false);
EndSessionRequest esr = new EndSessionRequest();
esr.setLogOff(true);
mbox.invokeJaxb(esr);
HttpGet get = new HttpGet(uri.toString());
HttpResponse response = HttpClientUtil.executeMethod(eve.build(), get);
int statusCode = response.getStatusLine().getStatusCode();
Assert.assertEquals("This request should not succeed. Getting status code " + statusCode, HttpStatus.SC_UNAUTHORIZED, statusCode);
}
use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.
the class TestContactGroup method csvOldZCOClient.
@Test
public void csvOldZCOClient() throws Exception {
Account acct = Provisioning.getInstance().get(AccountBy.name, TestUtil.getAddress("user1"));
// String relativePath = "/?fmt=zip&meta=0&zlv=4&list=259";
String relativePath = "/?fmt=zip&meta=1&zlv=4&list=257";
final int BUFFER = 2048;
ZMailbox mbox = TestUtil.getZMailbox(acct.getName());
ZipInputStream zin = new ZipInputStream(mbox.getRESTResource(relativePath));
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
System.out.println("Unzipping " + ze.getName());
int count;
byte[] data = new byte[BUFFER];
ByteArrayOutputStream os = new ByteArrayOutputStream();
while ((count = zin.read(data, 0, BUFFER)) != -1) {
os.write(data, 0, count);
}
os.flush();
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
byte[] bytes = ByteUtil.getContent(is, 1024);
String dd = new String(bytes, "UTF-8");
System.out.println(dd);
is.close();
os.close();
}
zin.close();
}
Aggregations