Skip to content

Commit 60b1f57

Browse files
committed
Fix RealmInteg test failures
As part of the changes in elastic#31234,the password verification logic determines the algorithm used for hashing the password from the format of the stored password hash itself. Thus, it is generally possible to validate a password even if it's associated stored hash was not created with the same algorithm than the one currently set in the settings. At the same time, we introduced a check for incoming client change password requests to make sure that the request's password is hashed with the same algorithm that is configured to be used in the node settings. In the spirit of randomizing the algorithms used, the {@code SecurityClient} used in the {@code NativeRealmIntegTests} and {@code ReservedRealmIntegTests} would send all requests dealing with user passwords by randomly selecting a hashing algorithm each time. This meant that some change password requests were using a different password hashing algorithm than the one used for the node and the request would fail. This commit changes this behavior in the two aforementioned Integ tests to use the same password hashing algorithm for the node and the clients, no matter what the request is. Resolves elastic#31670
1 parent f77559c commit 60b1f57

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/esnative/ReservedRealmIntegTests.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
import org.elasticsearch.ElasticsearchSecurityException;
99
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
1010
import org.elasticsearch.common.settings.SecureString;
11+
import org.elasticsearch.common.settings.Settings;
1112
import org.elasticsearch.test.NativeRealmIntegTestCase;
1213
import org.elasticsearch.xpack.core.security.action.user.ChangePasswordResponse;
14+
import org.elasticsearch.xpack.core.security.authc.support.Hasher;
1315
import org.elasticsearch.xpack.core.security.client.SecurityClient;
1416
import org.elasticsearch.xpack.core.security.user.BeatsSystemUser;
1517
import org.elasticsearch.xpack.core.security.user.ElasticUser;
1618
import org.elasticsearch.xpack.core.security.user.KibanaUser;
1719
import org.elasticsearch.xpack.core.security.user.LogstashSystemUser;
20+
import org.junit.BeforeClass;
1821

1922
import java.util.Arrays;
2023

@@ -29,6 +32,22 @@
2932
*/
3033
public class ReservedRealmIntegTests extends NativeRealmIntegTestCase {
3134

35+
private static Hasher hasher;
36+
37+
@BeforeClass
38+
public static void setHasher() {
39+
hasher = getFastStoredHashAlgoForTests();
40+
}
41+
42+
@Override
43+
public Settings nodeSettings(int nodeOrdinal) {
44+
Settings settings = Settings.builder()
45+
.put(super.nodeSettings(nodeOrdinal))
46+
.put("xpack.security.authc.password_hashing.algorithm", hasher.name())
47+
.build();
48+
return settings;
49+
}
50+
3251
public void testAuthenticate() {
3352
for (String username : Arrays.asList(ElasticUser.NAME, KibanaUser.NAME, LogstashSystemUser.NAME, BeatsSystemUser.NAME)) {
3453
ClusterHealthResponse response = client()
@@ -76,7 +95,7 @@ public void testChangingPassword() {
7695
}
7796

7897
ChangePasswordResponse response = securityClient()
79-
.prepareChangePassword(username, Arrays.copyOf(newPassword, newPassword.length), getFastStoredHashAlgoForTests())
98+
.prepareChangePassword(username, Arrays.copyOf(newPassword, newPassword.length), hasher)
8099
.get();
81100
assertThat(response, notNullValue());
82101

0 commit comments

Comments
 (0)