Skip to content

Commit

Permalink
test: fix CORS test cases (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
saig0 authored Feb 24, 2023
1 parent dbdbd49 commit 82dc233
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 6 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,16 @@
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.1</version>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>

<!-- hot swapping, live reload -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;

@SpringBootTest(
Expand All @@ -22,7 +22,6 @@
"logging.level.io.zeebe.tasklist: info",
})
@AutoConfigureMockMvc
@ActiveProfiles("junittest")
public class CorsSettingsControllerTest {

@LocalServerPort protected int port;
Expand All @@ -32,17 +31,20 @@ public class CorsSettingsControllerTest {
@MockBean protected HazelcastService zeebeHazelcastService;

@Test
@WithMockUser(username = "demo", password = "demo")
public void access_control_origin_request_header_is_checked() throws Exception {
mockMvc
.perform(
options("/")
.header("Access-Control-Request-Method", "GET")
.header("Host", "localhost")
.header("Origin", "http://a.bad-person.internet"))
.header("Origin", "http://a.bad-person.internet")
)
.andExpect(status().isForbidden());
}

@Test
@WithMockUser(username = "demo", password = "demo")
public void access_control_allow_origin_response_header_is_send() throws Exception {
mockMvc
.perform(
Expand Down

0 comments on commit 82dc233

Please sign in to comment.