use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Policy in project java-functions by googleapis.
the class CloudFunctionsServiceClientTest method getIamPolicyTest.
@Test
public void getIamPolicyTest() throws Exception {
Policy expectedResponse = Policy.newBuilder().setVersion(351608024).addAllBindings(new ArrayList<Binding>()).setEtag(ByteString.EMPTY).build();
mockCloudFunctionsService.addResponse(expectedResponse);
GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(CloudFunctionName.of("[PROJECT]", "[LOCATION]", "[FUNCTION]").toString()).setOptions(GetPolicyOptions.newBuilder().build()).build();
Policy actualResponse = client.getIamPolicy(request);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockCloudFunctionsService.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetIamPolicyRequest actualRequest = ((GetIamPolicyRequest) actualRequests.get(0));
Assert.assertEquals(request.getResource(), actualRequest.getResource());
Assert.assertEquals(request.getOptions(), actualRequest.getOptions());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Policy in project java-storage by googleapis.
the class StorageClientTest method getIamPolicyTest2.
@Test
public void getIamPolicyTest2() throws Exception {
Policy expectedResponse = Policy.newBuilder().setVersion(351608024).addAllBindings(new ArrayList<Binding>()).setEtag(ByteString.EMPTY).build();
mockStorage.addResponse(expectedResponse);
String resource = "resource-341064690";
Policy actualResponse = client.getIamPolicy(resource);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockStorage.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetIamPolicyRequest actualRequest = ((GetIamPolicyRequest) actualRequests.get(0));
Assert.assertEquals(resource, actualRequest.getResource());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Policy in project java-storage by googleapis.
the class StorageClientTest method setIamPolicyExceptionTest2.
@Test
public void setIamPolicyExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockStorage.addException(exception);
try {
String resource = "resource-341064690";
Policy policy = Policy.newBuilder().build();
client.setIamPolicy(resource, policy);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Policy in project java-storage by googleapis.
the class StorageClientTest method setIamPolicyTest.
@Test
public void setIamPolicyTest() throws Exception {
Policy expectedResponse = Policy.newBuilder().setVersion(351608024).addAllBindings(new ArrayList<Binding>()).setEtag(ByteString.EMPTY).build();
mockStorage.addResponse(expectedResponse);
ResourceName resource = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
Policy policy = Policy.newBuilder().build();
Policy actualResponse = client.setIamPolicy(resource, policy);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockStorage.getRequests();
Assert.assertEquals(1, actualRequests.size());
SetIamPolicyRequest actualRequest = ((SetIamPolicyRequest) actualRequests.get(0));
Assert.assertEquals(resource.toString(), actualRequest.getResource());
Assert.assertEquals(policy, actualRequest.getPolicy());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Policy in project core by authzforce.
the class XacmlXmlPdpTest method test.
@Test
public void test() throws IllegalArgumentException, IOException, JAXBException {
LOGGER.debug("******************************");
LOGGER.debug("Starting PDP test of directory '{}'", testDirPath);
final String testResourceLocationPrefix = testDirPath + "/";
// Parse request
final Request request;
// if no Request file, it is just a static policy syntax error check
final Path reqFilepath = Paths.get(testResourceLocationPrefix + REQUEST_FILENAME);
final XmlnsFilteringParser unmarshaller = XACML_PARSER_FACTORY.getInstance();
if (Files.exists(reqFilepath)) {
request = TestUtils.createRequest(reqFilepath, unmarshaller);
LOGGER.debug("XACML Request sent to the PDP: {}", request);
} else {
request = null;
// do nothing except logging -> request = null
LOGGER.debug("Request file '{}' does not exist -> Static policy syntax error check (Request/Response ignored)", reqFilepath);
}
/*
* Policies
*
* If there is a "$TEST_DIR/$POLICIES_DIR_NAME" directory, then load all policies from there, including root policy from "$TEST_DIR/$POLICIES_DIR_NAME/$ROOT_POLICY_FILENAME" Else load only the
* root policy from "$TEST_DIR/$ROOT_POLICY_FILENAME"
*/
final Path policiesDir = Paths.get(testResourceLocationPrefix + POLICIES_DIR_NAME);
final Optional<Path> optPoliciesDir;
final Path rootPolicyFile;
if (Files.isDirectory(policiesDir)) {
optPoliciesDir = Optional.of(policiesDir);
rootPolicyFile = policiesDir.resolve(ROOT_POLICY_FILENAME);
} else {
optPoliciesDir = Optional.empty();
rootPolicyFile = Paths.get(testResourceLocationPrefix + ROOT_POLICY_FILENAME);
}
/*
* Create PDP
*/
PdpEngineInoutAdapter<Request, Response> pdp = null;
final Path pdpConfFile = Paths.get(testResourceLocationPrefix + PDP_CONF_FILENAME);
try {
final PdpEngineConfiguration pdpEngineConf;
if (Files.notExists(pdpConfFile)) {
LOGGER.debug("No PDP configuration file found at location: '{}'. Using minimal PDP instead (returned by TestUtils.getPDPNewInstance(policy) ).", pdpConfFile);
pdpEngineConf = optPoliciesDir.isPresent() ? TestUtils.newPdpEngineConfiguration(TestUtils.getPolicyRef(rootPolicyFile), optPoliciesDir.get(), false, Optional.empty(), null, null) : TestUtils.newPdpEngineConfiguration(rootPolicyFile, false, Optional.empty(), null, null);
} else {
/*
* PDP configuration filename found in test directory -> create PDP from it
*/
// final String pdpExtXsdLocation = testResourceLocationPrefix + PDP_EXTENSION_XSD_FILENAME;
File pdpExtXsdFile = null;
try {
pdpExtXsdFile = ResourceUtils.getFile(PDP_EXTENSION_XSD_LOCATION);
} catch (final FileNotFoundException e) {
LOGGER.debug("No PDP extension configuration file '{}' found -> JAXB-bound PDP extensions not allowed.", PDP_EXTENSION_XSD_LOCATION);
}
try {
/*
* Load the PDP configuration from the configuration, and optionally, the PDP extension XSD if this file exists, and the XML catalog required to resolve these extension XSDs
*/
pdpEngineConf = pdpExtXsdFile == null ? PdpEngineConfiguration.getInstance(pdpConfFile.toString()) : PdpEngineConfiguration.getInstance(pdpConfFile.toString(), XML_CATALOG_LOCATION, PDP_EXTENSION_XSD_LOCATION);
} catch (final IOException e) {
throw new RuntimeException("Error parsing PDP configuration from file '" + pdpConfFile + "' with extension XSD '" + PDP_EXTENSION_XSD_LOCATION + "' and XML catalog file '" + XML_CATALOG_LOCATION + "'", e);
}
}
pdp = PdpEngineAdapters.newXacmlJaxbInoutAdapter(pdpEngineConf);
if (request == null) {
/*
* This is a policy syntax error check, and we didn't find the syntax error as expected
*/
Assert.fail("Failed to find syntax error as expected in policy(ies) located in directory: " + testDirPath);
} else {
// Parse expected response
final Response expectedResponse = TestUtils.createResponse(Paths.get(testResourceLocationPrefix + EXPECTED_RESPONSE_FILENAME), unmarshaller);
final Response response = pdp.evaluate(request, null);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("XACML Response received from the PDP: {}", TestUtils.printResponse(response));
}
TestUtils.assertNormalizedEquals(testResourceLocationPrefix, expectedResponse, response);
LOGGER.debug("Finished PDP test of directory '{}'", testDirPath);
}
} catch (final IllegalArgumentException e) {
// we found syntax error in policy
if (request == null) {
// this is a policy syntax error check, and we found the syntax error as
// expected -> success
LOGGER.debug("Successfully found syntax error as expected in policy(ies) located in directory: {}", testDirPath, e);
} else {
throw e;
}
} finally {
if (pdp != null) {
pdp.close();
}
}
}
Aggregations