use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.
the class XmlAttributeSecurityPolicyPluginTest method testProcessUnusedMethods.
@Test
public void testProcessUnusedMethods() throws StopProcessingException {
PolicyResponse policyResponse = plugin.processPreQuery(new QueryImpl(Filter.INCLUDE), new HashMap<>());
org.junit.Assert.assertThat(policyResponse.itemPolicy().entrySet().size(), Matchers.is(0));
policyResponse = plugin.processPreResource(new ResourceRequestById(""));
org.junit.Assert.assertThat(policyResponse.itemPolicy().entrySet().size(), Matchers.is(0));
}
use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.
the class XmlAttributeSecurityPolicyPluginTest method testProcessPreDelete.
@Test
public void testProcessPreDelete() throws StopProcessingException {
MetacardImpl metacard1 = new MetacardImpl();
metacard1.setMetadata(TEST_METADATA_3);
PolicyResponse policyResponse = plugin.processPreDelete(Arrays.asList(metacard, metacard1), new HashMap<>());
org.junit.Assert.assertThat(policyResponse.operationPolicy().entrySet().size(), Matchers.is(3));
}
use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.
the class XmlAttributeSecurityPolicyPluginTest method testProcessQuery.
@Test
public void testProcessQuery() throws StopProcessingException, PluginExecutionException {
Result mockResult = mock(Result.class);
when(mockResult.getMetacard()).thenReturn(metacard);
PolicyResponse policyResponse = plugin.processPostQuery(mockResult, new HashMap<>());
org.junit.Assert.assertThat(policyResponse.itemPolicy().entrySet().size(), Matchers.is(3));
}
use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.
the class RegistryPolicyPluginTest method testSecurityValueSet.
@Test
public void testSecurityValueSet() throws Exception {
RegistryPolicyPlugin rpp = createRegistryPlugin();
Map<String, Set<String>> expectedPolicy = new HashMap<>();
Set<String> firstSet = new HashSet<>();
Set<String> secondSet = new HashSet<>();
firstSet.add("Charles");
firstSet.add("Haller");
secondSet.add("Nikolaevna");
secondSet.add("Alexandria");
secondSet.add("Rasputin");
expectedPolicy.put("David", firstSet);
expectedPolicy.put("Illyana", secondSet);
Metacard mcard = new MetacardImpl();
mcard.setAttribute(new AttributeImpl(Metacard.TAGS, RegistryConstants.REGISTRY_TAG));
mcard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID, "validId"));
mcard.setAttribute(new AttributeImpl(Metacard.ID, "1234567890abcdefg987654321"));
List<Serializable> securityValues = new ArrayList<>();
securityValues.add("David=Charles,Haller");
securityValues.add("Illyana=Nikolaevna, Alexandria, Rasputin");
mcard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.SECURITY_LEVEL, securityValues));
PolicyResponse response = rpp.processPreCreate(mcard, null);
assertThat(response.operationPolicy().size(), is(0));
assertThat(response.itemPolicy().size(), is(2));
assertThat(response.itemPolicy(), equalTo(expectedPolicy));
}
use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.
the class RegistryPolicyPluginTest method testCudRegistryOperations.
@Test
public void testCudRegistryOperations() throws Exception {
RegistryPolicyPlugin rpp = createRegistryPlugin();
rpp.setRegistryBypassPolicyStrings(Collections.singletonList("role=system-admin"));
rpp.setCreateAccessPolicyStrings(Collections.singletonList("role=guest"));
rpp.setUpdateAccessPolicyStrings(Collections.singletonList("role=guest"));
rpp.setDeleteAccessPolicyStrings(Collections.singletonList("role=guest"));
Metacard mcard = new MetacardImpl();
mcard.setAttribute(new AttributeImpl(Metacard.TAGS, RegistryConstants.REGISTRY_TAG));
mcard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID, "validId"));
mcard.setAttribute(new AttributeImpl(Metacard.ID, "1234567890abcdefg987654321"));
PolicyResponse response = rpp.processPreCreate(mcard, null);
assertThat(response.operationPolicy(), equalTo(rpp.getCreateAccessPolicy()));
response = rpp.processPreUpdate(mcard, null);
assertThat(response.operationPolicy(), equalTo(rpp.getUpdateAccessPolicy()));
response = rpp.processPreDelete(Collections.singletonList(mcard), null);
assertThat(response.operationPolicy(), equalTo(rpp.getDeleteAccessPolicy()));
}
Aggregations