@Test public void test3destroy() { String token = store.getSessions().get(0).getToken(); store.destroyToken(token); assertThat(store.getSessions().isEmpty(), is(true)); }
@Test public void test0init() { assertThat(store.getSessions().isEmpty(), is(true)); assertThat(store.isValidToken("asdf", true), is(false)); assertThat(store.getIdentityForToken("asdf"), is(nullValue())); // These shouldn't throw anything store.destroyToken("asdf"); }
@Test public void test10expire() throws NotFoundException { String token = store.newToken("*****@*****.**", "domain.com"); assertThat(token, is(notNullValue())); assertThat(token.length(), is(not(0))); assertThat(store.getSessions().size(), is(1)); Session s = store.getSessions().get(0); store.expireSession(s.getId()); assertThat(store.getSessions().isEmpty(), is(true)); }
@Test public void test1create() throws InterruptedException { long now = System.currentTimeMillis(); Thread.sleep(20); String token = store.newToken("*****@*****.**", "domain.com"); assertThat(token, is(notNullValue())); assertThat(token.length(), is(not(0))); assertThat(store.getSessions().size(), is(1)); Session s = store.getSessions().get(0); assertThat(s.getId(), is(notNullValue())); assertThat(s.getDomain(), is("domain.com")); assertThat(s.getToken(), is(token)); assertThat(s.getUser(), is("*****@*****.**")); assertThat(s.getSessionStart(), is(greaterThan(now))); assertThat(s.getSessionExpiration(), is(greaterThan(s.getSessionStart()))); }
@Test public void test2ping() throws InterruptedException { long lastActive = store.getSessions().get(0).getLastActive(); assertThat(store.isValidToken(store.getSessions().get(0).getToken(), false), is(true)); assertThat(store.getSessions().get(0).getLastActive(), is(lastActive)); TimeUnit.MILLISECONDS.sleep(100); assertThat(store.isValidToken(store.getSessions().get(0).getToken(), true), is(true)); assertThat(store.getSessions().get(0).getLastActive(), is(greaterThan(lastActive))); }
@Test(expected = NotFoundException.class) public void test0notFound() throws NotFoundException { store.expireSession("asdf"); }
public JWTStoreTest() { System.setProperty("jwt.hmacSharedSecret", "qrllxoyy2x2bnsp84yjoi5wujrnqun6y0lspeu28"); this.store = JWTStore.getInstance(); }