55 */
66package org .elasticsearch .license ;
77
8+ import org .elasticsearch .Version ;
89import org .elasticsearch .common .settings .Settings ;
910import org .elasticsearch .license .License .OperationMode ;
1011import org .elasticsearch .test .ESTestCase ;
12+ import org .elasticsearch .test .VersionUtils ;
1113import org .elasticsearch .xpack .core .XPackField ;
1214import org .elasticsearch .xpack .core .XPackSettings ;
1315
@@ -31,7 +33,7 @@ public class XPackLicenseStateTests extends ESTestCase {
3133 /** Creates a license state with the given license type and active state, and checks the given method returns expected. */
3234 void assertAllowed (OperationMode mode , boolean active , Predicate <XPackLicenseState > predicate , boolean expected ) {
3335 XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
34- licenseState .update (mode , active );
36+ licenseState .update (mode , active , null );
3537 assertEquals (expected , predicate .test (licenseState ));
3638 }
3739
@@ -102,7 +104,7 @@ public void testSecurityDefaults() {
102104 public void testSecurityBasic () {
103105 XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
104106 Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
105- licenseState .update (BASIC , true );
107+ licenseState .update (BASIC , true , null );
106108
107109 assertThat (licenseState .isAuthAllowed (), is (false ));
108110 assertThat (licenseState .isIpFilteringAllowed (), is (false ));
@@ -116,7 +118,7 @@ public void testSecurityBasic() {
116118 public void testSecurityBasicExpired () {
117119 XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
118120 Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
119- licenseState .update (BASIC , false );
121+ licenseState .update (BASIC , false , null );
120122
121123 assertThat (licenseState .isAuthAllowed (), is (false ));
122124 assertThat (licenseState .isIpFilteringAllowed (), is (false ));
@@ -130,7 +132,7 @@ public void testSecurityBasicExpired() {
130132 public void testSecurityStandard () {
131133 XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
132134 Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
133- licenseState .update (STANDARD , true );
135+ licenseState .update (STANDARD , true , null );
134136
135137 assertThat (licenseState .isAuthAllowed (), is (true ));
136138 assertThat (licenseState .isIpFilteringAllowed (), is (false ));
@@ -144,7 +146,7 @@ public void testSecurityStandard() {
144146 public void testSecurityStandardExpired () {
145147 XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
146148 Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
147- licenseState .update (STANDARD , false );
149+ licenseState .update (STANDARD , false , null );
148150
149151 assertThat (licenseState .isAuthAllowed (), is (true ));
150152 assertThat (licenseState .isIpFilteringAllowed (), is (false ));
@@ -158,7 +160,7 @@ public void testSecurityStandardExpired() {
158160 public void testSecurityGold () {
159161 XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
160162 Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
161- licenseState .update (GOLD , true );
163+ licenseState .update (GOLD , true , null );
162164
163165 assertThat (licenseState .isAuthAllowed (), is (true ));
164166 assertThat (licenseState .isIpFilteringAllowed (), is (true ));
@@ -172,7 +174,7 @@ public void testSecurityGold() {
172174 public void testSecurityGoldExpired () {
173175 XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
174176 Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
175- licenseState .update (GOLD , false );
177+ licenseState .update (GOLD , false , null );
176178
177179 assertThat (licenseState .isAuthAllowed (), is (true ));
178180 assertThat (licenseState .isIpFilteringAllowed (), is (true ));
@@ -186,7 +188,7 @@ public void testSecurityGoldExpired() {
186188 public void testSecurityPlatinum () {
187189 XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
188190 Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
189- licenseState .update (PLATINUM , true );
191+ licenseState .update (PLATINUM , true , null );
190192
191193 assertThat (licenseState .isAuthAllowed (), is (true ));
192194 assertThat (licenseState .isIpFilteringAllowed (), is (true ));
@@ -200,7 +202,7 @@ public void testSecurityPlatinum() {
200202 public void testSecurityPlatinumExpired () {
201203 XPackLicenseState licenseState = new XPackLicenseState (randomFrom (Settings .EMPTY ,
202204 Settings .builder ().put (XPackSettings .SECURITY_ENABLED .getKey (), true ).build ()));
203- licenseState .update (PLATINUM , false );
205+ licenseState .update (PLATINUM , false , null );
204206
205207 assertThat (licenseState .isAuthAllowed (), is (true ));
206208 assertThat (licenseState .isIpFilteringAllowed (), is (true ));
@@ -211,6 +213,34 @@ public void testSecurityPlatinumExpired() {
211213 assertThat (licenseState .isCustomRoleProvidersAllowed (), is (false ));
212214 }
213215
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+
214244 public void testSecurityAckBasicToNotGoldOrStandard () {
215245 OperationMode toMode = randomFrom (OperationMode .values (), mode -> mode != GOLD && mode != STANDARD );
216246 assertAckMesssages (XPackField .SECURITY , BASIC , toMode , 0 );
@@ -354,63 +384,63 @@ public void testSqlDefaults() {
354384
355385 public void testSqlBasic () {
356386 XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
357- licenseState .update (BASIC , true );
387+ licenseState .update (BASIC , true , null );
358388
359389 assertThat (licenseState .isSqlAllowed (), is (true ));
360390 assertThat (licenseState .isJdbcAllowed (), is (false ));
361391 }
362392
363393 public void testSqlBasicExpired () {
364394 XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
365- licenseState .update (BASIC , false );
395+ licenseState .update (BASIC , false , null );
366396
367397 assertThat (licenseState .isSqlAllowed (), is (false ));
368398 assertThat (licenseState .isJdbcAllowed (), is (false ));
369399 }
370400
371401 public void testSqlStandard () {
372402 XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
373- licenseState .update (STANDARD , true );
403+ licenseState .update (STANDARD , true , null );
374404
375405 assertThat (licenseState .isSqlAllowed (), is (true ));
376406 assertThat (licenseState .isJdbcAllowed (), is (false ));
377407 }
378408
379409 public void testSqlStandardExpired () {
380410 XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
381- licenseState .update (STANDARD , false );
411+ licenseState .update (STANDARD , false , null );
382412
383413 assertThat (licenseState .isSqlAllowed (), is (false ));
384414 assertThat (licenseState .isJdbcAllowed (), is (false ));
385415 }
386416
387417 public void testSqlGold () {
388418 XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
389- licenseState .update (GOLD , true );
419+ licenseState .update (GOLD , true , null );
390420
391421 assertThat (licenseState .isSqlAllowed (), is (true ));
392422 assertThat (licenseState .isJdbcAllowed (), is (false ));
393423 }
394424
395425 public void testSqlGoldExpired () {
396426 XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
397- licenseState .update (GOLD , false );
427+ licenseState .update (GOLD , false , null );
398428
399429 assertThat (licenseState .isSqlAllowed (), is (false ));
400430 assertThat (licenseState .isJdbcAllowed (), is (false ));
401431 }
402432
403433 public void testSqlPlatinum () {
404434 XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
405- licenseState .update (PLATINUM , true );
435+ licenseState .update (PLATINUM , true , null );
406436
407437 assertThat (licenseState .isSqlAllowed (), is (true ));
408438 assertThat (licenseState .isJdbcAllowed (), is (true ));
409439 }
410440
411441 public void testSqlPlatinumExpired () {
412442 XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY );
413- licenseState .update (PLATINUM , false );
443+ licenseState .update (PLATINUM , false , null );
414444
415445 assertThat (licenseState .isSqlAllowed (), is (false ));
416446 assertThat (licenseState .isJdbcAllowed (), is (false ));
0 commit comments