SamPermissionsImpl implements PermissionsInterface { @Override public List<Permission> getPermissionsForWorkflow(User user, Workflow workflow) { final List<Permission> dockstoreOwners = PermissionsInterface.getOriginalOwnersForWorkflow(workflow); ResourcesApi resourcesApi = getResourcesApi(user); try { String encoded = encodedWorkflowResource(workflow, resourcesApi.getApiClient()); final List<Permission> samPermissions = accessPolicyResponseEntryToUserPermissions( resourcesApi.listResourcePolicies(SamConstants.RESOURCE_TYPE, encoded)); return PermissionsInterface.mergePermissions(dockstoreOwners, removeDuplicateEmails(samPermissions)); } catch (ApiException e) { final String errorGettingPermissions = "Error getting permissions"; if (e.getCode() != HttpStatus.SC_NOT_FOUND) { throw new CustomWebApplicationException(errorGettingPermissions, e.getCode()); } } return dockstoreOwners; } SamPermissionsImpl(TokenDAO tokenDAO, DockstoreWebserviceConfiguration config); @Override List<Permission> setPermission(User requester, Workflow workflow, Permission permission); @Override Map<Role, List<String>> workflowsSharedWithUser(User user); @Override List<Permission> getPermissionsForWorkflow(User user, Workflow workflow); @Override List<Role.Action> getActionsForWorkflow(User user, Workflow workflow); @Override void removePermission(User user, Workflow workflow, String email, Role role); @Override boolean canDoAction(User user, Workflow workflow, Role.Action action); @Override void selfDestruct(User user); @Override boolean isSharing(User user);  }
@Test public void testNoPermissions() throws ApiException { final String resourceId = SamConstants.WORKFLOW_PREFIX + FOO_WORKFLOW_NAME; when(resourcesApiMock.listResourcePolicies(SamConstants.RESOURCE_TYPE, resourceId)) .thenThrow(new ApiException(HttpStatus.SC_FORBIDDEN, "Unauthorized")); when(resourcesApiMock.resourceAction(SamConstants.RESOURCE_TYPE, resourceId, SamConstants.toSamAction(Role.Action.READ))) .thenReturn(Boolean.FALSE); when(resourcesApiMock.resourceAction(SamConstants.RESOURCE_TYPE, resourceId, SamConstants.toSamAction(Role.Action.WRITE))) .thenReturn(Boolean.FALSE); thrown.expect(CustomWebApplicationException.class); samPermissionsImpl.getPermissionsForWorkflow(userMock, workflowInstance); }