Search in sources :

Example 11 with User

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);
}
Also used : User(org.survey.model.user.User) Test(org.junit.Test)

Example 12 with User

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"));
}
Also used : User(org.survey.model.user.User) Test(org.junit.Test) CrudRepositoryTest(org.survey.repository.CrudRepositoryTest)

Example 13 with User

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");
}
Also used : User(org.survey.model.user.User) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 14 with User

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);
    }
}
Also used : User(org.survey.model.user.User) HashMap(java.util.HashMap) JWTExpiredException(com.auth0.jwt.JWTExpiredException) JWTExpiredException(com.auth0.jwt.JWTExpiredException) JWTVerifyException(com.auth0.jwt.JWTVerifyException) Test(org.junit.Test)

Example 15 with User

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");
}
Also used : User(org.survey.model.user.User) Before(org.junit.Before)

Aggregations

User (org.survey.model.user.User)30 Test (org.junit.Test)20 HashMap (java.util.HashMap)4 JWTExpiredException (com.auth0.jwt.JWTExpiredException)3 JWTVerifyException (com.auth0.jwt.JWTVerifyException)3 Before (org.junit.Before)3 BindException (org.springframework.validation.BindException)2 Errors (org.springframework.validation.Errors)2 UserValidator (org.survey.controller.UserValidator)2 JWTSigner (com.auth0.jwt.JWTSigner)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 File (org.survey.model.file.File)1 Poll (org.survey.model.poll.Poll)1 CrudRepositoryTest (org.survey.repository.CrudRepositoryTest)1