5
5
*/
6
6
package org .elasticsearch .license ;
7
7
8
+ import org .elasticsearch .Version ;
8
9
import org .elasticsearch .common .settings .Settings ;
9
10
import org .elasticsearch .license .License .OperationMode ;
10
11
import org .elasticsearch .test .ESTestCase ;
12
+ import org .elasticsearch .test .VersionUtils ;
11
13
import org .elasticsearch .xpack .core .XPackField ;
12
14
import org .elasticsearch .xpack .core .XPackSettings ;
13
15
@@ -31,7 +33,7 @@ public class XPackLicenseStateTests extends ESTestCase {
31
33
/** Creates a license state with the given license type and active state, and checks the given method returns expected. */
32
34
void assertAllowed (OperationMode mode , boolean active , Predicate <XPackLicenseState > predicate , boolean expected ) {
33
35
XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
34
- licenseState .update (mode , active );
36
+ licenseState .update (mode , active , null );
35
37
assertEquals (expected , predicate .test (licenseState ));
36
38
}
37
39
@@ -102,7 +104,7 @@ public void testSecurityDefaults() {
102
104
public void testSecurityBasic () {
103
105
XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
104
106
Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
105
- licenseState .update (BASIC , true );
107
+ licenseState .update (BASIC , true , null );
106
108
107
109
assertThat (licenseState .isAuthAllowed (), is (false ));
108
110
assertThat (licenseState .isIpFilteringAllowed (), is (false ));
@@ -116,7 +118,7 @@ public void testSecurityBasic() {
116
118
public void testSecurityBasicExpired () {
117
119
XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
118
120
Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
119
- licenseState .update (BASIC , false );
121
+ licenseState .update (BASIC , false , null );
120
122
121
123
assertThat (licenseState .isAuthAllowed (), is (false ));
122
124
assertThat (licenseState .isIpFilteringAllowed (), is (false ));
@@ -130,7 +132,7 @@ public void testSecurityBasicExpired() {
130
132
public void testSecurityStandard () {
131
133
XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
132
134
Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
133
- licenseState .update (STANDARD , true );
135
+ licenseState .update (STANDARD , true , null );
134
136
135
137
assertThat (licenseState .isAuthAllowed (), is (true ));
136
138
assertThat (licenseState .isIpFilteringAllowed (), is (false ));
@@ -144,7 +146,7 @@ public void testSecurityStandard() {
144
146
public void testSecurityStandardExpired () {
145
147
XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
146
148
Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
147
- licenseState .update (STANDARD , false );
149
+ licenseState .update (STANDARD , false , null );
148
150
149
151
assertThat (licenseState .isAuthAllowed (), is (true ));
150
152
assertThat (licenseState .isIpFilteringAllowed (), is (false ));
@@ -158,7 +160,7 @@ public void testSecurityStandardExpired() {
158
160
public void testSecurityGold () {
159
161
XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
160
162
Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
161
- licenseState .update (GOLD , true );
163
+ licenseState .update (GOLD , true , null );
162
164
163
165
assertThat (licenseState .isAuthAllowed (), is (true ));
164
166
assertThat (licenseState .isIpFilteringAllowed (), is (true ));
@@ -172,7 +174,7 @@ public void testSecurityGold() {
172
174
public void testSecurityGoldExpired () {
173
175
XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
174
176
Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
175
- licenseState .update (GOLD , false );
177
+ licenseState .update (GOLD , false , null );
176
178
177
179
assertThat (licenseState .isAuthAllowed (), is (true ));
178
180
assertThat (licenseState .isIpFilteringAllowed (), is (true ));
@@ -186,7 +188,7 @@ public void testSecurityGoldExpired() {
186
188
public void testSecurityPlatinum () {
187
189
XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
188
190
Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
189
- licenseState .update (PLATINUM , true );
191
+ licenseState .update (PLATINUM , true , null );
190
192
191
193
assertThat (licenseState .isAuthAllowed (), is (true ));
192
194
assertThat (licenseState .isIpFilteringAllowed (), is (true ));
@@ -200,7 +202,7 @@ public void testSecurityPlatinum() {
200
202
public void testSecurityPlatinumExpired () {
201
203
XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
202
204
Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
203
- licenseState .update (PLATINUM , false );
205
+ licenseState .update (PLATINUM , false , null );
204
206
205
207
assertThat (licenseState .isAuthAllowed (), is (true ));
206
208
assertThat (licenseState .isIpFilteringAllowed (), is (true ));
@@ -211,6 +213,34 @@ public void testSecurityPlatinumExpired() {
211
213
assertThat (licenseState .isCustomRoleProvidersAllowed (), is (false ));
212
214
}
213
215
216
+ public void testNewTrialDefaultsSecurityOff () {
217
+ XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
218
+ licenseState .update (TRIAL , true , VersionUtils .randomVersionBetween (random (), Version .V_6_3_0 , Version .CURRENT ));
219
+
220
+ assertThat (licenseState .isSecurityEnabled (), is (false ));
221
+ assertThat (licenseState .isAuthAllowed (), is (true ));
222
+ assertThat (licenseState .isIpFilteringAllowed (), is (true ));
223
+ assertThat (licenseState .isAuditingAllowed (), is (true ));
224
+ assertThat (licenseState .isStatsAndHealthAllowed (), is (true ));
225
+ assertThat (licenseState .isDocumentAndFieldLevelSecurityAllowed (), is (true ));
226
+ assertThat (licenseState .allowedRealmType (), is (XPackLicenseState .AllowedRealmType .ALL ));
227
+ assertThat (licenseState .isCustomRoleProvidersAllowed (), is (true ));
228
+ }
229
+
230
+ public void testOldTrialDefaultsSecurityOn () {
231
+ XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
232
+ licenseState .update (TRIAL , true , rarely () ? null : VersionUtils .randomVersionBetween (random (), Version .V_5_6_0 , Version .V_6_2_4 ));
233
+
234
+ assertThat (licenseState .isSecurityEnabled (), is (true ));
235
+ assertThat (licenseState .isAuthAllowed (), is (true ));
236
+ assertThat (licenseState .isIpFilteringAllowed (), is (true ));
237
+ assertThat (licenseState .isAuditingAllowed (), is (true ));
238
+ assertThat (licenseState .isStatsAndHealthAllowed (), is (true ));
239
+ assertThat (licenseState .isDocumentAndFieldLevelSecurityAllowed (), is (true ));
240
+ assertThat (licenseState .allowedRealmType (), is (XPackLicenseState .AllowedRealmType .ALL ));
241
+ assertThat (licenseState .isCustomRoleProvidersAllowed (), is (true ));
242
+ }
243
+
214
244
public void testSecurityAckBasicToNotGoldOrStandard () {
215
245
OperationMode toMode = randomFrom (OperationMode .values (), mode -> mode != GOLD && mode != STANDARD );
216
246
assertAckMesssages (XPackField .SECURITY , BASIC , toMode , 0 );
@@ -354,63 +384,63 @@ public void testSqlDefaults() {
354
384
355
385
public void testSqlBasic () {
356
386
XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
357
- licenseState .update (BASIC , true );
387
+ licenseState .update (BASIC , true , null );
358
388
359
389
assertThat (licenseState .isSqlAllowed (), is (true ));
360
390
assertThat (licenseState .isJdbcAllowed (), is (false ));
361
391
}
362
392
363
393
public void testSqlBasicExpired () {
364
394
XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
365
- licenseState .update (BASIC , false );
395
+ licenseState .update (BASIC , false , null );
366
396
367
397
assertThat (licenseState .isSqlAllowed (), is (false ));
368
398
assertThat (licenseState .isJdbcAllowed (), is (false ));
369
399
}
370
400
371
401
public void testSqlStandard () {
372
402
XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
373
- licenseState .update (STANDARD , true );
403
+ licenseState .update (STANDARD , true , null );
374
404
375
405
assertThat (licenseState .isSqlAllowed (), is (true ));
376
406
assertThat (licenseState .isJdbcAllowed (), is (false ));
377
407
}
378
408
379
409
public void testSqlStandardExpired () {
380
410
XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
381
- licenseState .update (STANDARD , false );
411
+ licenseState .update (STANDARD , false , null );
382
412
383
413
assertThat (licenseState .isSqlAllowed (), is (false ));
384
414
assertThat (licenseState .isJdbcAllowed (), is (false ));
385
415
}
386
416
387
417
public void testSqlGold () {
388
418
XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
389
- licenseState .update (GOLD , true );
419
+ licenseState .update (GOLD , true , null );
390
420
391
421
assertThat (licenseState .isSqlAllowed (), is (true ));
392
422
assertThat (licenseState .isJdbcAllowed (), is (false ));
393
423
}
394
424
395
425
public void testSqlGoldExpired () {
396
426
XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
397
- licenseState .update (GOLD , false );
427
+ licenseState .update (GOLD , false , null );
398
428
399
429
assertThat (licenseState .isSqlAllowed (), is (false ));
400
430
assertThat (licenseState .isJdbcAllowed (), is (false ));
401
431
}
402
432
403
433
public void testSqlPlatinum () {
404
434
XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
405
- licenseState .update (PLATINUM , true );
435
+ licenseState .update (PLATINUM , true , null );
406
436
407
437
assertThat (licenseState .isSqlAllowed (), is (true ));
408
438
assertThat (licenseState .isJdbcAllowed (), is (true ));
409
439
}
410
440
411
441
public void testSqlPlatinumExpired () {
412
442
XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
413
- licenseState .update (PLATINUM , false );
443
+ licenseState .update (PLATINUM , false , null );
414
444
415
445
assertThat (licenseState .isSqlAllowed (), is (false ));
416
446
assertThat (licenseState .isJdbcAllowed (), is (false ));
0 commit comments