Search in sources :

Example 1 with RelativeExpiration

use of com.zimbra.cs.ephemeral.EphemeralInput.RelativeExpiration in project zm-mailbox by Zimbra.

the class EphemeralAttributesTest method testCsrfTokens.

@Test
public void testCsrfTokens() throws Exception {
    EphemeralKey tokenDataKey1 = new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb1");
    EphemeralKey tokenDataKey2 = new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb2");
    //already expired
    acct.addCsrfTokenData("crumb1", "data1", new AbsoluteExpiration(1000L));
    acct.addCsrfTokenData("crumb2", "data2", new RelativeExpiration(1L, TimeUnit.DAYS));
    //is it in the ephemeral store?
    assertEquals("data1", store.get(tokenDataKey1, location).getValue());
    assertEquals("data2", store.get(tokenDataKey2, location).getValue());
    //test getter
    assertEquals("data1", acct.getCsrfTokenData("crumb1"));
    assertEquals("data2", acct.getCsrfTokenData("crumb2"));
    //test removing expired
    acct.purgeCsrfTokenData();
    assertTrue(store.get(tokenDataKey1, location).isEmpty());
    assertEquals("data2", store.get(tokenDataKey2, location).getValue());
    //test removing a specific value
    acct.addCsrfTokenData("crumb3", "data3", new RelativeExpiration(1L, TimeUnit.DAYS));
    acct.removeCsrfTokenData("crumb2", "data2");
    assertTrue(store.get(tokenDataKey2, location).isEmpty());
    assertEquals("data3", acct.getCsrfTokenData("crumb3"));
    //test removing incorrect value
    acct.removeCsrfTokenData("crumb3", "data2");
    assertEquals("data3", acct.getCsrfTokenData("crumb3"));
}
Also used : RelativeExpiration(com.zimbra.cs.ephemeral.EphemeralInput.RelativeExpiration) AbsoluteExpiration(com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration) Test(org.junit.Test)

Example 2 with RelativeExpiration

use of com.zimbra.cs.ephemeral.EphemeralInput.RelativeExpiration in project zm-mailbox by Zimbra.

the class EphemeralAttributesTest method testAuthTokens.

@Test
public void testAuthTokens() throws Exception {
    EphemeralKey tokenKey1 = new EphemeralKey(Provisioning.A_zimbraAuthTokens, "token1");
    EphemeralKey tokenKey2 = new EphemeralKey(Provisioning.A_zimbraAuthTokens, "token2");
    //already expired
    acct.addAuthTokens("token1", "data1", new AbsoluteExpiration(1000L));
    acct.addAuthTokens("token2", "data2", new RelativeExpiration(1L, TimeUnit.DAYS));
    //is it in the ephemeral store?
    assertEquals("data1", store.get(tokenKey1, location).getValue());
    assertEquals("data2", store.get(tokenKey2, location).getValue());
    //test getter
    assertEquals("data1", acct.getAuthTokens("token1"));
    assertEquals("data2", acct.getAuthTokens("token2"));
    //test removing expired
    acct.purgeAuthTokens();
    assertTrue(store.get(tokenKey1, location).isEmpty());
    assertEquals("data2", store.get(tokenKey2, location).getValue());
    //test removing a specific value
    acct.addAuthTokens("token3", "data3", new RelativeExpiration(1L, TimeUnit.DAYS));
    acct.removeAuthTokens("token2", "data2");
    assertTrue(store.get(tokenKey2, location).isEmpty());
    assertEquals("data3", acct.getAuthTokens("token3"));
    //test removing incorrect value
    acct.removeAuthTokens("token3", "data2");
    assertEquals("data3", acct.getAuthTokens("token3"));
}
Also used : RelativeExpiration(com.zimbra.cs.ephemeral.EphemeralInput.RelativeExpiration) AbsoluteExpiration(com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration) Test(org.junit.Test)

Example 3 with RelativeExpiration

use of com.zimbra.cs.ephemeral.EphemeralInput.RelativeExpiration in project zm-mailbox by Zimbra.

the class EphemeralStoreTest method testExpiry.

@Test
public void testExpiry() throws Exception {
    EphemeralLocation target = new TestLocation();
    EphemeralKey staticKey = new EphemeralKey("foo");
    EphemeralKey dynamicKey = new EphemeralKey("foo", "1");
    EphemeralInput input1 = new EphemeralInput(staticKey, "bar");
    input1.setExpiration(new RelativeExpiration(1L, TimeUnit.SECONDS));
    store.set(input1, target);
    EphemeralInput input2 = new EphemeralInput(dynamicKey, "bar");
    input2.setExpiration(new RelativeExpiration(1L, TimeUnit.SECONDS));
    store.update(input2, target);
    //sanity check
    assertEquals("bar", store.get(staticKey, target).getValue());
    assertEquals("bar", store.get(dynamicKey, target).getValue());
    Thread.sleep(1500);
    //purging without specifying a dynamic component will purge all keys with dynamic components
    store.purgeExpired(staticKey, target);
    assertTrue(store.get(staticKey, target).isEmpty());
    assertTrue(store.get(dynamicKey, target).isEmpty());
    store.set(input1, target);
    store.update(input2, target);
    Thread.sleep(1500);
    //purging with a dynamic component will purge only keys that match that dynamic component
    store.purgeExpired(dynamicKey, target);
    assertTrue(store.get(dynamicKey, target).isEmpty());
    assertEquals("bar", store.get(staticKey, target).getValue());
}
Also used : RelativeExpiration(com.zimbra.cs.ephemeral.EphemeralInput.RelativeExpiration) Test(org.junit.Test)

Aggregations

RelativeExpiration (com.zimbra.cs.ephemeral.EphemeralInput.RelativeExpiration)3 Test (org.junit.Test)3 AbsoluteExpiration (com.zimbra.cs.ephemeral.EphemeralInput.AbsoluteExpiration)2