01/01: Add voterList import test + fix security check on voter list service
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See http://git.chorem.org/pollen.git commit 40ff0e8d8d49f644f164d1a1ddcdb597deeb41e1 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Jun 6 09:18:02 2014 +0200 Add voterList import test + fix security check on voter list service --- .../pollen/services/service/VoterListService.java | 38 ++++++- .../services/service/VoterListServiceTest.java | 125 +++++++++++++++++++++ 2 files changed, 159 insertions(+), 4 deletions(-) diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java index 6b0fa84..99af926 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java @@ -36,6 +36,7 @@ import org.chorem.pollen.persistence.entity.VoterListTopiaDao; import org.chorem.pollen.services.bean.PollenEntityRef; import org.chorem.pollen.services.bean.VoterListBean; import org.chorem.pollen.services.bean.VoterListMemberBean; +import org.chorem.pollen.services.service.security.PermissionVerb; import java.util.ArrayList; import java.util.List; @@ -49,12 +50,30 @@ import java.util.Set; */ public class VoterListService extends PollenServiceSupport { - public VoterListBean importFavoriteList(String pollId, - String favoriteListId) { + public VoterListBean newRestrictedVoterList() { + + VoterListBean list = new VoterListBean(); + list.setName("restrictedVoterList"); + list.setWeight(1.0f); + return list; + + } + + public VoterListBean newGroupVoterList() { + + VoterListBean list = new VoterListBean(); + list.setWeight(1.0f); + return list; + + } + + public PollenEntityRef<VoterList> importFavoriteList(String pollId, + String favoriteListId) { checkIsConnected(); checkNotNull(pollId); checkNotNull(favoriteListId); + checkPermission(PermissionVerb.editPoll, pollId); Poll poll = getPollService().getPoll0(pollId); @@ -86,13 +105,15 @@ public class VoterListService extends PollenServiceSupport { commit(); - return toBean(VoterListBean.class, result); + PollenEntityRef<VoterList> createBeanRef = PollenEntityRef.of(result); + return createBeanRef; } public List<VoterListBean> getVoterLists(String pollId) { checkNotNull(pollId); + checkPermission(PermissionVerb.readPoll, pollId); Poll poll = getPollService().getPoll0(pollId); List<VoterList> voterLists = getVoterLists0(poll); @@ -105,6 +126,7 @@ public class VoterListService extends PollenServiceSupport { checkNotNull(pollId); checkNotNull(voterListId); + checkPermission(PermissionVerb.readPoll, pollId); VoterList voterList = getVoterList0(pollId, voterListId); VoterListBean voterListBean = toBean(VoterListBean.class, voterList); @@ -119,6 +141,7 @@ public class VoterListService extends PollenServiceSupport { checkNotNull(pollId); checkNotNull(voterList); checkIsNotPersisted(voterList); + checkPermission(PermissionVerb.editPoll, pollId); Poll poll = getPollService().getPoll0(pollId); @@ -153,6 +176,7 @@ public class VoterListService extends PollenServiceSupport { checkNotNull(pollId); checkNotNull(voterList); checkIsPersisted(voterList); + checkPermission(PermissionVerb.editPoll, pollId); Poll poll = getPollService().getPoll0(pollId); @@ -174,6 +198,7 @@ public class VoterListService extends PollenServiceSupport { checkNotNull(pollId); checkNotNull(voterListId); + checkPermission(PermissionVerb.editPoll, pollId); Poll poll = getPollService().getPoll0(pollId); @@ -187,6 +212,7 @@ public class VoterListService extends PollenServiceSupport { checkNotNull(pollId); checkNotNull(voterListId); + checkPermission(PermissionVerb.readPoll, pollId); VoterList voterList = getVoterList0(pollId, voterListId); @@ -201,6 +227,7 @@ public class VoterListService extends PollenServiceSupport { checkNotNull(pollId); checkNotNull(voterListId); checkNotNull(memberId); + checkPermission(PermissionVerb.readPoll, pollId); VoterList voterList = getVoterList0(pollId, voterListId); @@ -216,6 +243,7 @@ public class VoterListService extends PollenServiceSupport { checkNotNull(voterListId); checkNotNull(member); checkIsNotPersisted(member); + checkPermission(PermissionVerb.editPoll, pollId); VoterList voterList = getVoterList0(pollId, voterListId); @@ -238,6 +266,7 @@ public class VoterListService extends PollenServiceSupport { checkNotNull(voterListId); checkNotNull(member); checkIsPersisted(member); + checkPermission(PermissionVerb.editPoll, pollId); VoterList voterList = getVoterList0(pollId, voterListId); @@ -260,7 +289,8 @@ public class VoterListService extends PollenServiceSupport { checkNotNull(pollId); checkNotNull(voterListId); checkNotNull(memberId); - + checkPermission(PermissionVerb.editPoll, pollId); + VoterList voterList = getVoterList0(pollId, voterListId); VoterListMember member = getVoterListMember0(voterList, memberId); diff --git a/pollen-services/src/test/java/org/chorem/pollen/services/service/VoterListServiceTest.java b/pollen-services/src/test/java/org/chorem/pollen/services/service/VoterListServiceTest.java new file mode 100644 index 0000000..23c3976 --- /dev/null +++ b/pollen-services/src/test/java/org/chorem/pollen/services/service/VoterListServiceTest.java @@ -0,0 +1,125 @@ +package org.chorem.pollen.services.service; + +import com.google.common.base.Charsets; +import com.google.common.io.Files; +import org.chorem.pollen.persistence.entity.ChoiceType; +import org.chorem.pollen.persistence.entity.FavoriteList; +import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.persistence.entity.PollType; +import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.persistence.entity.VoterList; +import org.chorem.pollen.services.AbstractPollenServiceTest; +import org.chorem.pollen.services.bean.ChoiceBean; +import org.chorem.pollen.services.bean.FavoriteListBean; +import org.chorem.pollen.services.bean.PollBean; +import org.chorem.pollen.services.bean.PollenEntityRef; +import org.chorem.pollen.services.bean.VoterListMemberBean; +import org.chorem.pollen.services.service.security.PollenAuthenticationException; +import org.chorem.pollen.services.service.security.PollenInvalidSessionTokenException; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Set; + +/** + * Created on 6/6/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class VoterListServiceTest extends AbstractPollenServiceTest { + + protected PollenUserService userService; + + protected PollService pollService; + + protected FavoriteListService favoriteListService; + + protected VoterListService voterListService; + + protected VoterListService service; + + protected PollenUser user; + + @Before + public void setUp() throws ParseException { + + loadFixtures("fixtures"); + + userService = newService(PollenUserService.class); + pollService = newService(PollService.class); + favoriteListService = newService(FavoriteListService.class); + voterListService = newService(VoterListService.class); + service = newService(VoterListService.class); + + getServiceContext().setDate(new Date(1363948427576l)); + + user = application.fixture("user_jean"); + } + + @Test + public void importFavoriteList() throws FavoriteListImportException, InvalidFormException, IOException, PollenInvalidSessionTokenException, PollenAuthenticationException { + + login("jean@pollen.fake", "fake"); + + // create favorite list + + FavoriteListBean favoriteListBean1 = new FavoriteListBean(); + + favoriteListBean1.setName("list1"); + PollenEntityRef<FavoriteList> savedList1 = favoriteListService.createFavoriteList(favoriteListBean1); + Assert.assertNotNull(savedList1); + String favoriteListId = savedList1.getEntityId(); + Assert.assertNotNull(favoriteListId); + + // create import file + + File importFile = new File(application.getTestBasedir(), "importFavoriteListFromFile_" + System.nanoTime()); + Files.write(FavoriteListServiceTest.IMPORT_FILE_CONTENT, importFile, Charsets.UTF_8); + + // import file + + favoriteListService.importFavoriteListMembersFromCsv(favoriteListId, importFile); + + // create poll and voter list + + PollBean poll = pollService.getNewPoll(); + + poll.setPollType(PollType.RESTRICTED); + poll.setTitle("poll1"); + + List<ChoiceBean> choices = new ArrayList<>(); + + ChoiceBean choice1 = new ChoiceBean(); + choices.add(choice1); + choice1.setChoiceType(ChoiceType.TEXT); + choice1.setName("A"); + choice1.setDescription("Choice A"); + + ChoiceBean choice2 = new ChoiceBean(); + choice2.setChoiceType(ChoiceType.TEXT); + choice2.setName("B"); + choice2.setDescription("Choice B"); + choices.add(choice2); + + PollenEntityRef<Poll> createdPoll = pollService.createPoll(poll, choices); + Assert.assertNotNull(createdPoll); + + String pollId = createdPoll.getEntityId(); + + PollenEntityRef<VoterList> createdVoterList = voterListService.importFavoriteList(pollId, favoriteListId); + Assert.assertNotNull(createdVoterList); + + Set<VoterListMemberBean> voterListMembers = voterListService.getVoterListMembers(pollId, createdVoterList.getEntityId()); + Assert.assertNotNull(voterListMembers); + Assert.assertEquals(2, voterListMembers.size()); + + } +} -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm