From 33c5e5b09d472798cd9daaa3457af90a3353b520 Mon Sep 17 00:00:00 2001 From: Ioannis Kakavas Date: Tue, 1 Oct 2019 09:13:01 +0300 Subject: [PATCH] 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 --- .../xpack/ssl/SSLErrorMessageTests.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/ssl/SSLErrorMessageTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/ssl/SSLErrorMessageTests.java index 2bc9fd922c5..672e0bbb046 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/ssl/SSLErrorMessageTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/ssl/SSLErrorMessageTests.java @@ -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(); } /**