@@ -121,7 +121,7 @@ public void testToString() {
121121 }
122122
123123 public void testToXContentRoundtrip () throws Exception {
124- final RoleDescriptor descriptor = randomRoleDescriptor ();
124+ final RoleDescriptor descriptor = randomRoleDescriptor (Version . CURRENT );
125125 final XContentType xContentType = randomFrom (XContentType .values ());
126126 final BytesReference xContentValue = toShuffledXContent (descriptor , xContentType , ToXContent .EMPTY_PARAMS , false );
127127 final RoleDescriptor parsed = RoleDescriptor .parse (descriptor .getName (), xContentValue , false , xContentType );
@@ -234,7 +234,7 @@ public void testSerialization() throws Exception {
234234 BytesStreamOutput output = new BytesStreamOutput ();
235235 output .setVersion (version );
236236
237- final RoleDescriptor descriptor = randomRoleDescriptor ();
237+ final RoleDescriptor descriptor = randomRoleDescriptor (version );
238238 descriptor .writeTo (output );
239239 final NamedWriteableRegistry registry = new NamedWriteableRegistry (new XPackClientPlugin (Settings .EMPTY ).getNamedWriteables ());
240240 StreamInput streamInput = new NamedWriteableAwareStreamInput (
@@ -388,13 +388,16 @@ public void testIsEmpty() {
388388 }
389389 }
390390
391- private RoleDescriptor randomRoleDescriptor () {
391+ /**
392+ * @param compatibleVersion Return a role descriptor that is compatible with the features that existed in this version of Elasticsearch
393+ */
394+ private RoleDescriptor randomRoleDescriptor (Version compatibleVersion ) {
392395 final RoleDescriptor .IndicesPrivileges [] indexPrivileges = new RoleDescriptor .IndicesPrivileges [randomIntBetween (0 , 3 )];
393396 for (int i = 0 ; i < indexPrivileges .length ; i ++) {
394397 final RoleDescriptor .IndicesPrivileges .Builder builder = RoleDescriptor .IndicesPrivileges .builder ()
395398 .privileges (randomSubsetOf (randomIntBetween (1 , 4 ), IndexPrivilege .names ()))
396399 .indices (generateRandomStringArray (5 , randomIntBetween (3 , 9 ), false , false ))
397- .allowRestrictedIndices (randomBoolean ());
400+ .allowRestrictedIndices (compatibleVersion . onOrAfter ( Version . V_6_7_0 ) && randomBoolean ());
398401 if (randomBoolean ()) {
399402 builder .query (
400403 randomBoolean ()
0 commit comments