Search in sources :

Example 11 with Policy

use of com.google.iam.v1.Policy in project openstack4j by ContainX.

the class KeystonePolicyServiceTest method policy_update_Test.

// ------------ Policy Tests ------------
// The following tests are to verify the update() method of the
// PolicyService using HTTP PATCH, which is not supported by betamax.
// Find more tests in KeystonePolicyServiceSpec in core-integration-test
// module.
public void policy_update_Test() throws Exception {
    respondWith(JSON_POLICIES_GET_BYID);
    Policy policy_setToUpdate = osv3().identity().policies().get(POLICY_ID);
    respondWith(JSON_POLICIES_UPDATE);
    Policy updatedPolicy = osv3().identity().policies().update(policy_setToUpdate.toBuilder().blob(POLICY_BLOB_UPDATE).build());
    assertEquals(updatedPolicy.getId(), POLICY_ID);
    assertEquals(updatedPolicy.getBlob(), POLICY_BLOB_UPDATE);
    assertEquals(updatedPolicy.getProjectId(), POLICY_PROJECT_ID);
    assertEquals(updatedPolicy.getUserId(), POLICY_USER_ID);
    assertEquals(updatedPolicy.getType(), POLICY_TYPE);
}
Also used : Policy(org.openstack4j.model.identity.v3.Policy)

Example 12 with Policy

use of com.google.iam.v1.Policy in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method setIamPolicyExceptionTest.

@Test
@SuppressWarnings("all")
public void setIamPolicyExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockIAMPolicy.addException(exception);
    try {
        String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
        Policy policy = Policy.newBuilder().build();
        client.setIamPolicy(formattedResource, policy);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : Policy(com.google.iam.v1.Policy) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 13 with Policy

use of com.google.iam.v1.Policy in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method setIamPolicyTest.

@Test
@SuppressWarnings("all")
public void setIamPolicyTest() {
    int version = 351608024;
    ByteString etag = ByteString.copyFromUtf8("21");
    Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build();
    mockIAMPolicy.addResponse(expectedResponse);
    String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
    Policy policy = Policy.newBuilder().build();
    Policy actualResponse = client.setIamPolicy(formattedResource, policy);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockIAMPolicy.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SetIamPolicyRequest actualRequest = (SetIamPolicyRequest) actualRequests.get(0);
    Assert.assertEquals(formattedResource, actualRequest.getResource());
    Assert.assertEquals(policy, actualRequest.getPolicy());
}
Also used : Policy(com.google.iam.v1.Policy) SetIamPolicyRequest(com.google.iam.v1.SetIamPolicyRequest) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 14 with Policy

use of com.google.iam.v1.Policy in project google-cloud-java by GoogleCloudPlatform.

the class ITTopicAdminClientSnippets method replaceTopicPolicyAndTestPermissionsIsSuccessful.

@Test
public void replaceTopicPolicyAndTestPermissionsIsSuccessful() throws Exception {
    String topicName = topics[0];
    topicAdminClientSnippets.createTopic(topicName);
    Policy policy = topicAdminClientSnippets.replaceTopicPolicy(topicName);
    assertNotNull(policy.getBindingsCount());
    assertTrue(policy.getBindings(0).getRole().equalsIgnoreCase(Role.viewer().toString()));
    assertTrue(policy.getBindings(0).getMembers(0).equalsIgnoreCase(Identity.allAuthenticatedUsers().toString()));
    TestIamPermissionsResponse response = topicAdminClientSnippets.testTopicPermissions(topicName);
    assertTrue(response.getPermissionsList().contains("pubsub.topics.get"));
}
Also used : Policy(com.google.iam.v1.Policy) TestIamPermissionsResponse(com.google.iam.v1.TestIamPermissionsResponse) Test(org.junit.Test)

Example 15 with Policy

use of com.google.iam.v1.Policy in project google-cloud-java by GoogleCloudPlatform.

the class ITTopicAdminClientSnippets method topicPolicyIsCorrectlyRetrieved.

@Test
public void topicPolicyIsCorrectlyRetrieved() throws Exception {
    String topicName = topics[0];
    topicAdminClientSnippets.createTopic(topicName);
    Policy policy = topicAdminClientSnippets.getTopicPolicy(topicName);
    assertNotNull(policy);
}
Also used : Policy(com.google.iam.v1.Policy) Test(org.junit.Test)

Aggregations

Policy (com.google.iam.v1.Policy)15 Test (org.junit.Test)11 ByteString (com.google.protobuf.ByteString)9 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)4 Binding (com.google.iam.v1.Binding)3 ApiException (com.google.api.gax.grpc.ApiException)2 SubscriptionAdminClient (com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient)2 TopicAdminClient (com.google.cloud.pubsub.spi.v1.TopicAdminClient)2 GetIamPolicyRequest (com.google.iam.v1.GetIamPolicyRequest)2 SetIamPolicyRequest (com.google.iam.v1.SetIamPolicyRequest)2 TestIamPermissionsResponse (com.google.iam.v1.TestIamPermissionsResponse)2 SubscriptionName (com.google.pubsub.v1.SubscriptionName)2 TopicName (com.google.pubsub.v1.TopicName)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 Policy (org.openstack4j.model.identity.v3.Policy)1