47
47
public class TransportChangePasswordActionTests extends ESTestCase {
48
48
49
49
public void testAnonymousUser () {
50
+ final String hashingAlgorithm = randomFrom ("pbkdf2" , "pbkdf2_1000" , "bcrypt" , "bcrypt9" );
50
51
Settings settings = Settings .builder ().put (AnonymousUser .ROLES_SETTING .getKey (), "superuser" ).build ();
51
52
AnonymousUser anonymousUser = new AnonymousUser (settings );
52
53
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 ,
54
57
x -> null , null , Collections .emptySet ());
55
58
TransportChangePasswordAction action = new TransportChangePasswordAction (settings , transportService ,
56
59
mock (ActionFilters .class ), usersStore );
57
60
58
61
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
59
63
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 ));
62
65
63
66
final AtomicReference <Throwable > throwableRef = new AtomicReference <>();
64
67
final AtomicReference <ChangePasswordResponse > responseRef = new AtomicReference <>();
@@ -81,16 +84,19 @@ public void onFailure(Exception e) {
81
84
}
82
85
83
86
public void testInternalUsers () {
87
+ final String hashingAlgorithm = randomFrom ("pbkdf2" , "pbkdf2_1000" , "bcrypt" , "bcrypt9" );
84
88
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 ,
86
92
x -> null , null , Collections .emptySet ());
87
93
TransportChangePasswordAction action = new TransportChangePasswordAction (Settings .EMPTY , transportService ,
88
94
mock (ActionFilters .class ), usersStore );
89
95
90
96
ChangePasswordRequest request = new ChangePasswordRequest ();
91
97
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 ));
94
100
95
101
final AtomicReference <Throwable > throwableRef = new AtomicReference <>();
96
102
final AtomicReference <ChangePasswordResponse > responseRef = new AtomicReference <>();
@@ -153,7 +159,6 @@ public void onFailure(Exception e) {
153
159
verify (usersStore , times (1 )).changePassword (eq (request ), any (ActionListener .class ));
154
160
}
155
161
156
- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/31696" )
157
162
public void testIncorrectPasswordHashingAlgorithm () {
158
163
final User user = randomFrom (new ElasticUser (true ), new KibanaUser (true ), new User ("joe" ));
159
164
final Hasher hasher = Hasher .resolve (randomFrom ("pbkdf2" , "pbkdf2_1000" , "bcrypt9" , "bcrypt5" ));
@@ -166,7 +171,7 @@ public void testIncorrectPasswordHashingAlgorithm() {
166
171
TransportService transportService = new TransportService (Settings .EMPTY , null , null , TransportService .NOOP_TRANSPORT_INTERCEPTOR ,
167
172
x -> null , null , Collections .emptySet ());
168
173
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 ();
170
175
TransportChangePasswordAction action = new TransportChangePasswordAction (passwordHashingSettings , transportService ,
171
176
mock (ActionFilters .class ), usersStore );
172
177
action .doExecute (mock (Task .class ), request , new ActionListener <ChangePasswordResponse >() {
0 commit comments