-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update security-config * update cors-test * remove unused imports
- Loading branch information
Showing
2 changed files
with
80 additions
and
5 deletions.
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
75 changes: 75 additions & 0 deletions
75
src/test/java/rocks/inspectit/oce/eum/server/security/cors/CorsTest.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,75 @@ | ||
package rocks.inspectit.oce.eum.server.security.cors; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.util.TestPropertyValues; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.context.ApplicationContextInitializer; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.http.*; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@ContextConfiguration(initializers = CorsTest.Initializer.class) | ||
@DirtiesContext | ||
public class CorsTest { | ||
|
||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
|
||
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | ||
|
||
@Override | ||
public void initialize(ConfigurableApplicationContext applicationContext) { | ||
String tokenDir = getClass().getClassLoader().getResource("security/simple-auth-provider").getFile(); | ||
TestPropertyValues.of("inspectit-eum-server.security.enabled=true", "inspectit-eum-server.security.auth-provider.simple.enabled=true", "inspectit-eum-server.security.auth-provider.simple.token-directory=" + tokenDir, "inspectit-eum-server.security.auth-provider.simple.default-file-name=") | ||
.applyTo(applicationContext); | ||
} | ||
} | ||
|
||
@Test | ||
public void successfulCorsForGetBeacons() { | ||
String endpoint = "/beacon"; | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setOrigin("https://www.example.com"); | ||
headers.setAccessControlRequestMethod(HttpMethod.GET); | ||
HttpEntity<Void> requestEntity = new HttpEntity<>(headers); | ||
ResponseEntity<String> response = restTemplate.exchange( | ||
endpoint, HttpMethod.OPTIONS, requestEntity, String.class); | ||
|
||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
|
||
@Test | ||
public void successfulCorsForPostBeacons() { | ||
String endpoint = "/beacon"; | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setOrigin("https://www.example.com"); | ||
headers.setAccessControlRequestMethod(HttpMethod.POST); | ||
HttpEntity<Void> requestEntity = new HttpEntity<>(headers); | ||
ResponseEntity<String> response = restTemplate.exchange( | ||
endpoint, HttpMethod.OPTIONS, requestEntity, String.class); | ||
|
||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
|
||
@Test | ||
public void successfulCorsForSpans() { | ||
String endpoint = "/spans"; | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setOrigin("https://www.example.com"); | ||
headers.setAccessControlRequestMethod(HttpMethod.POST); | ||
HttpEntity<Void> requestEntity = new HttpEntity<>(headers); | ||
ResponseEntity<String> response = restTemplate.exchange( | ||
endpoint, HttpMethod.OPTIONS, requestEntity, String.class); | ||
|
||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
} |