SamPermissionsImpl implements PermissionsInterface { void checkEmailNotOriginalOwner(String email, Workflow workflow) { assert email != null; final boolean isOwner = workflow.getUsers().stream().anyMatch(u -> { if (email.equals(u.getUsername())) { return true; } final User.Profile profile = u.getUserProfiles().get(TokenType.GOOGLE_COM.toString()); return profile != null && email.equals(profile.email); }); if (isOwner) { throw new CustomWebApplicationException(email + " is an original owner and their permissions cannot be modified", HttpStatus.SC_FORBIDDEN); } } 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 testNotOriginalOwnerWithEmailNotUsername() { when(userMock.getUsername()).thenReturn(JANE_DOE_GITHUB_ID); when(workflowInstance.getUsers()).thenReturn(new HashSet<>(Collections.singletonList(userMock))); thrown.expect(CustomWebApplicationException.class); samPermissionsImpl.checkEmailNotOriginalOwner(JANE_DOE_GMAIL_COM, workflowInstance); samPermissionsImpl.checkEmailNotOriginalOwner("johndoe@example.com", workflowInstance); }