Skip to content

Commit

Permalink
Fix CORS origin regexps
Browse files Browse the repository at this point in the history
And test that, because that's starting to be a lot of problems.
  • Loading branch information
yrodiere committed Dec 18, 2023
1 parent 211975d commit a31cb35
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ quarkusio.localized.ja.git-uri=https://github.com/quarkusio/ja.quarkus.io.git
indexing.scheduled.cron=0 0 19 * * ?
# More secure HTTP defaults
quarkus.http.cors=true
quarkus.http.cors.origins=https://quarkus.io,/https://.*\.quarkus\.io/,/https://quarkus-(web)?site-pr-[0-9]+-preview\.surge\.sh/
quarkus.http.cors.origins=https://quarkus.io,/https://.*\\\\.quarkus\\\\.io/,/https://quarkus-(web)?site-pr-[0-9]+-preview\\\\.surge\\\\.sh/
quarkus.http.cors.methods=GET
quarkus.http.header."X-Content-Type-Options".value=nosniff
quarkus.http.header."X-Frame-Options".value=deny
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/io/quarkus/search/app/SearchServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

import org.assertj.core.api.InstanceOfAssertFactories;
import org.assertj.core.api.ThrowingConsumer;
Expand Down Expand Up @@ -149,6 +150,45 @@ void queryNotProvided() {
assertThat(result.total()).isEqualTo(10);
}

@ParameterizedTest
@ValueSource(strings = {
"https://quarkus.io",
"https://es.quarkus.io",
"https://cn.quarkus.io",
"https://ja.quarkus.io",
"https://pt.quarkus.io",
"https://quarkus-site-pr-1825-preview.surge.sh",
"https://quarkus-website-pr-1825-preview.surge.sh"
})
void cors_allowed(String origin) {
given()
.header("Origin", origin)
.queryParam("q", "foo")
.when().get(GUIDES_SEARCH)
.then()
.statusCode(200)
.header("access-control-allow-origin", origin);
}

@ParameterizedTest
@ValueSource(strings = {
"http://localhost:8080/guides",
"https://localhost:8080/guides",
"https://example.com/guides",
"https://example.com/",
"https://my-quarkus.io",
"https://quarkus-site-pr-1825-preview-surge.sh",
"https://quarkus-website-pr-1825-preview-surge.sh"
})
void cors_denied(String origin) {
given()
.header("Origin", origin)
.queryParam("q", "foo")
.when().get(GUIDES_SEARCH)
.then()
.statusCode(403);
}

@ParameterizedTest
@MethodSource
void relevance(String query, URI[] expectedGuideUrls) {
Expand Down

0 comments on commit a31cb35

Please sign in to comment.