-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds test to verify that index-template update is a cluster level per…
…mission Signed-off-by: Darshit Chanpura <[email protected]>
- Loading branch information
1 parent
fbb87c9
commit e5c6b46
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/test/java/org/opensearch/security/IndexTemplateClusterPermissionsCheckTest.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,52 @@ | ||
|
||
|
||
/* | ||
* Copyright OpenSearch Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the \"License\"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the \"license\" file accompanying this file. This file is distributed | ||
* on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package org.opensearch.security; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import org.opensearch.security.test.SingleClusterTest; | ||
import org.opensearch.security.test.helper.rest.RestHelper; | ||
import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse; | ||
|
||
public class IndexTemplateClusterPermissionsCheckTest extends SingleClusterTest{ | ||
public String getIndexTemplateBody() { | ||
return "{ \"index_patterns\": [\"sem1234*\"], \"template\": { \"settings\": { \"number_of_shards\": 2, \"number_of_replicas\": 1 }, \"mappings\": { \"properties\": { \"timestamp\": { \"type\": \"date\", \"format\": \"yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis\" }, \"value\": { \"type\": \"double\" } } } } }"; | ||
} | ||
|
||
@Test | ||
public void testPutIndexTemplate() throws Exception { | ||
setup(); | ||
RestHelper rh = nonSslRestHelper(); | ||
HttpResponse response; | ||
|
||
String expectedFailureResponse = "{\"error\":{\"root_cause\":[{\"type\":\"security_exception\",\"reason\":\"no permissions for [indices:admin/index_template/put] and User [name=ds3, backend_roles=[], requestedTenant=null]\"}],\"type\":\"security_exception\",\"reason\":\"no permissions for [indices:admin/index_template/put] and User [name=ds3, backend_roles=[], requestedTenant=null]\"},\"status\":403}"; | ||
|
||
// should fail, as `ds3` user doesn't have correct permissions | ||
response = rh.executePutRequest("/_index_template/sem1234", getIndexTemplateBody(), encodeBasicHeader("ds3", "nagilum")); | ||
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode()); | ||
Assert.assertEquals(expectedFailureResponse, response.getBody()); | ||
|
||
// should pass, as `sem-user` user has correct permissions | ||
response = rh.executePutRequest("/_index_template/sem1234", getIndexTemplateBody(), encodeBasicHeader("sem-user", "nagilum")); | ||
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); | ||
} | ||
|
||
|
||
} |
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
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
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 |
---|---|---|
|
@@ -413,3 +413,8 @@ data_stream_3: | |
hidden: false | ||
users: | ||
- "ds3" | ||
sem-role: | ||
reserved: false | ||
hidden: false | ||
users: | ||
- "sem-user" |