Skip to content

Commit

Permalink
Fix thumbnail IT tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lfarrell committed Nov 29, 2023
1 parent ed497b4 commit 87ac2fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package edu.unc.lib.boxc.web.services.rest;

import static edu.unc.lib.boxc.auth.api.Permission.viewAccessCopies;
import static edu.unc.lib.boxc.auth.api.Permission.viewHidden;
import static edu.unc.lib.boxc.auth.api.Permission.viewMetadata;
import static edu.unc.lib.boxc.model.api.DatastreamType.MD_EVENTS;
import static edu.unc.lib.boxc.model.api.DatastreamType.TECHNICAL_METADATA;
import static edu.unc.lib.boxc.model.api.DatastreamType.THUMBNAIL_SMALL;
Expand All @@ -17,6 +17,7 @@
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand All @@ -26,7 +27,10 @@
import java.nio.file.Path;
import java.nio.file.Paths;

import edu.unc.lib.boxc.auth.api.models.AccessGroupSet;
import edu.unc.lib.boxc.indexing.solr.test.TestCorpus;
import edu.unc.lib.boxc.search.api.models.ContentObjectRecord;
import edu.unc.lib.boxc.web.common.services.PermissionsHelper;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.jena.rdf.model.Model;
Expand All @@ -36,6 +40,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
Expand Down Expand Up @@ -87,6 +92,9 @@ public class DatastreamRestControllerIT extends AbstractAPIIT {
@Autowired
private EmbeddedSolrServer embeddedSolrServer;

@Mock
private PermissionsHelper permissionsHelper;

@TempDir
public Path derivDir;
private String derivDirPath;
Expand Down Expand Up @@ -190,6 +198,9 @@ public void testGetThumbnailForWork() throws Exception {
createDerivative(id, THUMBNAIL_SMALL, BINARY_CONTENT.getBytes());
PID workPid = corpus.pid6;

doReturn(true).when(permissionsHelper)
.hasThumbnailAccess(any(AccessGroupSet.class), any(ContentObjectRecord.class));

MvcResult result = mvc.perform(get("/thumb/" + workPid.getId()))
.andExpect(status().is2xxSuccessful())
.andReturn();
Expand Down Expand Up @@ -225,7 +236,7 @@ public void testGetThumbnailNoPermission() throws Exception {
createDerivative(id, THUMBNAIL_SMALL, BINARY_CONTENT.getBytes());

doThrow(new AccessRestrictionException()).when(accessControlService)
.assertHasAccess(anyString(), eq(filePid), any(AccessGroupSetImpl.class), eq(viewMetadata));
.assertHasAccess(anyString(), eq(filePid), any(AccessGroupSetImpl.class), eq(viewAccessCopies));

MvcResult result = mvc.perform(get("/thumb/" + filePid.getId()))
.andExpect(status().isForbidden())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@

<bean id="accessCopiesService" class="edu.unc.lib.boxc.web.common.services.AccessCopiesService">
<property name="globalPermissionEvaluator" ref="globalPermissionEvaluator" />
<property name="permissionsHelper" ref="permsHelper" />
<property name="solrSearchService" ref="solrSearchService" />
</bean>

<bean id="permsHelper" class="edu.unc.lib.boxc.web.common.services.PermissionsHelper">
<property name="accessControlService" ref="aclService" />
</bean>
</beans>

0 comments on commit 87ac2fc

Please sign in to comment.