use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class AbstractExternalStoreManagerTest method testUncachedSubstream.
@Test
public void testUncachedSubstream() throws Exception {
ParsedMessage pm = ThreaderTest.getRootMessage();
byte[] mimeBytes = TestUtil.readInputStream(pm.getRawInputStream());
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
StoreManager sm = StoreManager.getInstance();
Blob blob = sm.storeIncoming(pm.getRawInputStream());
StagedBlob staged = sm.stage(blob, mbox);
MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
mblob = sm.getMailboxBlob(mbox, 0, 0, staged.getLocator());
Blob localBlob = mblob.getLocalBlob();
InputStream stream = sm.getContent(localBlob);
Assert.assertTrue("input stream external", stream instanceof BlobInputStream);
if (sm instanceof ExternalStoreManager) {
((ExternalStoreManager) sm).clearCache();
}
blob.getFile().delete();
Assert.assertFalse(blob.getFile().exists());
//create new stream spanning the whole blob
InputStream newStream = ((BlobInputStream) stream).newStream(0, -1);
Assert.assertNotNull(newStream);
Assert.assertTrue("stream content = mime content", TestUtil.bytesEqual(mimeBytes, newStream));
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class TritonBlobStoreManagerTest method sisEmpty.
@Test
public void sisEmpty() throws Exception {
TritonBlobStoreManager sm = (TritonBlobStoreManager) StoreManager.getInstance();
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Assert.assertTrue("StoreManager is content addressable", sm instanceof ContentAddressableStoreManager);
Assert.assertTrue("StoreManager supports SIS check", sm.supports(StoreFeature.SINGLE_INSTANCE_SERVER_CREATE));
byte[] bytes = new byte[0];
Blob blob = sm.storeIncoming(new ByteArrayInputStream(bytes));
//blob has not yet been finalized, so it shouldn't exist in remote system yet
byte[] hash = sm.getHash(blob);
Assert.assertNotNull("empty blob always exists", sm.getSisBlob(hash));
Assert.assertEquals("blob size = incoming written", bytes.length, blob.getRawSize());
Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, blob.getInputStream()));
StagedBlob staged = sm.stage(blob, mbox);
Assert.assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
Assert.assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
Assert.assertTrue("link content = mime content", TestUtil.bytesEqual(bytes, mblob.getLocalBlob().getInputStream()));
//blob uploaded, now sis should return true and increment ref count
Blob sisBlob = sm.getSisBlob(hash);
Assert.assertNotNull("object created", sisBlob);
Assert.assertEquals("blob size = incoming written", bytes.length, sisBlob.getRawSize());
Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, sisBlob.getInputStream()));
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class TritonBlobStoreManagerTest method sis.
@Test
public void sis() throws Exception {
TritonBlobStoreManager sm = (TritonBlobStoreManager) StoreManager.getInstance();
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Assert.assertTrue("StoreManager is content addressable", sm instanceof ContentAddressableStoreManager);
Assert.assertTrue("StoreManager supports SIS check", sm.supports(StoreFeature.SINGLE_INSTANCE_SERVER_CREATE));
Random rand = new Random();
byte[] bytes = new byte[10000];
rand.nextBytes(bytes);
Blob blob = sm.storeIncoming(new ByteArrayInputStream(bytes));
//blob has not yet been finalized, so it shouldn't exist in remote system yet
byte[] hash = sm.getHash(blob);
Assert.assertNull("object not yet created", sm.getSisBlob(hash));
Assert.assertEquals("blob size = incoming written", bytes.length, blob.getRawSize());
Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, blob.getInputStream()));
StagedBlob staged = sm.stage(blob, mbox);
Assert.assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
Assert.assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
Assert.assertTrue("link content = mime content", TestUtil.bytesEqual(bytes, mblob.getLocalBlob().getInputStream()));
//blob uploaded, now sis should return true and increment ref count
Blob sisBlob = sm.getSisBlob(hash);
Assert.assertNotNull("object created", sisBlob);
Assert.assertEquals("blob size = incoming written", bytes.length, sisBlob.getRawSize());
Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, sisBlob.getInputStream()));
//delete once, should still exist;
sm.delete(mblob);
Assert.assertNotNull("object still ref'd", sm.getSisBlob(hash));
//delete twice (once for original, once since we just did a sisCheck above)
sm.delete(mblob);
sm.delete(mblob);
Assert.assertNull("object deleted", sm.getSisBlob(hash));
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class TagActionTest method permissions.
@Test
public void permissions() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
Tag tag1 = mbox.createTag(null, name1, (byte) 0);
Element request = new Element.XMLElement(MailConstants.TAG_ACTION_REQUEST);
Element action = request.addElement(MailConstants.E_ACTION);
action.addAttribute(MailConstants.A_OPERATION, ItemAction.OP_COLOR).addAttribute(MailConstants.A_COLOR, 4);
action.addAttribute(MailConstants.A_TAG_NAMES, TagUtil.encodeTags(name1));
try {
new TagAction().handle(request, ServiceTestUtil.getRequestContext(acct2, acct));
Assert.fail("colored another user's tags without permissions");
} catch (ServiceException e) {
Assert.assertEquals("expected error code: " + ServiceException.PERM_DENIED, ServiceException.PERM_DENIED, e.getCode());
}
action.addAttribute(MailConstants.A_TAG_NAMES, (String) null).addAttribute(MailConstants.A_ID, tag1.getId());
try {
new TagAction().handle(request, ServiceTestUtil.getRequestContext(acct2, acct));
Assert.fail("colored another user's tags without permissions");
} catch (ServiceException e) {
Assert.assertEquals("expected error code: " + ServiceException.PERM_DENIED, ServiceException.PERM_DENIED, e.getCode());
}
action.addAttribute(MailConstants.A_TAG_NAMES, TagUtil.encodeTags(name2));
try {
new TagAction().handle(request, ServiceTestUtil.getRequestContext(acct2, acct));
Assert.fail("colored another user's tags without permissions");
} catch (ServiceException e) {
Assert.assertEquals("expected error code: " + ServiceException.PERM_DENIED, ServiceException.PERM_DENIED, e.getCode());
}
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class TagActionTest method delete.
@Test
public void delete() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("test@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// create the tag
Element request = new Element.XMLElement(MailConstants.CREATE_TAG_REQUEST);
request.addUniqueElement(MailConstants.E_TAG).addAttribute(MailConstants.A_COLOR, 4).addAttribute(MailConstants.A_NAME, "test");
Element response = new CreateTag().handle(request, ServiceTestUtil.getRequestContext(acct));
int tagId = response.getElement(MailConstants.E_TAG).getAttributeInt(MailConstants.A_ID);
try {
mbox.getTagById(null, tagId);
} catch (ServiceException e) {
Assert.fail("tag not created: " + e);
}
// delete the tag
request = new Element.XMLElement(MailConstants.TAG_ACTION_REQUEST);
request.addUniqueElement(MailConstants.E_ACTION).addAttribute(MailConstants.A_OPERATION, ItemAction.OP_HARD_DELETE).addAttribute(MailConstants.A_ID, tagId);
new TagAction().handle(request, ServiceTestUtil.getRequestContext(acct));
try {
mbox.getTagById(null, tagId);
Assert.fail("tag not deleted");
} catch (NoSuchItemException e) {
}
}
Aggregations