@@ -551,19 +551,27 @@ public static class DataStreams {
551551 final String primaryAction ;
552552 final ImmutableSet <String > requiredActions ;
553553 final ImmutableSet <String > otherActions ;
554- final RoleBasedActionPrivileges subject ;
554+ final Statefulness statefulness ;
555555
556556 @ Test
557557 public void positive_full () throws Exception {
558558 PrivilegesEvaluationContext ctx = ctx ().roles ("test_role" ).indexMetadata (INDEX_METADATA ).get ();
559- PrivilegesEvaluatorResponse result = subject .hasIndexPrivilege (ctx , requiredActions , resolved ("data_stream_a11" ));
559+ PrivilegesEvaluatorResponse result = subject ( false ) .hasIndexPrivilege (ctx , requiredActions , resolved ("data_stream_a11" ));
560560 if (covers (ctx , "data_stream_a11" )) {
561561 assertThat (result , isAllowed ());
562- } else if (covers (ctx , ".ds-data_stream_a11-000001" )) {
563- assertThat (
564- result ,
565- isPartiallyOk (".ds-data_stream_a11-000001" , ".ds-data_stream_a11-000002" , ".ds-data_stream_a11-000003" )
566- );
562+ } else {
563+ assertThat (result , isForbidden (missingPrivileges (requiredActions )));
564+ }
565+ }
566+
567+ @ Test
568+ public void positive_full_breakDownAliases () throws Exception {
569+ PrivilegesEvaluationContext ctx = ctx ().roles ("test_role" ).indexMetadata (INDEX_METADATA ).get ();
570+ PrivilegesEvaluatorResponse result = subject (true ).hasIndexPrivilege (ctx , requiredActions , resolved ("data_stream_a11" ));
571+ if (covers (ctx , "data_stream_a11" )) {
572+ assertThat (result , isAllowed ());
573+ } else if (covers (ctx , ".ds-data_stream_a11" )) {
574+ assertThat (result , isAllowed ());
567575 } else {
568576 assertThat (result , isForbidden (missingPrivileges (requiredActions )));
569577 }
@@ -572,7 +580,7 @@ public void positive_full() throws Exception {
572580 @ Test
573581 public void positive_partial () throws Exception {
574582 PrivilegesEvaluationContext ctx = ctx ().roles ("test_role" ).indexMetadata (INDEX_METADATA ).get ();
575- PrivilegesEvaluatorResponse result = subject .hasIndexPrivilege (
583+ PrivilegesEvaluatorResponse result = subject ( false ) .hasIndexPrivilege (
576584 ctx ,
577585 requiredActions ,
578586 resolved ("data_stream_a11" , "data_stream_a12" )
@@ -584,16 +592,38 @@ public void positive_partial() throws Exception {
584592 assertThat (
585593 result ,
586594 isPartiallyOk (
587- "data_stream_a11" ,
588- ".ds-data_stream_a11-000001" ,
589- ".ds-data_stream_a11-000002" ,
590- ".ds-data_stream_a11-000003"
595+ "data_stream_a11"
591596 )
592597 );
593- } else if (covers (ctx , ".ds-data_stream_a11-000001" )) {
598+ } else {
599+ assertThat (result , isForbidden (missingPrivileges (requiredActions )));
600+ }
601+ }
602+
603+ @ Test
604+ public void positive_partial_breakDownAliases () throws Exception {
605+ PrivilegesEvaluationContext ctx = ctx ().roles ("test_role" ).indexMetadata (INDEX_METADATA ).get ();
606+ PrivilegesEvaluatorResponse result = subject (true ).hasIndexPrivilege (
607+ ctx ,
608+ requiredActions ,
609+ resolved ("data_stream_a11" , "data_stream_a12" )
610+ );
611+
612+ if (covers (ctx , "data_stream_a11" , "data_stream_a12" )) {
613+ assertThat (result , isAllowed ());
614+ } else if (covers (ctx , "data_stream_a11" )) {
594615 assertThat (
595- result ,
596- isPartiallyOk (".ds-data_stream_a11-000001" , ".ds-data_stream_a11-000002" , ".ds-data_stream_a11-000003" )
616+ result ,
617+ isPartiallyOk (
618+ "data_stream_a11"
619+ )
620+ );
621+ } else if (covers (ctx , ".ds-data_stream_a11" )) {
622+ assertThat (
623+ result ,
624+ isPartiallyOk (
625+ "data_stream_a11"
626+ )
597627 );
598628 } else {
599629 assertThat (result , isForbidden (missingPrivileges (requiredActions )));
@@ -603,14 +633,14 @@ public void positive_partial() throws Exception {
603633 @ Test
604634 public void negative_wrongRole () throws Exception {
605635 PrivilegesEvaluationContext ctx = ctx ().roles ("other_role" ).indexMetadata (INDEX_METADATA ).get ();
606- PrivilegesEvaluatorResponse result = subject .hasIndexPrivilege (ctx , requiredActions , resolved ("data_stream_a11" ));
636+ PrivilegesEvaluatorResponse result = subject ( false ) .hasIndexPrivilege (ctx , requiredActions , resolved ("data_stream_a11" ));
607637 assertThat (result , isForbidden (missingPrivileges (requiredActions )));
608638 }
609639
610640 @ Test
611641 public void negative_wrongAction () throws Exception {
612642 PrivilegesEvaluationContext ctx = ctx ().roles ("test_role" ).indexMetadata (INDEX_METADATA ).get ();
613- PrivilegesEvaluatorResponse result = subject .hasIndexPrivilege (ctx , otherActions , resolved ("data_stream_a11" ));
643+ PrivilegesEvaluatorResponse result = subject ( false ) .hasIndexPrivilege (ctx , otherActions , resolved ("data_stream_a11" ));
614644 assertThat (result , isForbidden (missingPrivileges (otherActions )));
615645 }
616646
@@ -676,28 +706,33 @@ public DataStreams(IndexSpec indexSpec, ActionSpec actionSpec, Statefulness stat
676706 ? ImmutableSet .of ("indices:data/write/update" )
677707 : ImmutableSet .of ("indices:foobar/unknown" );
678708 this .indexSpec .indexMetadata = INDEX_METADATA .getIndicesLookup ();
709+ this .statefulness = statefulness ;
710+ }
679711
712+ private RoleBasedActionPrivileges subject (boolean breakDownAliases ) {
680713 Settings settings = Settings .EMPTY ;
681714 if (statefulness == Statefulness .STATEFUL_LIMITED ) {
682715 settings = Settings .builder ()
683- .put (
684- RoleBasedActionPrivileges .PRECOMPUTED_PRIVILEGES_MAX_HEAP_SIZE .getKey (),
685- new ByteSizeValue (10 , ByteSizeUnit .BYTES )
686- )
687- .build ();
716+ .put (
717+ RoleBasedActionPrivileges .PRECOMPUTED_PRIVILEGES_MAX_HEAP_SIZE .getKey (),
718+ new ByteSizeValue (10 , ByteSizeUnit .BYTES )
719+ )
720+ .build ();
688721 }
689722
690- this . subject = new RoleBasedActionPrivileges (
691- roles ,
692- FlattenedActionGroups .EMPTY ,
693- RuntimeOptimizedActionPrivileges .SpecialIndexProtection .NONE ,
694- settings ,
695- false
723+ RoleBasedActionPrivileges result = new RoleBasedActionPrivileges (
724+ roles ,
725+ FlattenedActionGroups .EMPTY ,
726+ RuntimeOptimizedActionPrivileges .SpecialIndexProtection .NONE ,
727+ settings ,
728+ breakDownAliases
696729 );
697730
698731 if (statefulness == Statefulness .STATEFUL || statefulness == Statefulness .STATEFUL_LIMITED ) {
699- this . subject .updateStatefulIndexPrivileges (INDEX_METADATA .getIndicesLookup (), 1 );
732+ result .updateStatefulIndexPrivileges (INDEX_METADATA .getIndicesLookup (), 1 );
700733 }
734+
735+ return result ;
701736 }
702737
703738 final static Metadata INDEX_METADATA = //
@@ -706,22 +741,6 @@ public DataStreams(IndexSpec indexSpec, ActionSpec actionSpec, Statefulness stat
706741
707742 static ResolvedIndices resolved (String ... indices ) {
708743 return ResolvedIndices .of (indices );
709- // TODO check
710- // ImmutableSet.Builder<String> allIndices = ImmutableSet.builder();
711- //
712- //
713- // for (String index : indices) {
714- // IndexAbstraction indexAbstraction = INDEX_METADATA.getIndicesLookup().get(index);
715- //
716- // if (indexAbstraction instanceof IndexAbstraction.DataStream) {
717- // allIndices.addAll(
718- // indexAbstraction.getIndices().stream().map(i -> i.getIndex().getName()).collect(Collectors.toList())
719- // );
720- // }
721- //
722- // allIndices.add(index);
723- // }
724-
725744 }
726745 }
727746
@@ -849,21 +868,6 @@ enum Statefulness {
849868 }
850869
851870 public static class Misc {
852- @ Test
853- public void relevantOnly_identity () throws Exception {
854- Map <String , IndexAbstraction > metadata = //
855- indices ("index_a11" , "index_a12" , "index_b" )//
856- .alias ("alias_a" )
857- .of ("index_a11" , "index_a12" )//
858- .build ()
859- .getIndicesLookup ();
860-
861- assertTrue (
862- "relevantOnly() returned identical object" ,
863- RoleBasedActionPrivileges .StatefulIndexPrivileges .relevantOnly (metadata , i -> false ) == metadata
864- );
865- }
866-
867871 @ Test
868872 public void relevantOnly_closed () throws Exception {
869873 Map <String , IndexAbstraction > metadata = indices ("index_open_1" , "index_open_2" )//
@@ -942,7 +946,7 @@ public void hasIndexPrivilege_errors() throws Exception {
942946 assertTrue (
943947 "Result mentions role_with_errors: " + result .getEvaluationExceptionInfo (),
944948 result .getEvaluationExceptionInfo ()
945- .startsWith ("Exceptions encountered during privilege evaluation:\n " + "Error while evaluating" )
949+ .contains ("Exceptions encountered during privilege evaluation:\n " + "Error while evaluating" )
946950 );
947951 }
948952
@@ -1075,7 +1079,7 @@ public void hasExplicitIndexPrivilege_errors() throws Exception {
10751079 assertTrue (
10761080 "Result mentions role_with_errors: " + result .getEvaluationExceptionInfo (),
10771081 result .getEvaluationExceptionInfo ()
1078- .startsWith ("Exceptions encountered during privilege evaluation:\n " + "Error while evaluating role role_with_errors" )
1082+ .contains ("Exceptions encountered during privilege evaluation:\n " + "Error while evaluating role role_with_errors" )
10791083 );
10801084 }
10811085
0 commit comments