Skip to content

Commit

Permalink
updating to main
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharon Luong committed Jan 11, 2024
2 parents 6f70c6f + c63b224 commit 113e759
Show file tree
Hide file tree
Showing 80 changed files with 5,714 additions and 12,024 deletions.
10 changes: 0 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ endif
build-admin-npm:
# Build vue permissions application files
npm --prefix static/js/admin/vue-permissions-editor ci

ifeq ($(DEPLOY_TYPE), prod)
npm --prefix static/js/admin/vue-permissions-editor run build
else
npm --prefix static/js/admin/vue-permissions-editor run build-dev
endif

cp static/js/admin/vue-permissions-editor/dist/assets/vue-permissions-index.js static/js/vue-permissions-index.js

Expand Down Expand Up @@ -87,12 +82,7 @@ SUSPEND = "n"
build-access-npm:
# Build vue application(s) files
npm --prefix static/js/vue-cdr-access ci

ifeq ($(DEPLOY_TYPE), prod)
npm --prefix static/js/vue-cdr-access run build
else
npm --prefix static/js/vue-cdr-access run build-dev
endif

# Minify viewer.js file for pdf viewer (Uncomment the lines below if changes are made to the viewer.js file. Requires nodejs 15.x or higher)
# npm install minify -g
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class VirusScanJob extends AbstractConcurrentDepositJob {
.getLogger(VirusScanJob.class);

private static final int MAX_RETRIES = 5;
private long maxStreamSize;

private ClamAVClient clamClient;

Expand Down Expand Up @@ -97,18 +98,20 @@ public void runJob() {
Path file = Paths.get(fileURI);

ScanResult result;
// Clamd is unable to find files with unicode characters in their path
if (charactersInBoundsForClam(file)) {
result = clamClient.scanWithResult(file);
} else {
// Scan files with unicode in their paths via streaming
try {
try {
if (shouldScanByPath(file)) {
// Scan entire file by path
log.debug("Scanning file {} by path", file);
result = clamClient.scanWithResult(file);
} else {
// Scanning via InputStream up to the max number of bytes
log.debug("Scanning file {} by stream", file);
result = clamClient.scanWithResult(Files.newInputStream(file));
} catch (IOException e) {
failures.put(fileURI.toString(), "Failed to scan file");
log.error("Unable to scan file {}", file, e);
return;
}
} catch (IOException e) {
failures.put(fileURI.toString(), "Failed to scan file");
log.error("Unable to scan file {}", file, e);
return;
}

switch (result.getStatus()) {
Expand Down Expand Up @@ -180,8 +183,23 @@ private boolean charactersInBoundsForClam(Path path) {
return CharMatcher.ascii().matchesAllOf(path.toString());
}

/**
* Determines if we should scan a file by its file path or use streaming. Files larger than the scanning
* limit or with characters in their path that clamd can't handle will return false.
* @param path
* @return
* @throws IOException
*/
private boolean shouldScanByPath(Path path) throws IOException {
return Files.size(path) < this.maxStreamSize && charactersInBoundsForClam(path);
}

// unused, no results to flush
@Override
protected void registrationAction() {
}
}

public void setMaxStreamSize(long maxStreamSize) {
this.maxStreamSize = maxStreamSize;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
<property name="clamClient" ref="clamClient" />
<property name="maxQueuedJobs" value="${job.fileValidation.maxQueuedJobs:5}" />
<property name="executorService" ref="fileValidationExecutor" />
<property name="maxStreamSize" value="${clamd.maxStreamSize:64000000}" />
</bean>

<bean id="FixityCheckJob" class="edu.unc.lib.boxc.deposit.validate.FixityCheckJob"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,10 @@
package edu.unc.lib.boxc.deposit.validate;

import static edu.unc.lib.boxc.common.test.TestHelpers.setField;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.File;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.UUID;
import java.util.concurrent.ExecutorService;

import org.apache.commons.io.FileUtils;
import org.apache.jena.rdf.model.Bag;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.RDF;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import com.google.common.util.concurrent.MoreExecutors;

import edu.unc.lib.boxc.common.util.URIUtil;
import edu.unc.lib.boxc.deposit.api.RedisWorkerConstants.DepositState;
import edu.unc.lib.boxc.deposit.fcrepo4.AbstractDepositJobTest;
import edu.unc.lib.boxc.deposit.impl.model.DepositModelHelpers;
import edu.unc.lib.boxc.deposit.validate.VirusScanJob;
import edu.unc.lib.boxc.deposit.work.JobFailedException;
import edu.unc.lib.boxc.deposit.work.JobInterruptedException;
import edu.unc.lib.boxc.model.api.exceptions.RepositoryException;
Expand All @@ -51,6 +17,37 @@
import fi.solita.clamav.ClamAVClient;
import fi.solita.clamav.ScanResult;
import fi.solita.clamav.ScanResult.Status;
import org.apache.commons.io.FileUtils;
import org.apache.jena.rdf.model.Bag;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.RDF;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.io.File;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.UUID;
import java.util.concurrent.ExecutorService;

import static edu.unc.lib.boxc.common.test.TestHelpers.setField;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
*
Expand Down Expand Up @@ -92,6 +89,7 @@ public PID answer(InvocationOnMock invocation) throws Throwable {
});

when(clamClient.scanWithResult(any(Path.class))).thenReturn(scanResult);
when(clamClient.scanWithResult(any(InputStream.class))).thenReturn(scanResult);

File examplesFile = new File("src/test/resources/examples");
FileUtils.copyDirectory(examplesFile, depositDir);
Expand All @@ -104,6 +102,7 @@ private void initializeJob() {
job.setJobUUID(jobUUID);
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
job.setMaxStreamSize(300l);
setField(job, "pidMinter", pidMinter);
job.setClamClient(clamClient);
job.setPremisLoggerFactory(premisLoggerFactory);
Expand Down Expand Up @@ -142,7 +141,8 @@ public void passScanTest() throws Exception {

job.run();

verify(clamClient, times(3)).scanWithResult(any(Path.class));
verify(clamClient, times(1)).scanWithResult(any(InputStream.class));
verify(clamClient, times(2)).scanWithResult(any(Path.class));

verify(jobStatusFactory).setTotalCompletion(eq(jobUUID), eq(3));
verify(jobStatusFactory, times(3)).incrCompletion(eq(jobUUID), eq(1));
Expand Down Expand Up @@ -189,9 +189,8 @@ public void failOneScanTest() throws Exception {
when(result2.getStatus()).thenReturn(Status.FOUND);
File pdfFile = new File(depositDir, "pdf.pdf");
File textFile = new File(depositDir, "text.txt");
when(clamClient.scanWithResult(any(Path.class)))
.thenReturn(scanResult)
.thenReturn(result2);
when(clamClient.scanWithResult(any(InputStream.class))).thenReturn(scanResult);
when(clamClient.scanWithResult(any(Path.class))).thenReturn(result2);

Model model = job.getWritableModel();
Bag depBag = model.createBag(depositPid.getRepositoryPath());
Expand Down
1 change: 0 additions & 1 deletion integration/src/test/resources/access-app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ services.api.url=http://localhost:48080/services/api/

fuseki.baseUri=http://localhost:48080

google.trackingId=
matomo.authToken=
matomo.api.url=
matomo.site.id=5
Expand Down
32 changes: 16 additions & 16 deletions static/js/admin/src/ResultObjectActionMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ define('ResultObjectActionMenu', [ 'jquery', 'jquery-ui', 'StringUtilities', 'A
}

// Export actions
if (metadata.type !== 'File' && $.inArray('viewHidden', metadata.permissions) !== -1) {
if (!isContentRoot && metadata.type !== 'File' && $.inArray('viewHidden', metadata.permissions) !== -1) {
items["export"] = {name: "Export", items: {}}

if (!isContentRoot) {
items['export']['items']["exportCSV"] = {name: "Export CSV"};
}
items['export']['items']["exportCSV"] = {name: "Export CSV"};

items['export']['items']["exportMemberOrder"] = {name: "Export Member Order"};
if (metadata.type === 'Work') {
items['export']['items']["exportMemberOrder"] = {name: "Export Member Order"};
}
}

items["copyid"] = {name : 'Copy PID to Clipboard'};
Expand Down Expand Up @@ -446,19 +446,19 @@ define('ResultObjectActionMenu', [ 'jquery', 'jquery-ui', 'StringUtilities', 'A
})();
break;
case "patronPermissions":
perms_editor_store.commit('setPermissionType', 'Patron');
perms_editor_store.commit('setMetadata', metadata);
perms_editor_store.commit('setShowModal', true);
perms_editor_store.commit('setAlertHandler', self.options.alertHandler);
perms_editor_store.commit('setActionHandler', self.actionHandler);
perms_editor_store.commit('setResultObject', resultObject);
perms_editor_store.commit('setResultObjects', null);
perms_editor_store.setPermissionType('Patron');
perms_editor_store.setMetadata(metadata);
perms_editor_store.setShowModal(true);
perms_editor_store.setAlertHandler(self.options.alertHandler);
perms_editor_store.setActionHandler(self.actionHandler);
perms_editor_store.setResultObject(resultObject);
perms_editor_store.setResultObjects(null);
break;
case "staffPermissions":
perms_editor_store.commit('setPermissionType', 'Staff');
perms_editor_store.commit('setMetadata', metadata);
perms_editor_store.commit('setShowModal', true);
perms_editor_store.commit('setAlertHandler', self.options.alertHandler);
perms_editor_store.setPermissionType('Staff');
perms_editor_store.setMetadata(metadata);
perms_editor_store.setShowModal(true);
perms_editor_store.setAlertHandler(self.options.alertHandler);
break;
}
},
Expand Down
20 changes: 10 additions & 10 deletions static/js/admin/src/action/UpdatePatronAccessBatchAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ define('UpdatePatronAccessBatchAction', [ 'jquery', 'AbstractBatchAction'], func
UpdatePatronAccessBatchAction.prototype.execute = function() {
let targets = this.getTargets();

perms_editor_store.commit('setPermissionType', 'Patron');
perms_editor_store.commit('setAlertHandler', this.context.view.$alertHandler);
perms_editor_store.commit('setActionHandler', this.context.actionHandler);
perms_editor_store.setPermissionType('Patron');
perms_editor_store.setAlertHandler(this.context.view.$alertHandler);
perms_editor_store.setActionHandler(this.context.actionHandler);
if (targets.length == 1) {
perms_editor_store.commit('setResultObject', targets[0]);
perms_editor_store.commit('setResultObjects', null);
perms_editor_store.commit('setMetadata', targets[0].metadata);
perms_editor_store.setResultObject(targets[0]);
perms_editor_store.setResultObjects(null);
perms_editor_store.setMetadata(targets[0].metadata);
} else {
perms_editor_store.commit('setResultObject', null);
perms_editor_store.commit('setResultObjects', targets);
perms_editor_store.commit('setMetadata', {
perms_editor_store.setResultObject(null);
perms_editor_store.setResultObjects(targets);
perms_editor_store.setMetadata({
title: targets.length + " objects",
id: null,
type: null
});
}
perms_editor_store.commit('setShowModal', true);
perms_editor_store.setShowModal(true);

AbstractBatchAction.prototype.execute.call(this);
}
Expand Down
1 change: 1 addition & 0 deletions static/js/admin/vue-permissions-editor/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ yarn-error.log*
*.njsproj
*.sln
*.sw?
.env
Loading

0 comments on commit 113e759

Please sign in to comment.