Search in sources :

Example 1 with LoginVM

use of io.github.jhipster.sample.web.rest.vm.LoginVM in project jhipster-sample-app-cassandra by jhipster.

the class UserJWTControllerIntTest method testAuthorizeFails.

@Test
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(io.github.jhipster.sample.web.rest.vm.LoginVM) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with LoginVM

use of io.github.jhipster.sample.web.rest.vm.LoginVM in project jhipster-sample-app-cassandra by jhipster.

the class UserJWTControllerIntTest method testAuthorize.

@Test
public void testAuthorize() throws Exception {
    User user = new User();
    user.setId(UUID.randomUUID().toString());
    user.setLogin("user-jwt-controller");
    user.setEmail("user-jwt-controller@example.com");
    user.setActivated(true);
    user.setPassword(passwordEncoder.encode("test"));
    userRepository.save(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(io.github.jhipster.sample.web.rest.vm.LoginVM) User(io.github.jhipster.sample.domain.User) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with LoginVM

use of io.github.jhipster.sample.web.rest.vm.LoginVM in project jhipster-sample-app-mongodb by jhipster.

the class UserJWTControllerIntTest method testAuthorize.

@Test
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.save(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(io.github.jhipster.sample.web.rest.vm.LoginVM) User(io.github.jhipster.sample.domain.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with LoginVM

use of io.github.jhipster.sample.web.rest.vm.LoginVM in project jhipster-sample-app-mongodb by jhipster.

the class UserJWTControllerIntTest method testAuthorizeFails.

@Test
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(io.github.jhipster.sample.web.rest.vm.LoginVM) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with LoginVM

use of io.github.jhipster.sample.web.rest.vm.LoginVM in project jhipster-sample-app-cassandra by jhipster.

the class UserJWTControllerIntTest method testAuthorizeWithRememberMe.

@Test
public void testAuthorizeWithRememberMe() throws Exception {
    User user = new User();
    user.setId(UUID.randomUUID().toString());
    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.save(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(io.github.jhipster.sample.web.rest.vm.LoginVM) User(io.github.jhipster.sample.domain.User) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

LoginVM (io.github.jhipster.sample.web.rest.vm.LoginVM)9 Test (org.junit.Test)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 User (io.github.jhipster.sample.domain.User)6 AbstractCassandraTest (io.github.jhipster.sample.AbstractCassandraTest)3 Transactional (org.springframework.transaction.annotation.Transactional)3