2626
2727import static org .hamcrest .MatcherAssert .assertThat ;
2828import static org .hamcrest .Matchers .containsString ;
29- import static org .hamcrest .Matchers .not ;
3029import static org .opensearch .security .privileges .int_tests .SystemIndexRestoreIntTests .ELIGIBLE ;
30+ import static org .opensearch .security .privileges .int_tests .SystemIndexRestoreIntTests .NOT_ELIGIBLE ;
3131import static org .opensearch .security .privileges .int_tests .SystemIndexRestoreIntTests .REST_ADMIN ;
3232import static org .opensearch .security .privileges .int_tests .SystemIndexRestoreIntTests .cleanup ;
3333import static org .opensearch .security .privileges .int_tests .SystemIndexRestoreIntTests .createIndicesAndSnapshot ;
3434import static org .opensearch .security .privileges .int_tests .SystemIndexRestoreIntTests .restorePath ;
3535import static org .opensearch .test .framework .cluster .TestRestClient .json ;
3636import static org .opensearch .test .framework .matcher .RestMatchers .isForbidden ;
37+ import static org .opensearch .test .framework .matcher .RestMatchers .isOk ;
3738
3839/**
39- * With {@code plugins.security.system_indices.restore.indices} left at its empty default, a REST admin cannot
40- * restore any system index , for both the legacy and the V4 privilege evaluation.
40+ * With {@code plugins.security.system_indices.restore.indices} left at its default, a REST admin can restore the system
41+ * indices in the default list and no others , for both the legacy and the V4 privilege evaluation.
4142 */
4243@ RunWith (Parameterized .class )
4344public class SystemIndexRestoreDefaultIntTests {
@@ -50,18 +51,29 @@ public class SystemIndexRestoreDefaultIntTests {
5051 final LocalCluster cluster ;
5152
5253 @ Test
53- public void restAdmin_cannotRestoreSystemIndexWhenNoneConfigured () {
54+ public void restAdmin_restoresSystemIndicesInDefaultList () {
5455 createIndicesAndSnapshot (cluster , "snap_default" , ELIGIBLE );
5556 try (TestRestClient client = cluster .getRestClient (REST_ADMIN )) {
5657 TestRestClient .HttpResponse response = client .post (restorePath ("snap_default" ), json ("indices" , List .of (ELIGIBLE )));
57- assertThat (response , isForbidden ());
58- assertThat (response .getBody (), containsString ("[" + ELIGIBLE + "] are not eligible for restore." ));
59- assertThat (response .getBody (), not (containsString ("Restorable system indices" )));
58+ assertThat (response , isOk ());
6059 } finally {
6160 cleanup (cluster , "snap_default" , ELIGIBLE );
6261 }
6362 }
6463
64+ @ Test
65+ public void restAdmin_cannotRestoreSystemIndexOutsideDefaultList () {
66+ createIndicesAndSnapshot (cluster , "snap_not_in_default" , NOT_ELIGIBLE );
67+ try (TestRestClient client = cluster .getRestClient (REST_ADMIN )) {
68+ TestRestClient .HttpResponse response = client .post (restorePath ("snap_not_in_default" ), json ("indices" , List .of (NOT_ELIGIBLE )));
69+ assertThat (response , isForbidden ());
70+ assertThat (response .getBody (), containsString ("[" + NOT_ELIGIBLE + "] are not eligible for restore." ));
71+ assertThat (response .getBody (), containsString ("Restorable system indices: [" + ELIGIBLE ));
72+ } finally {
73+ cleanup (cluster , "snap_not_in_default" , NOT_ELIGIBLE );
74+ }
75+ }
76+
6577 @ Parameters (name = "{0}" )
6678 public static Collection <Object []> params () {
6779 List <Object []> result = new ArrayList <>();
0 commit comments