use of io.github.jhipster.sample.domain.PersistentToken in project jhipster-sample-app-hazelcast by jhipster.
the class UserServiceIntTest method generateUserToken.
private void generateUserToken(User user, String tokenSeries, LocalDate localDate) {
PersistentToken token = new PersistentToken();
token.setSeries(tokenSeries);
token.setUser(user);
token.setTokenValue(tokenSeries + "-data");
token.setTokenDate(localDate);
token.setIpAddress("127.0.0.1");
token.setUserAgent("Test agent");
persistentTokenRepository.saveAndFlush(token);
}
use of io.github.jhipster.sample.domain.PersistentToken in project jhipster-sample-app-hazelcast by jhipster.
the class AccountResourceIntTest method testGetCurrentSessions.
@Test
@Transactional
@WithMockUser("current-sessions")
public void testGetCurrentSessions() throws Exception {
User user = new User();
user.setPassword(RandomStringUtils.random(60));
user.setLogin("current-sessions");
user.setEmail("current-sessions@example.com");
userRepository.saveAndFlush(user);
PersistentToken token = new PersistentToken();
token.setSeries("current-sessions");
token.setUser(user);
token.setTokenValue("current-session-data");
token.setTokenDate(LocalDate.of(2017, 3, 23));
token.setIpAddress("127.0.0.1");
token.setUserAgent("Test agent");
persistentTokenRepository.saveAndFlush(token);
restMvc.perform(get("/api/account/sessions")).andExpect(status().isOk()).andExpect(jsonPath("$.[*].series").value(hasItem(token.getSeries()))).andExpect(jsonPath("$.[*].ipAddress").value(hasItem(token.getIpAddress()))).andExpect(jsonPath("$.[*].userAgent").value(hasItem(token.getUserAgent()))).andExpect(jsonPath("$.[*].tokenDate").value(hasItem(token.getTokenDate().toString())));
}
use of io.github.jhipster.sample.domain.PersistentToken in project jhipster-sample-app-hazelcast by jhipster.
the class AccountResourceIntTest method testInvalidateSession.
@Test
@Transactional
@WithMockUser("invalidate-session")
public void testInvalidateSession() throws Exception {
User user = new User();
user.setPassword(RandomStringUtils.random(60));
user.setLogin("invalidate-session");
user.setEmail("invalidate-session@example.com");
userRepository.saveAndFlush(user);
PersistentToken token = new PersistentToken();
token.setSeries("invalidate-session");
token.setUser(user);
token.setTokenValue("invalidate-data");
token.setTokenDate(LocalDate.of(2017, 3, 23));
token.setIpAddress("127.0.0.1");
token.setUserAgent("Test agent");
persistentTokenRepository.saveAndFlush(token);
assertThat(persistentTokenRepository.findByUser(user)).hasSize(1);
restMvc.perform(delete("/api/account/sessions/invalidate-session")).andExpect(status().isOk());
assertThat(persistentTokenRepository.findByUser(user)).isEmpty();
}
use of io.github.jhipster.sample.domain.PersistentToken in project jhipster-sample-app-websocket by jhipster.
the class AccountResourceIntTest method testInvalidateSession.
@Test
@Transactional
@WithMockUser("invalidate-session")
public void testInvalidateSession() throws Exception {
User user = new User();
user.setPassword(RandomStringUtils.random(60));
user.setLogin("invalidate-session");
user.setEmail("invalidate-session@example.com");
userRepository.saveAndFlush(user);
PersistentToken token = new PersistentToken();
token.setSeries("invalidate-session");
token.setUser(user);
token.setTokenValue("invalidate-data");
token.setTokenDate(LocalDate.of(2017, 3, 23));
token.setIpAddress("127.0.0.1");
token.setUserAgent("Test agent");
persistentTokenRepository.saveAndFlush(token);
assertThat(persistentTokenRepository.findByUser(user)).hasSize(1);
restMvc.perform(delete("/api/account/sessions/invalidate-session")).andExpect(status().isOk());
assertThat(persistentTokenRepository.findByUser(user)).isEmpty();
}
use of io.github.jhipster.sample.domain.PersistentToken in project jhipster-sample-app-websocket by jhipster.
the class AccountResourceIntTest method testGetCurrentSessions.
@Test
@Transactional
@WithMockUser("current-sessions")
public void testGetCurrentSessions() throws Exception {
User user = new User();
user.setPassword(RandomStringUtils.random(60));
user.setLogin("current-sessions");
user.setEmail("current-sessions@example.com");
userRepository.saveAndFlush(user);
PersistentToken token = new PersistentToken();
token.setSeries("current-sessions");
token.setUser(user);
token.setTokenValue("current-session-data");
token.setTokenDate(LocalDate.of(2017, 3, 23));
token.setIpAddress("127.0.0.1");
token.setUserAgent("Test agent");
persistentTokenRepository.saveAndFlush(token);
restMvc.perform(get("/api/account/sessions")).andExpect(status().isOk()).andExpect(jsonPath("$.[*].series").value(hasItem(token.getSeries()))).andExpect(jsonPath("$.[*].ipAddress").value(hasItem(token.getIpAddress()))).andExpect(jsonPath("$.[*].userAgent").value(hasItem(token.getUserAgent()))).andExpect(jsonPath("$.[*].tokenDate").value(hasItem(token.getTokenDate().toString())));
}
Aggregations