Skip to content

Commit 3777c70

Browse files
committed
Adjust reload keystore test to pass in FIPS (elastic#57050)
In KeystoreWrapper class we determine if the error to decrypt a given keystore is caused by a wrong password based on the exception that the SunJCE implementation of AES is throwing (AEADBadTagException). Other implementations from other Security Providers might cause decryption to fail in a different way and cause us to throw a generic error message. We handle this in this test by matching both possible exception messages. Relates: elastic#56889
1 parent 184338e commit 3777c70

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

x-pack/qa/password-protected-keystore/src/test/java/org/elasticsearch/password_protected_keystore/ReloadSecureSettingsWithPasswordProtectedKeystoreRestIT.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.test.rest.ESRestTestCase;
1515

1616
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
17+
import static org.hamcrest.Matchers.anyOf;
1718
import static org.hamcrest.Matchers.equalTo;
1819
import static org.hamcrest.Matchers.instanceOf;
1920
import static org.hamcrest.Matchers.nullValue;
@@ -43,7 +44,7 @@ public void testReloadSecureSettingsWithCorrectPassword() throws Exception {
4344
}
4445

4546
@SuppressWarnings("unchecked")
46-
public void testReloadSecureSettingsWithInCorrectPassword() throws Exception {
47+
public void testReloadSecureSettingsWithIncorrectPassword() throws Exception {
4748
final Request request = new Request("POST", "_nodes/reload_secure_settings");
4849
request.setJsonEntity("{\"secure_settings_password\":\"" + KEYSTORE_PASSWORD + randomAlphaOfLength(7) + "\"}");
4950
final Response response = client().performRequest(request);
@@ -56,7 +57,9 @@ public void testReloadSecureSettingsWithInCorrectPassword() throws Exception {
5657
assertThat(entry.getValue(), instanceOf(Map.class));
5758
final Map<String, Object> node = (Map<String, Object>) entry.getValue();
5859
assertThat(node.get("reload_exception"), instanceOf(Map.class));
59-
assertThat(ObjectPath.eval("reload_exception.reason", node), equalTo("Provided keystore password was incorrect"));
60+
assertThat(ObjectPath.eval("reload_exception.reason", node), anyOf(
61+
equalTo("Provided keystore password was incorrect"),
62+
equalTo("Keystore has been corrupted or tampered with")));
6063
assertThat(ObjectPath.eval("reload_exception.type", node), equalTo("security_exception"));
6164
}
6265
}
@@ -74,7 +77,9 @@ public void testReloadSecureSettingsWithEmptyPassword() throws Exception {
7477
assertThat(entry.getValue(), instanceOf(Map.class));
7578
final Map<String, Object> node = (Map<String, Object>) entry.getValue();
7679
assertThat(node.get("reload_exception"), instanceOf(Map.class));
77-
assertThat(ObjectPath.eval("reload_exception.reason", node), equalTo("Provided keystore password was incorrect"));
80+
assertThat(ObjectPath.eval("reload_exception.reason", node), anyOf(
81+
equalTo("Provided keystore password was incorrect"),
82+
equalTo("Keystore has been corrupted or tampered with")));
7883
assertThat(ObjectPath.eval("reload_exception.type", node), equalTo("security_exception"));
7984
}
8085
}

0 commit comments

Comments
 (0)