Fix SSLErrorMessageTests in Windows (#47315)
- Build paths with PathUtils#get instead of hard-coding a string with forward slashes. - Do not try to match the whole message that includes paths. The file separator is `\\` in windows but when we throw an Elasticsearch Exception, the message is formatted with LoggerMessageFormat#format which replaces `\\` with `\` in Path names. That means that in Windows the Exception message will contain paths with single backslashes while the expected string that comes from Path#toString on filename and env.configFile will contain double backslashes. There is no point in attempting to match the whole message string for the purpose of this test. Resolves: #45598
This commit is contained in:
parent
fa0b1b641a
commit
33c5e5b09d
|
@ -9,6 +9,7 @@ import org.apache.lucene.util.Constants;
|
|||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.ElasticsearchSecurityException;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
|
@ -107,27 +108,22 @@ public class SSLErrorMessageTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testMessageForKeyStoreOutsideConfigDir() throws Exception {
|
||||
assumeFalse("@AwaitsFix(bugUrl = https://github.com/elastic/elasticsearch/issues/45598)", Constants.WINDOWS);
|
||||
checkBlockedKeyManagerResource("keystore", "keystore.path", null);
|
||||
}
|
||||
|
||||
public void testMessageForPemCertificateOutsideConfigDir() throws Exception {
|
||||
assumeFalse("@AwaitsFix(bugUrl = https://github.com/elastic/elasticsearch/issues/45598)", Constants.WINDOWS);
|
||||
checkBlockedKeyManagerResource("certificate", "certificate", withKey("cert1a.key"));
|
||||
}
|
||||
|
||||
public void testMessageForPemKeyOutsideConfigDir() throws Exception {
|
||||
assumeFalse("@AwaitsFix(bugUrl = https://github.com/elastic/elasticsearch/issues/45598)", Constants.WINDOWS);
|
||||
checkBlockedKeyManagerResource("key", "key", withCertificate("cert1a.crt"));
|
||||
}
|
||||
|
||||
public void testMessageForTrustStoreOutsideConfigDir() throws Exception {
|
||||
assumeFalse("@AwaitsFix(bugUrl = https://github.com/elastic/elasticsearch/issues/45598)", Constants.WINDOWS);
|
||||
checkBlockedTrustManagerResource("truststore", "truststore.path");
|
||||
}
|
||||
|
||||
public void testMessageForCertificateAuthoritiesOutsideConfigDir() throws Exception {
|
||||
assumeFalse("@AwaitsFix(bugUrl = https://github.com/elastic/elasticsearch/issues/45598)", Constants.WINDOWS);
|
||||
checkBlockedTrustManagerResource("certificate_authorities", "certificate_authorities");
|
||||
}
|
||||
|
||||
|
@ -229,9 +225,9 @@ public class SSLErrorMessageTests extends ESTestCase {
|
|||
assertThat(exception, instanceOf(ElasticsearchSecurityException.class));
|
||||
|
||||
exception = exception.getCause();
|
||||
assertThat(exception, throwableWithMessage(
|
||||
"failed to initialize SSL " + sslManagerType + " - access to read " + fileType + " file [" + fileName +
|
||||
"] is blocked; SSL resources should be placed in the [" + env.configFile() + "] directory"));
|
||||
assertThat(exception.getMessage(),
|
||||
containsString("failed to initialize SSL " + sslManagerType + " - access to read " + fileType + " file"));
|
||||
assertThat(exception.getMessage(),containsString("file.error"));
|
||||
assertThat(exception, instanceOf(ElasticsearchException.class));
|
||||
|
||||
exception = exception.getCause();
|
||||
|
@ -253,7 +249,7 @@ public class SSLErrorMessageTests extends ESTestCase {
|
|||
}
|
||||
|
||||
private String blockedFile() throws IOException {
|
||||
return "/this/path/is/outside/the/config/directory/file.error";
|
||||
return PathUtils.get("/this", "path", "is", "outside", "the", "config", "directory", "file.error").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue