4747public class TransportChangePasswordActionTests extends ESTestCase {
4848
4949 public void testAnonymousUser () {
50+ final String hashingAlgorithm = randomFrom ("pbkdf2" , "pbkdf2_1000" , "bcrypt" , "bcrypt9" );
5051 Settings settings = Settings .builder ().put (AnonymousUser .ROLES_SETTING .getKey (), "superuser" ).build ();
5152 AnonymousUser anonymousUser = new AnonymousUser (settings );
5253 NativeUsersStore usersStore = mock (NativeUsersStore .class );
53- TransportService transportService = new TransportService (Settings .EMPTY , null , null , TransportService .NOOP_TRANSPORT_INTERCEPTOR ,
54+ Settings passwordHashingSettings = Settings .builder ().
55+ put (XPackSettings .PASSWORD_HASHING_ALGORITHM .getKey (), hashingAlgorithm ).build ();
56+ TransportService transportService = new TransportService (passwordHashingSettings , null , null , TransportService .NOOP_TRANSPORT_INTERCEPTOR ,
5457 x -> null , null , Collections .emptySet ());
5558 TransportChangePasswordAction action = new TransportChangePasswordAction (settings , transportService ,
5659 mock (ActionFilters .class ), usersStore );
5760
5861 ChangePasswordRequest request = new ChangePasswordRequest ();
62+ // Request will fail before the request hashing algorithm is checked, but we use the same algorithm as in settings for consistency
5963 request .username (anonymousUser .principal ());
60- request .passwordHash (Hasher .resolve (
61- randomFrom ("pbkdf2" , "pbkdf2_1000" , "bcrypt" , "bcrypt9" )).hash (SecuritySettingsSourceField .TEST_PASSWORD_SECURE_STRING ));
64+ request .passwordHash (Hasher .resolve (hashingAlgorithm ).hash (SecuritySettingsSourceField .TEST_PASSWORD_SECURE_STRING ));
6265
6366 final AtomicReference <Throwable > throwableRef = new AtomicReference <>();
6467 final AtomicReference <ChangePasswordResponse > responseRef = new AtomicReference <>();
@@ -81,16 +84,19 @@ public void onFailure(Exception e) {
8184 }
8285
8386 public void testInternalUsers () {
87+ final String hashingAlgorithm = randomFrom ("pbkdf2" , "pbkdf2_1000" , "bcrypt" , "bcrypt9" );
8488 NativeUsersStore usersStore = mock (NativeUsersStore .class );
85- TransportService transportService = new TransportService (Settings .EMPTY , null , null , TransportService .NOOP_TRANSPORT_INTERCEPTOR ,
89+ Settings passwordHashingSettings = Settings .builder ().
90+ put (XPackSettings .PASSWORD_HASHING_ALGORITHM .getKey (), hashingAlgorithm ).build ();
91+ TransportService transportService = new TransportService (passwordHashingSettings , null , null , TransportService .NOOP_TRANSPORT_INTERCEPTOR ,
8692 x -> null , null , Collections .emptySet ());
8793 TransportChangePasswordAction action = new TransportChangePasswordAction (Settings .EMPTY , transportService ,
8894 mock (ActionFilters .class ), usersStore );
8995
9096 ChangePasswordRequest request = new ChangePasswordRequest ();
9197 request .username (randomFrom (SystemUser .INSTANCE .principal (), XPackUser .INSTANCE .principal ()));
92- request . passwordHash ( Hasher . resolve (
93- randomFrom ( "pbkdf2" , "pbkdf2_1000" , "bcrypt" , "bcrypt9" ) ).hash (SecuritySettingsSourceField .TEST_PASSWORD_SECURE_STRING ));
98+ // Request will fail before the request hashing algorithm is checked, but we use the same algorithm as in settings for consistency
99+ request . passwordHash ( Hasher . resolve ( hashingAlgorithm ).hash (SecuritySettingsSourceField .TEST_PASSWORD_SECURE_STRING ));
94100
95101 final AtomicReference <Throwable > throwableRef = new AtomicReference <>();
96102 final AtomicReference <ChangePasswordResponse > responseRef = new AtomicReference <>();
@@ -153,7 +159,6 @@ public void onFailure(Exception e) {
153159 verify (usersStore , times (1 )).changePassword (eq (request ), any (ActionListener .class ));
154160 }
155161
156- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/31696" )
157162 public void testIncorrectPasswordHashingAlgorithm () {
158163 final User user = randomFrom (new ElasticUser (true ), new KibanaUser (true ), new User ("joe" ));
159164 final Hasher hasher = Hasher .resolve (randomFrom ("pbkdf2" , "pbkdf2_1000" , "bcrypt9" , "bcrypt5" ));
@@ -166,7 +171,7 @@ public void testIncorrectPasswordHashingAlgorithm() {
166171 TransportService transportService = new TransportService (Settings .EMPTY , null , null , TransportService .NOOP_TRANSPORT_INTERCEPTOR ,
167172 x -> null , null , Collections .emptySet ());
168173 Settings passwordHashingSettings = Settings .builder ().put (XPackSettings .PASSWORD_HASHING_ALGORITHM .getKey (),
169- randomFrom ("pbkdf2_50000" , "pbkdf2_10000 " , "bcrypt11" , "bcrypt8" , "bcrypt" )).build ();
174+ randomFrom ("pbkdf2_50000" , "pbkdf2_100000 " , "bcrypt11" , "bcrypt8" , "bcrypt" )).build ();
170175 TransportChangePasswordAction action = new TransportChangePasswordAction (passwordHashingSettings , transportService ,
171176 mock (ActionFilters .class ), usersStore );
172177 action .doExecute (mock (Task .class ), request , new ActionListener <ChangePasswordResponse >() {
0 commit comments