-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Security / Build permission filter based on user info.
- Loading branch information
1 parent
6bf1fe5
commit c12f5fa
Showing
11 changed files
with
147 additions
and
31 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
65 changes: 65 additions & 0 deletions
65
modules/services/searching/src/test/java/org/fao/geonet/common/search/FilterBuilderTest.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,65 @@ | ||
/** | ||
* (c) 2020 Open Source Geospatial Foundation - all rights reserved This code is licensed under the | ||
* GPL 2.0 license, available at the root application directory. | ||
*/ | ||
|
||
package org.fao.geonet.common.search; | ||
|
||
import org.fao.geonet.common.search.domain.Profile; | ||
import org.fao.geonet.common.search.domain.UserInfo; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
|
||
public class FilterBuilderTest { | ||
|
||
FilterBuilder filterBuilder; | ||
|
||
@Before | ||
public void setup() { | ||
this.filterBuilder = new FilterBuilder(); | ||
} | ||
|
||
@Test | ||
public void testFilterType() { | ||
UserInfo userInfo = new UserInfo(); | ||
String queryFilter = filterBuilder.buildQueryFilter("", userInfo); | ||
assertTrue(queryFilter.contains("op0:(1) AND (draft:n OR draft:e)")); | ||
queryFilter = filterBuilder.buildQueryFilter("metadata", userInfo); | ||
assertTrue(queryFilter.contains("op0:(1) AND (isTemplate:n) AND (draft:n OR draft:e)")); | ||
queryFilter = filterBuilder.buildQueryFilter("template", userInfo); | ||
assertTrue(queryFilter.contains("op0:(1) AND (isTemplate:y) AND (draft:n OR draft:e)")); | ||
queryFilter = filterBuilder.buildQueryFilter("subtemplate", userInfo); | ||
assertTrue(queryFilter.contains("op0:(1) AND (isTemplate:s) AND (draft:n OR draft:e)")); | ||
} | ||
|
||
@Test | ||
public void testFilterForAnonymousUser() { | ||
UserInfo userInfo = new UserInfo(); | ||
String queryFilter = filterBuilder.buildQueryFilter("metadata", userInfo); | ||
assertTrue(queryFilter.contains("op0:(1) AND (isTemplate:n) AND (draft:n OR draft:e)")); | ||
} | ||
|
||
@Test | ||
public void testFilterForAdministrator() { | ||
UserInfo userInfo = new UserInfo(); | ||
userInfo.setHighestProfile(Profile.Administrator.name()); | ||
String queryFilter = filterBuilder.buildQueryFilter("metadata", userInfo); | ||
assertTrue(queryFilter.contains("* AND (isTemplate:n) AND (draft:n OR draft:e)")); | ||
} | ||
|
||
@Test | ||
public void testFilterForEditor() { | ||
UserInfo userInfo = new UserInfo(); | ||
userInfo.setUserName("Dad"); | ||
userInfo.setUserId(999); | ||
userInfo.setHighestProfile(Profile.Editor.name()); | ||
userInfo.setEditingGroups(Arrays.asList(new Integer[]{10, 11, 12})); | ||
String queryFilter = filterBuilder.buildQueryFilter("metadata", userInfo); | ||
assertTrue(queryFilter.contains("(op0:(1 OR 10 OR 11 OR 12) owner:999) AND (isTemplate:n) AND (draft:n OR draft:e)")); | ||
} | ||
} |