-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Owais Kazi <[email protected]>
- Loading branch information
1 parent
00f912b
commit 025f21b
Showing
11 changed files
with
119 additions
and
28 deletions.
There are no files selected for viewing
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
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
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
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
47 changes: 47 additions & 0 deletions
47
src/test/java/org/opensearch/flowframework/util/RestHandlerUtilsTests.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,47 @@ | ||
/* | ||
* 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.flowframework.util; | ||
|
||
import org.opensearch.commons.authuser.User; | ||
import org.opensearch.search.builder.SearchSourceBuilder; | ||
import org.opensearch.search.fetch.subphase.FetchSourceContext; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class RestHandlerUtilsTests extends OpenSearchTestCase { | ||
|
||
public void testGetSourceContextFromClientWithDashboardExcludes() { | ||
SearchSourceBuilder testSearchSourceBuilder = new SearchSourceBuilder(); | ||
testSearchSourceBuilder.fetchSource(new String[] { "a" }, new String[] { "b" }); | ||
User user = new User("user", Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); | ||
FetchSourceContext sourceContext = RestHandlerUtils.getSourceContext(user, testSearchSourceBuilder); | ||
assertEquals(sourceContext.excludes().length, 4); | ||
} | ||
|
||
public void testGetSourceContextFromClientWithExcludes() { | ||
SearchSourceBuilder testSearchSourceBuilder = new SearchSourceBuilder(); | ||
User user = new User("user", Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); | ||
FetchSourceContext sourceContext = RestHandlerUtils.getSourceContext(user, testSearchSourceBuilder); | ||
assertEquals(sourceContext.excludes().length, 2); | ||
} | ||
|
||
public void testGetSourceContextAdminUser() { | ||
SearchSourceBuilder testSearchSourceBuilder = new SearchSourceBuilder(); | ||
List<String> roles = new ArrayList<>(); | ||
roles.add("all_access"); | ||
|
||
User user = new User("admin", roles, roles, Collections.emptyList()); | ||
FetchSourceContext sourceContext = RestHandlerUtils.getSourceContext(user, testSearchSourceBuilder); | ||
assertEquals(sourceContext.excludes().length, 1); | ||
} | ||
|
||
} |