-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that IndexResolverReplacer resolves to indices for RolloverReq…
…uests (#5076) Signed-off-by: Craig Perkins <[email protected]>
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
src/integrationTest/java/org/opensearch/security/RolloverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
*/ | ||
package org.opensearch.security; | ||
|
||
import java.io.IOException; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.opensearch.core.rest.RestStatus; | ||
import org.opensearch.test.framework.AuditCompliance; | ||
import org.opensearch.test.framework.AuditConfiguration; | ||
import org.opensearch.test.framework.AuditFilters; | ||
import org.opensearch.test.framework.TestSecurityConfig.Role; | ||
import org.opensearch.test.framework.TestSecurityConfig.User; | ||
import org.opensearch.test.framework.cluster.ClusterManager; | ||
import org.opensearch.test.framework.cluster.LocalCluster; | ||
import org.opensearch.test.framework.cluster.TestRestClient; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.opensearch.test.framework.TestSecurityConfig.AuthcDomain.AUTHC_HTTPBASIC_INTERNAL; | ||
import static org.opensearch.test.framework.TestSecurityConfig.Role.ALL_ACCESS; | ||
|
||
@RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class) | ||
@ThreadLeakScope(ThreadLeakScope.Scope.NONE) | ||
public class RolloverTest { | ||
|
||
private static final Logger log = LogManager.getLogger(RolloverTest.class); | ||
|
||
static final User ADMIN_USER = new User("admin").roles(ALL_ACCESS); | ||
|
||
static final User LIMITED_USER = new User("limited_user").roles( | ||
new Role("limited-role").indexPermissions("indices:admin/rollover", "indices:monitor/stats").on("logs*") | ||
); | ||
|
||
@ClassRule | ||
public static final LocalCluster cluster = new LocalCluster.Builder().clusterManager(ClusterManager.THREE_CLUSTER_MANAGERS) | ||
.anonymousAuth(false) | ||
.authc(AUTHC_HTTPBASIC_INTERNAL) | ||
.users(ADMIN_USER, LIMITED_USER) | ||
.audit( | ||
new AuditConfiguration(true).compliance(new AuditCompliance().enabled(true)) | ||
.filters(new AuditFilters().enabledRest(true).enabledTransport(true)) | ||
) | ||
.build(); | ||
|
||
@Test | ||
public void testRolloverWithLimitedUser() throws IOException { | ||
try (TestRestClient client = cluster.getRestClient(ADMIN_USER)) { | ||
client.put("index-that-limited-user-does-not-have-access-to"); | ||
client.put("logs-old-index"); | ||
client.put("logs-old-index/_aliases/logs"); | ||
} | ||
try (TestRestClient client = cluster.getRestClient(LIMITED_USER)) { | ||
String rolloverRequest = "{\"conditions\": {\"max_age\": \"0s\"}}"; | ||
TestRestClient.HttpResponse response = client.postJson("logs/_rollover/logs-new-index", rolloverRequest); | ||
|
||
assertThat(response.getStatusCode(), equalTo(RestStatus.OK.getStatus())); | ||
assertThat( | ||
response.getBody(), | ||
containsString("\"old_index\":\"logs-old-index\",\"new_index\":\"logs-new-index\",\"rolled_over\":true") | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters