-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'InformDataLab-features/cors' into main
- Loading branch information
Showing
5 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/test/java/io/zeebe/tasklist/CorsSettingsControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.zeebe.tasklist.rest; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.options; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import io.zeebe.tasklist.HazelcastService; | ||
import io.zeebe.tasklist.repository.HazelcastConfigRepository; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
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.test.web.servlet.MockMvc; | ||
|
||
@SpringBootTest( | ||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, | ||
properties = { | ||
"server.allowedOriginsUrls: http://www.someurl.com", | ||
"logging.level.io.zeebe.tasklist: info", | ||
}) | ||
@AutoConfigureMockMvc | ||
@ActiveProfiles("junittest") | ||
public class CorsSettingsControllerTest { | ||
|
||
@LocalServerPort protected int port; | ||
@Autowired protected MockMvc mockMvc; | ||
|
||
@MockBean protected HazelcastConfigRepository hazelcastConfigRepository; | ||
@MockBean protected HazelcastService zeebeHazelcastService; | ||
|
||
@Test | ||
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")) | ||
.andExpect(status().isForbidden()); | ||
} | ||
|
||
@Test | ||
public void access_control_allow_origin_response_header_is_send() throws Exception { | ||
mockMvc | ||
.perform( | ||
options("/") | ||
.header("Access-Control-Request-Method", "GET") | ||
.header("Host", "localhost") | ||
.header("Origin", "http://www.someurl.com")) | ||
.andExpect(status().isOk()) | ||
.andExpect(header().string("Access-Control-Allow-Origin", "http://www.someurl.com")); | ||
} | ||
} |