|
@@ -44,6 +44,7 @@ import org.elasticsearch.common.bytes.BytesArray;
|
|
|
import org.elasticsearch.common.network.NetworkService;
|
|
|
import org.elasticsearch.common.settings.Setting;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
+import org.elasticsearch.common.settings.SettingsException;
|
|
|
import org.elasticsearch.common.transport.TransportAddress;
|
|
|
import org.elasticsearch.common.unit.ByteSizeValue;
|
|
|
import org.elasticsearch.common.unit.TimeValue;
|
|
@@ -75,6 +76,7 @@ import java.util.Set;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
+import java.util.regex.PatternSyntaxException;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static org.elasticsearch.common.Strings.collectionToDelimitedString;
|
|
@@ -148,6 +150,17 @@ public class Netty4HttpServerTransportTests extends ESTestCase {
|
|
|
assertFalse(corsConfig.isCredentialsAllowed());
|
|
|
}
|
|
|
|
|
|
+ public void testCorsConfigWithBadRegex() {
|
|
|
+ final Settings settings = Settings.builder()
|
|
|
+ .put(SETTING_CORS_ENABLED.getKey(), true)
|
|
|
+ .put(SETTING_CORS_ALLOW_ORIGIN.getKey(), "/[*/")
|
|
|
+ .put(SETTING_CORS_ALLOW_CREDENTIALS.getKey(), true)
|
|
|
+ .build();
|
|
|
+ SettingsException e = expectThrows(SettingsException.class, () -> Netty4HttpServerTransport.buildCorsConfig(settings));
|
|
|
+ assertThat(e.getMessage(), containsString("Bad regex in [http.cors.allow-origin]: [/[*/]"));
|
|
|
+ assertThat(e.getCause(), instanceOf(PatternSyntaxException.class));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Test that {@link Netty4HttpServerTransport} supports the "Expect: 100-continue" HTTP header
|
|
|
* @throws InterruptedException if the client communication with the server is interrupted
|