use of com.zimbra.cs.ephemeral.EphemeralStoreTest.TestLocation in project zm-mailbox by Zimbra.
the class LdapEphemeralStoreTest method testExpiry.
@Test
public void testExpiry() throws Exception {
EphemeralLocation location = new TestLocation();
EphemeralInput input = new EphemeralInput(new EphemeralKey("foo"), "bar");
input.setExpiration(new AbsoluteExpiration(1000L));
store.set(input, location);
input = new EphemeralInput(new EphemeralKey("foo", "1"), "bar");
input.setExpiration(new AbsoluteExpiration(1000L));
store.set(input, location);
input = new EphemeralInput(new EphemeralKey("foo", "2"), "bar");
input.setExpiration(new AbsoluteExpiration(1000L));
store.set(input, location);
helper.reset();
Thread.sleep(1500);
store.purgeExpired(new EphemeralKey("foo"), location);
Map<String, Object> expected = makeMap("-foo", "bar||1000", "bar|1|1000", "bar|2|1000");
verifyAttrMap(expected);
}
use of com.zimbra.cs.ephemeral.EphemeralStoreTest.TestLocation in project zm-mailbox by Zimbra.
the class LdapEphemeralStoreTest method testGet.
@Test
public void testGet() throws Exception {
EphemeralKey key = new EphemeralKey("foo");
store.set(new EphemeralInput(key, "bar"), new TestLocation());
EphemeralResult result = store.get(key, new TestLocation());
assertEquals("bar", result.getValue());
}
use of com.zimbra.cs.ephemeral.EphemeralStoreTest.TestLocation in project zm-mailbox by Zimbra.
the class LdapEphemeralStoreTest method testInvalidToken.
private void testInvalidToken(String attrName, String expected) throws Exception {
EphemeralLocation target = new TestLocation();
//sanity check: make sure a valid token works
EphemeralKey key = new EphemeralKey(attrName, "dynamicPart");
EphemeralInput input = new EphemeralInput(key, "validToken");
input.setExpiration(new AbsoluteExpiration(1000));
store.set(input, target);
EphemeralResult result = store.get(key, target);
assertEquals(result.getValue(), "validToken");
helper.reset();
//no expiration will result in an invalid auth/CSRF token
key = new EphemeralKey(attrName, "dynamicPart");
store.set(new EphemeralInput(key, "value"), target);
helper.reset();
result = store.get(key, target);
//the invalid token is not returned
assertTrue(result.isEmpty());
//but is instead flagged for deletion
verifyAttrMap(makeMap("-" + attrName, expected));
}
use of com.zimbra.cs.ephemeral.EphemeralStoreTest.TestLocation in project zm-mailbox by Zimbra.
the class AttributeEncodersTest method testValueEncoders.
@Test
public void testValueEncoders() throws Exception {
EphemeralLocation location = new TestLocation();
EphemeralKey staticKey = new EphemeralKey("foo");
EphemeralKey dynamicKey = new EphemeralKey("foo", "1");
ValueEncoder dynamicExpirationEncoder = new DynamicExpirationValueEncoder();
EphemeralInput staticInput = new EphemeralInput(staticKey, "bar");
EphemeralInput dynamicInput = new EphemeralInput(dynamicKey, "bar");
//static key, no expiration
assertEquals("bar", dynamicExpirationEncoder.encodeValue(staticInput, location));
//dynamic key, no expiration
assertEquals("bar|1|", dynamicExpirationEncoder.encodeValue(dynamicInput, location));
//set expirations
staticInput.setExpiration(new AbsoluteExpiration(1000L));
dynamicInput.setExpiration(new AbsoluteExpiration(1000L));
//static key, expiration
assertEquals("bar||1000", dynamicExpirationEncoder.encodeValue(staticInput, location));
//dynamic key, expiration
assertEquals("bar|1|1000", dynamicExpirationEncoder.encodeValue(dynamicInput, location));
//test special handling of auth and CSRF token encoding for LDAP backwards compatibility
ValueEncoder ldapValueEncoder = new LdapValueEncoder();
EphemeralKey authKey = new EphemeralKey(Provisioning.A_zimbraAuthTokens, "tokenId");
EphemeralInput authInput = new EphemeralInput(authKey, "serverVersion");
authInput.setExpiration(new AbsoluteExpiration(1000L));
assertEquals("tokenId|1000|serverVersion", ldapValueEncoder.encodeValue(authInput, location));
EphemeralKey csrfKey = new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb");
EphemeralInput csrfInput = new EphemeralInput(csrfKey, "data");
csrfInput.setExpiration(new AbsoluteExpiration(1000L));
assertEquals("data:crumb:1000", ldapValueEncoder.encodeValue(csrfInput, location));
}
use of com.zimbra.cs.ephemeral.EphemeralStoreTest.TestLocation in project zm-mailbox by Zimbra.
the class LdapEphemeralStoreTest method testUpdate.
@Test
public void testUpdate() throws Exception {
store.update(new EphemeralInput(new EphemeralKey("foo"), "bar"), new TestLocation());
Map<String, Object> expected = makeMap("+foo", "bar");
verifyAttrMap(expected);
}
Aggregations