use of org.elasticsearch.common.settings.SettingsException in project crate by crate.
the class AzureStorageServiceTests method testProxyWrongHost.
public void testProxyWrongHost() {
final Settings settings = Settings.builder().put(buildClientCredSettings()).put("proxy_type", randomFrom("socks", "http")).put("proxy_host", "thisisnotavalidhostorwehavebeensuperunlucky").put("proxy_port", 8080).build();
final SettingsException e = expectThrows(SettingsException.class, () -> storageServiceWithSettings(settings));
assertEquals("Azure proxy host is unknown.", e.getMessage());
}
use of org.elasticsearch.common.settings.SettingsException in project crate by crate.
the class AzureStorageServiceTests method testProxyNoPort.
public void testProxyNoPort() {
final Settings settings = Settings.builder().put(buildClientCredSettings()).put("proxy_host", "127.0.0.1").put("proxy_type", randomFrom("socks", "http")).build();
final SettingsException e = expectThrows(SettingsException.class, () -> storageServiceWithSettings(settings));
assertEquals("Azure Proxy type has been set but proxy host or port is not defined.", e.getMessage());
}
use of org.elasticsearch.common.settings.SettingsException in project crate by crate.
the class AzureStorageServiceTests method testProxyNoType.
public void testProxyNoType() {
final Settings settings = Settings.builder().put(buildClientCredSettings()).put("proxy_host", "127.0.0.1").put("proxy_port", 8080).build();
final SettingsException e = expectThrows(SettingsException.class, () -> storageServiceWithSettings(settings));
assertEquals("Azure Proxy port or host have been set but proxy type is not defined.", e.getMessage());
}
use of org.elasticsearch.common.settings.SettingsException in project crate by crate.
the class Netty4HttpServerTransport method buildCorsConfig.
// package private for testing
static Netty4CorsConfig buildCorsConfig(Settings settings) {
if (SETTING_CORS_ENABLED.get(settings) == false) {
return Netty4CorsConfigBuilder.forOrigins().disable().build();
}
String origin = SETTING_CORS_ALLOW_ORIGIN.get(settings);
final Netty4CorsConfigBuilder builder;
if (Strings.isNullOrEmpty(origin)) {
builder = Netty4CorsConfigBuilder.forOrigins();
} else if (origin.equals(ANY_ORIGIN)) {
builder = Netty4CorsConfigBuilder.forAnyOrigin();
} else {
try {
Pattern p = RestUtils.checkCorsSettingForRegex(origin);
if (p == null) {
builder = Netty4CorsConfigBuilder.forOrigins(RestUtils.corsSettingAsArray(origin));
} else {
builder = Netty4CorsConfigBuilder.forPattern(p);
}
} catch (PatternSyntaxException e) {
throw new SettingsException("Bad regex in [" + SETTING_CORS_ALLOW_ORIGIN.getKey() + "]: [" + origin + "]", e);
}
}
if (SETTING_CORS_ALLOW_CREDENTIALS.get(settings)) {
builder.allowCredentials();
}
String[] strMethods = Strings.tokenizeToStringArray(SETTING_CORS_ALLOW_METHODS.get(settings), ",");
HttpMethod[] methods = Arrays.stream(strMethods).map(HttpMethod::valueOf).toArray(HttpMethod[]::new);
return builder.allowedRequestMethods(methods).maxAge(SETTING_CORS_MAX_AGE.get(settings)).allowedRequestHeaders(Strings.tokenizeToStringArray(SETTING_CORS_ALLOW_HEADERS.get(settings), ",")).shortCircuit().build();
}
use of org.elasticsearch.common.settings.SettingsException in project elasticsearch by elastic.
the class InternalSettingsPreparerTests method testGarbageIsNotSwallowed.
public void testGarbageIsNotSwallowed() throws IOException {
try {
InputStream garbage = getClass().getResourceAsStream("/config/garbage/garbage.yml");
Path home = createTempDir();
Path config = home.resolve("config");
Files.createDirectory(config);
Files.copy(garbage, config.resolve("elasticsearch.yml"));
InternalSettingsPreparer.prepareEnvironment(Settings.builder().put(baseEnvSettings).build(), null);
} catch (SettingsException e) {
assertEquals("Failed to load settings from [elasticsearch.yml]", e.getMessage());
}
}
Aggregations