Search in sources :

Example 1 with LoginVM

use of com.arnaugarcia.uplace.web.rest.vm.LoginVM in project uplace.es by Uplace.

the class UserJWTControllerIntTest method testAuthorizeWithRememberMe.

@Test
@Transactional
public void testAuthorizeWithRememberMe() throws Exception {
    User user = new User();
    user.setLogin("user-jwt-controller-remember-me");
    user.setEmail("user-jwt-controller-remember-me@example.com");
    user.setActivated(true);
    user.setPassword(passwordEncoder.encode("test"));
    userRepository.saveAndFlush(user);
    LoginVM login = new LoginVM();
    login.setUsername("user-jwt-controller-remember-me");
    login.setPassword("test");
    login.setRememberMe(true);
    mockMvc.perform(post("/api/authenticate").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(login))).andExpect(status().isOk()).andExpect(jsonPath("$.id_token").isString()).andExpect(jsonPath("$.id_token").isNotEmpty()).andExpect(header().string("Authorization", not(nullValue()))).andExpect(header().string("Authorization", not(isEmptyString())));
}
Also used : LoginVM(com.arnaugarcia.uplace.web.rest.vm.LoginVM) User(com.arnaugarcia.uplace.domain.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with LoginVM

use of com.arnaugarcia.uplace.web.rest.vm.LoginVM in project uplace.es by Uplace.

the class UserJWTControllerIntTest method testAuthorizeFails.

@Test
@Transactional
public void testAuthorizeFails() throws Exception {
    LoginVM login = new LoginVM();
    login.setUsername("wrong-user");
    login.setPassword("wrong password");
    mockMvc.perform(post("/api/authenticate").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(login))).andExpect(status().isUnauthorized()).andExpect(jsonPath("$.id_token").doesNotExist()).andExpect(header().doesNotExist("Authorization"));
}
Also used : LoginVM(com.arnaugarcia.uplace.web.rest.vm.LoginVM) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with LoginVM

use of com.arnaugarcia.uplace.web.rest.vm.LoginVM in project uplace.es by Uplace.

the class UserJWTControllerIntTest method testAuthorize.

@Test
@Transactional
public void testAuthorize() throws Exception {
    User user = new User();
    user.setLogin("user-jwt-controller");
    user.setEmail("user-jwt-controller@example.com");
    user.setActivated(true);
    user.setPassword(passwordEncoder.encode("test"));
    userRepository.saveAndFlush(user);
    LoginVM login = new LoginVM();
    login.setUsername("user-jwt-controller");
    login.setPassword("test");
    mockMvc.perform(post("/api/authenticate").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(login))).andExpect(status().isOk()).andExpect(jsonPath("$.id_token").isString()).andExpect(jsonPath("$.id_token").isNotEmpty()).andExpect(header().string("Authorization", not(nullValue()))).andExpect(header().string("Authorization", not(isEmptyString())));
}
Also used : LoginVM(com.arnaugarcia.uplace.web.rest.vm.LoginVM) User(com.arnaugarcia.uplace.domain.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

LoginVM (com.arnaugarcia.uplace.web.rest.vm.LoginVM)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Transactional (org.springframework.transaction.annotation.Transactional)3 User (com.arnaugarcia.uplace.domain.User)2