use of org.survey.model.user.User in project survey by markoniemi.
the class LoginServiceTest method loginNoUser.
@Test(expected = NotAuthorizedException.class)
public void loginNoUser() throws AuthenticationException {
Mockito.when(userService.findOne(Mockito.anyString())).thenReturn(null);
User user = new User("no_user", "password", "email", Role.ROLE_USER);
String token = loginService.login(user);
Assert.assertNotNull(token);
}
use of org.survey.model.user.User in project survey by markoniemi.
the class UserRepositoryTest method findByEmail.
@Test
public void findByEmail() {
save();
for (int i = 0; i < ENTITY_COUNT; i++) {
User foundEntity = userRepository.findByEmail(savedEntities.get(i).getEmail());
assertEntity(orginalEntities.get(i), foundEntity);
}
Assert.assertNull(userRepository.findByEmail("non-existent"));
}
use of org.survey.model.user.User in project survey by markoniemi.
the class JwtAuthenticationFilterTest method doFilterWithExpiredToken.
@Test
public void doFilterWithExpiredToken() throws ServletException, IOException, InterruptedException {
String loginUrl = "/api/rest/login";
String contextPath = "/jwt-authentication";
String requestUri = "/jwt-authentication/api/rest/echo";
User user = new User("username", "password", "email", Role.ROLE_USER);
Map<String, Object> payload = new HashMap<String, Object>();
payload.put("username", user.getUsername());
int expirySeconds = 1;
prepareMock(loginUrl, contextPath, requestUri, new JwtToken(payload, expirySeconds).getToken());
Thread.sleep(1000);
doFilter();
Mockito.verify(response).sendError(401, "Unauthorized");
}
use of org.survey.model.user.User in project survey by markoniemi.
the class JwtTokenTest method verifyTokenWithExpiredToken.
@Test
public void verifyTokenWithExpiredToken() {
try {
User user = new User("username", "password", "email", Role.ROLE_USER);
Map<String, Object> payload = new HashMap<String, Object>();
payload.put("username", user.getUsername());
JwtToken token = new JwtToken(payload, 1);
Thread.sleep(1000);
token.verifyToken();
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e instanceof JWTExpiredException);
}
}
use of org.survey.model.user.User in project survey by markoniemi.
the class LoginServiceTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
loginService = new LoginServiceImpl();
loginService.setUserService(userService);
User user = new User("username", "password", "email", Role.ROLE_USER);
Mockito.when(userService.findOne(Mockito.anyString())).thenReturn(user);
Mockito.when(request.getHeader(JwtToken.AUTHORIZATION_HEADER)).thenReturn("token");
}
Aggregations