ALF-9156 Calendar listing permissions check unit tests

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29025 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2011-07-14 11:52:52 +00:00
parent d60b7631af
commit e22d74350d
2 changed files with 59 additions and 29 deletions

View File

@@ -120,6 +120,24 @@ public class CalendarServiceImpl implements CalendarService
*/ */
protected NodeRef getSiteCalendarContainer(final String siteShortName, boolean create) protected NodeRef getSiteCalendarContainer(final String siteShortName, boolean create)
{ {
// Does the site exist?
if(siteService.getSite(siteShortName) == null) {
// Either the site doesn't exist, or you're not allowed to see it
if(! create)
{
// Just say there's no container
return null;
}
else
{
// We can't create on a non-existant site
throw new AlfrescoRuntimeException(
"Unable to create the calendar container from a hidden or non-existant site"
);
}
}
// Check about the container
if(! siteService.hasContainer(siteShortName, CALENDAR_COMPONENT)) if(! siteService.hasContainer(siteShortName, CALENDAR_COMPONENT))
{ {
if(create) if(create)
@@ -405,12 +423,6 @@ public class CalendarServiceImpl implements CalendarService
List<NodeRef> containersL = new ArrayList<NodeRef>(); List<NodeRef> containersL = new ArrayList<NodeRef>();
for(String siteShortName : siteShortNames) for(String siteShortName : siteShortNames)
{ {
// Ensure the site exists, skip if not
if(siteService.getSite(siteShortName) == null)
{
continue;
}
// Grab the container for this site // Grab the container for this site
NodeRef container = getSiteCalendarContainer(siteShortName, false); NodeRef container = getSiteCalendarContainer(siteShortName, false);
if(container != null) if(container != null)

View File

@@ -42,7 +42,6 @@ import org.alfresco.service.cmr.calendar.CalendarService;
import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
@@ -493,35 +492,26 @@ public class CalendarServiceImplTest
/** /**
* Checks that the correct permission checking occurs on fetching * Checks that the correct permission checking occurs on fetching
* calendar listings (which go through canned queries) * calendar listings (which go through canned queries)
* TODO FIX
*/ */
public void DISABLEDcalendarListingPermissionsChecking() throws Exception @Test public void calendarListingPermissionsChecking() throws Exception
{ {
PagingRequest paging = new PagingRequest(10); PagingRequest paging = new PagingRequest(10);
PagingResults<CalendarEntry> results; PagingResults<CalendarEntry> results;
// TODO This shouldn't be needed...
PERMISSION_SERVICE.clearPermission(ALTERNATE_CALENDAR_SITE.getNodeRef(), TEST_USER);
System.err.println(PERMISSION_SERVICE.getPermissions(ALTERNATE_CALENDAR_SITE.getNodeRef()));
System.err.println(PERMISSION_SERVICE.getAllSetPermissions(ALTERNATE_CALENDAR_SITE.getNodeRef()));
System.err.println(NODE_SERVICE.getChildAssocs(ALTERNATE_CALENDAR_SITE.getNodeRef()));
System.err.println(PUBLIC_NODE_SERVICE.getChildAssocs(ALTERNATE_CALENDAR_SITE.getNodeRef()));
// Nothing to start with in either site // Nothing to start with in either site
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging); results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
// assertEquals(0, results.getPage().size()); assertEquals(0, results.getPage().size());
results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging); results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging);
assertEquals(0, results.getPage().size()); assertEquals(0, results.getPage().size());
// Double check that we're only allowed to see the 1st site // Double check that we're only allowed to see the 1st site
assertEquals(true, SITE_SERVICE.isMember(CALENDAR_SITE.getShortName(), TEST_USER)); assertEquals(true, SITE_SERVICE.isMember(CALENDAR_SITE.getShortName(), TEST_USER));
assertEquals(false, SITE_SERVICE.isMember(ALTERNATE_CALENDAR_SITE.getShortName(), TEST_USER)); assertEquals(false, SITE_SERVICE.isMember(ALTERNATE_CALENDAR_SITE.getShortName(), TEST_USER));
assertEquals(AccessStatus.ALLOWED, PERMISSION_SERVICE.hasReadPermission(CALENDAR_SITE.getNodeRef()));
assertEquals(AccessStatus.DENIED, PERMISSION_SERVICE.hasReadPermission(ALTERNATE_CALENDAR_SITE.getNodeRef()));
// Add two events to one site and three to the other // Add two events to one site and three to the other
// Note - add the events as a different user for the site that the
// test user isn't a member of!
CALENDAR_SERVICE.createCalendarEntry(CALENDAR_SITE.getShortName(), new CalendarEntryDTO( CALENDAR_SERVICE.createCalendarEntry(CALENDAR_SITE.getShortName(), new CalendarEntryDTO(
"TitleA", "Description", "Location", new Date(1302431400), new Date(1302435000) "TitleA", "Description", "Location", new Date(1302431400), new Date(1302435000)
)); ));
@@ -529,6 +519,7 @@ public class CalendarServiceImplTest
"TitleB", "Description", "Location", new Date(1302431400), new Date(1302442200) "TitleB", "Description", "Location", new Date(1302431400), new Date(1302442200)
)); ));
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
CALENDAR_SERVICE.createCalendarEntry(ALTERNATE_CALENDAR_SITE.getShortName(), new CalendarEntryDTO( CALENDAR_SERVICE.createCalendarEntry(ALTERNATE_CALENDAR_SITE.getShortName(), new CalendarEntryDTO(
"PrivateTitleA", "Description", "Location", new Date(1302431400), new Date(1302435000) "PrivateTitleA", "Description", "Location", new Date(1302431400), new Date(1302435000)
)); ));
@@ -538,17 +529,28 @@ public class CalendarServiceImplTest
NodeRef priv3 = CALENDAR_SERVICE.createCalendarEntry(ALTERNATE_CALENDAR_SITE.getShortName(), new CalendarEntryDTO( NodeRef priv3 = CALENDAR_SERVICE.createCalendarEntry(ALTERNATE_CALENDAR_SITE.getShortName(), new CalendarEntryDTO(
"PrivateTitleC", "Description", "Location", new Date(1302431400), new Date(1302442200) "PrivateTitleC", "Description", "Location", new Date(1302431400), new Date(1302442200)
)).getNodeRef(); )).getNodeRef();
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
// Check again, as we're not in the 2nd site won't see any there // Check again, as we're not in the 2nd site won't see any there
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging); results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size()); assertEquals(2, results.getPage().size());
results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging); results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging);
assertEquals(0, results.getPage().size()); assertEquals(null, results); // TODO is this the right answer?
// Join the site, now we can see both // Join the site, now we can see both
SITE_SERVICE.setMembership(ALTERNATE_CALENDAR_SITE.getShortName(), TEST_USER, SiteModel.SITE_CONTRIBUTOR); TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
SITE_SERVICE.setMembership(ALTERNATE_CALENDAR_SITE.getShortName(), TEST_USER, SiteModel.SITE_COLLABORATOR);
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
return null;
}
});
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging); results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size()); assertEquals(2, results.getPage().size());
@@ -567,27 +569,43 @@ public class CalendarServiceImplTest
// Leave, they go away again // Leave, they go away again
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
SITE_SERVICE.removeMembership(ALTERNATE_CALENDAR_SITE.getShortName(), TEST_USER); SITE_SERVICE.removeMembership(ALTERNATE_CALENDAR_SITE.getShortName(), TEST_USER);
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
return null;
}
});
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging); results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size()); assertEquals(2, results.getPage().size());
results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging); results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging);
assertEquals(0, results.getPage().size()); assertEquals(null, results);
// Tidy // Tidy
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
paging = new PagingRequest(10); paging = new PagingRequest(10);
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging); results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
for(CalendarEntry entry : results.getPage()) for(CalendarEntry entry : results.getPage())
{ {
testNodesToTidy.add(entry.getNodeRef()); testNodesToTidy.add(entry.getNodeRef());
} }
results = CALENDAR_SERVICE.listCalendarEntries(ALTERNATE_CALENDAR_SITE.getShortName(), paging);
for(CalendarEntry entry : results.getPage())
{
testNodesToTidy.add(entry.getNodeRef());
}
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
} }
/** /**
* Test that we can retrieve (with date filtering) events from * Test that we can retrieve (with date filtering) events from
* multiple sites * multiple sites
* TODO Fix permission tests
*/ */
@Test public void calendarMultiSiteListing() throws Exception @Test public void calendarMultiSiteListing() throws Exception
{ {
@@ -631,25 +649,25 @@ public class CalendarServiceImplTest
assertEquals(3, results.getPage().size()); assertEquals(3, results.getPage().size());
// Should be date ordered, from then too // Should be date ordered, from then too
CalendarEntry a = results.getPage().get(0);
assertEquals("TitleA", results.getPage().get(0).getTitle()); assertEquals("TitleA", results.getPage().get(0).getTitle());
assertEquals("TitleC", results.getPage().get(1).getTitle()); assertEquals("TitleC", results.getPage().get(1).getTitle());
assertEquals("TitleB", results.getPage().get(2).getTitle()); assertEquals("TitleB", results.getPage().get(2).getTitle());
// Add some to the other site // Add some to the other site, which the user isn't a member of
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
CALENDAR_SERVICE.createCalendarEntry(ALTERNATE_CALENDAR_SITE.getShortName(), new CalendarEntryDTO( CALENDAR_SERVICE.createCalendarEntry(ALTERNATE_CALENDAR_SITE.getShortName(), new CalendarEntryDTO(
"PrivateTitleA", "Description", "Location", new Date(1302131400), new Date(1302135000) "PrivateTitleA", "Description", "Location", new Date(1302131400), new Date(1302135000)
)); ));
CALENDAR_SERVICE.createCalendarEntry(ALTERNATE_CALENDAR_SITE.getShortName(), new CalendarEntryDTO( CALENDAR_SERVICE.createCalendarEntry(ALTERNATE_CALENDAR_SITE.getShortName(), new CalendarEntryDTO(
"PrivateTitleB", "Description", "Location", new Date(1302731400), new Date(1302472200) "PrivateTitleB", "Description", "Location", new Date(1302731400), new Date(1302472200)
)); ));
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
// Check, they won't show up due to permissions // Check, they won't show up due to permissions
results = CALENDAR_SERVICE.listCalendarEntries(new String[] { results = CALENDAR_SERVICE.listCalendarEntries(new String[] {
CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()}, paging); CALENDAR_SITE.getShortName(), ALTERNATE_CALENDAR_SITE.getShortName()}, paging);
// TODO FIX the permissions! assertEquals(3, results.getPage().size());
//assertEquals(3, results.getPage().size());
// Make a member of the site, they should now show up // Make a member of the site, they should now show up