/** * Returns the permissions that a caller has on this project. You typically don't call this method * if you're using Google Cloud Platform directly to manage permissions. This method is intended * for integration with your proprietary software, such as a customized graphical user interface. * For example, the Cloud Platform Console tests IAM permissions internally to determine which UI * should be available to the logged-in user. Each service that supports IAM lists the possible * permissions; see the <i>Supported Cloud Platform services</i> page below for links to these * lists. * * @return a list of booleans representing whether the caller has the permissions specified (in * the order of the given permissions) * @throws ResourceManagerException upon failure * @see <a href= * "https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/testIamPermissions"> * Resource Manager testIamPermissions</a> * @see <a href= "https://cloud.google.com/iam/#supported_cloud_platform_services">Supported Cloud * Platform Services</a> */ List<Boolean> testPermissions(List<String> permissions) { return resourceManager.testPermissions(getProjectId(), permissions); }
@Test public void testTestPermissions() { List<Boolean> response = ImmutableList.of(true, true); String getPermission = "resourcemanager.projects.get"; String deletePermission = "resourcemanager.projects.delete"; expect(resourceManager.getOptions()).andReturn(mockOptions).times(1); expect( resourceManager.testPermissions( PROJECT_ID, ImmutableList.of(getPermission, deletePermission))) .andReturn(response); replay(resourceManager); initializeProject(); assertEquals( response, project.testPermissions(ImmutableList.of(getPermission, deletePermission))); }
@Test public void testTestPermissions() { List<String> permissions = ImmutableList.of("resourcemanager.projects.get"); try { RESOURCE_MANAGER.testPermissions("nonexistent-project", permissions); fail("Nonexistent project"); } catch (ResourceManagerException e) { assertEquals(403, e.getCode()); assertEquals("Project nonexistent-project not found.", e.getMessage()); } RESOURCE_MANAGER.create(PARTIAL_PROJECT); assertEquals( ImmutableList.of(true), RESOURCE_MANAGER.testPermissions(PARTIAL_PROJECT.getProjectId(), permissions)); }
/** * Returns the permissions that a caller has on this project. You typically don't call this method * if you're using Google Cloud Platform directly to manage permissions. This method is intended * for integration with your proprietary software, such as a customized graphical user interface. * For example, the Cloud Platform Console tests IAM permissions internally to determine which UI * should be available to the logged-in user. Each service that supports IAM lists the possible * permissions; see the <i>Supported Cloud Platform services</i> page below for links to these * lists. * * @return a list of booleans representing whether the caller has the permissions specified (in * the order of the given permissions) * @throws ResourceManagerException upon failure * @see <a href= * "https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/testIamPermissions"> * Resource Manager testIamPermissions</a> * @see <a href= * "https://cloud.google.com/iam/#supported_cloud_platform_services">Supported Cloud Platform * Services</a> */ List<Boolean> testPermissions(List<String> permissions) { return resourceManager.testPermissions(projectId(), permissions); }