Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit 5d212604 authored by Darrel Danadyaksa Poli's avatar Darrel Danadyaksa Poli
Browse files

[REFACTOR] AuthenticationControllerTest to disable CSRF and update JSON path assertions

parent cd133a42
No related branches found
No related tags found
1 merge request!1Login registration
......@@ -15,6 +15,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.test.web.servlet.MockMvc;
......@@ -51,11 +52,13 @@ class AuthenticationControllerTest {
static class TestSecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(authorize -> authorize.anyRequest().permitAll());
return http.build();
http.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(authorize -> authorize.anyRequest().permitAll());
return http.build();
}
}
@Test
void testRegisterEmail() throws Exception {
RegistrationRequest request = new RegistrationRequest();
......@@ -73,8 +76,8 @@ class AuthenticationControllerTest {
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(1L))
.andExpect(jsonPath("$.email").value("email@example.com"));
.andExpect(jsonPath("$.data.id").value(1L))
.andExpect(jsonPath("$.data.email").value("email@example.com"));
}
@Test
......@@ -96,8 +99,8 @@ class AuthenticationControllerTest {
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(2L))
.andExpect(jsonPath("$.email").value("social@example.com"));
.andExpect(jsonPath("$.data.id").value(2L))
.andExpect(jsonPath("$.data.email").value("social@example.com"));
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment