Skip to content

Commit

Permalink
added test for DISABLED digest type to FoxML digest Validation (#190)
Browse files Browse the repository at this point in the history
* added test for DISABLED digest type

* Adding Integration Test and a new exceptin for disabled digests

* checkstyle fixes

* changing index to match inline-it et al

* seperating test index in case of clash

* fixing issues with the disabled integration test

* removing superflous log message as we throw an exception now

* git wasn't adding an empty dir. used .gitkeep and now the test should parse tge datastream dir

* .gitkeep broke the indexer. copying a datastream from another test

* reverting to logging rather than throwing exception

* improved DISABLED fixity Integration Test to use fcrepo-storage-ocfl session object

* Switch from assembly to shade plugin to correct Jena re-packaging (#189)

Resolves:  https://fedora-repository.atlassian.net/browse/FCREPO-3836

* Alter test assertion to allow for ocfl 1.0 and 1.1 (#192)

Resolves: https://fedora-repository.atlassian.net/browse/FCREPO-3863

* Bump woodstox-core from 6.2.3 to 6.4.0 (#191)

Bumps [woodstox-core](https://github.com/FasterXML/woodstox) from 6.2.3 to 6.4.0.
- [Release notes](https://github.com/FasterXML/woodstox/releases)
- [Commits](FasterXML/woodstox@woodstox-core-6.2.3...woodstox-core-6.4.0)

---
updated-dependencies:
- dependency-name: com.fasterxml.woodstox:woodstox-core
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Increment version to 6.3.1-SNAPSHOT

* fixing issues with the disabled integration test

* removing superflous log message as we throw an exception now

* git wasn't adding an empty dir. used .gitkeep and now the test should parse tge datastream dir

* .gitkeep broke the indexer. copying a datastream from another test

* reverting to logging rather than throwing exception

* improved DISABLED fixity Integration Test to use fcrepo-storage-ocfl session object

* fixed test to look for a DISABLED digest

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Dan Field <[email protected]>
Co-authored-by: Dan Field <[email protected]>
Co-authored-by: Jared Whiklo <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Daniel Bernstein <[email protected]>
  • Loading branch information
6 people authored Feb 16, 2023
1 parent db57ddb commit bad1e17
Show file tree
Hide file tree
Showing 7 changed files with 922 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@ public void processObject(final StreamingFedoraObjectHandler handler) {
dsInfo = new Foxml11DatastreamInfo(objectInfo, reader);
} else if (reader.getLocalName().equals("datastreamVersion")) {
final var v = new Foxml11DatastreamVersion(dsInfo, reader);
v.validateInlineXml();
try {
v.validateInlineXml();
} catch (RuntimeException e) {
// do we need to do anyting with disabled digests?
LOG.error("Inline Validation failed", e);
throw new RuntimeException(e);
}
handler.processDatastreamVersion(v);
} else {
throw new RuntimeException("Unexpected element! \"" + reader.getLocalName() + "\"!");
Expand Down Expand Up @@ -468,6 +474,12 @@ private String extractInlineXml() throws XMLStreamException {

private void validateInlineXml() {
if (isInlineXml && contentDigest != null && StringUtils.isNotBlank(contentDigest.getDigest())) {

if (StringUtils.equals(contentDigest.getType(), "DISABLED")) {
LOG.warn("Datastream Digest DISABLED. Skipping digest validation");
return;
}

final var transformedXml = transformInlineXmlForChecksum();
final var digest = DigestUtils.getDigest(contentDigest.getType());
final var digestBytes = DigestUtils.digest(digest, transformedXml);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,15 @@ private ResourceHeaders createDatastreamHeaders(final DatastreamVersion dv,
}

if (dv.getContentDigest() != null && !Strings.isNullOrEmpty(dv.getContentDigest().getDigest())) {
final var digest = dv.getContentDigest();
final var digests = new ArrayList<URI>();
digests.add(URI.create("urn:" + digest.getType().toLowerCase() + ":" + digest.getDigest().toLowerCase()));
headers.withDigests(digests);
if (!dv.getContentDigest().getDigest().equals("none")) {
final var digest = dv.getContentDigest();
final var digests = new ArrayList<URI>();
digests.add(URI.create("urn:" + digest.getType().toLowerCase() + ":" +
digest.getDigest().toLowerCase()));
headers.withDigests(digests);
} else {
LOGGER.warn("Digest content 'none' found. Not adding to header");
}
}

headers.withMimeType(mime);
Expand Down
74 changes: 74 additions & 0 deletions src/test/java/org/fcrepo/migration/DisabledDigestIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Copyright 2015 DuraSpace, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.fcrepo.migration;

import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.fcrepo.storage.ocfl.OcflObjectSessionFactory;

import java.nio.file.Files;
import java.nio.file.Paths;

import static org.junit.Assert.assertTrue;

/**
* @author Dan Field
*/
public class DisabledDigestIT {

private ConfigurableApplicationContext context;
private Migrator migrator;
private OcflObjectSessionFactory sessionFactory;

@After
public void tearDown() {
if (context != null) {
context.close();
}
}

private void setup(final String name) throws Exception {
final var storage = Paths.get(String.format("target/test/ocfl/%s/storage", name));
final var staging = Paths.get(String.format("target/test/ocfl/%s/staging", name));

if (Files.exists(storage)) {
FileUtils.forceDelete(storage.toFile());
}
if (Files.exists(staging)) {
FileUtils.forceDelete(staging.toFile());
}

Files.createDirectories(storage);
Files.createDirectories(staging);

context = new ClassPathXmlApplicationContext(String.format("spring/%s-setup.xml", name));
migrator = (Migrator) context.getBean("migrator");
sessionFactory = (OcflObjectSessionFactory) context.getBean("ocflSessionFactory");
}

@Test
public void testMigrateObjectWithExternalDatastreamAndDisabledDigest() throws Exception {
setup("inline-disabled-it");
migrator.run();
final var session = sessionFactory.newSession("info:fedora/llgc-id:1591190");
assertTrue(session.containsResource("info:fedora/llgc-id:1591190/POLICY"));
}

}
1 change: 1 addition & 0 deletions src/test/java/org/fcrepo/migration/InlineXmlIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,5 @@ public void failMigrationWhenInlineXmlDoesNotMatchDigest() throws Exception {
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<Policy
xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://digital.library.wisc.edu/1711.dl/XMLSchema-XACML-3.0"
PolicyId="hdl:1711.dl/Access-policy-open-access-UW-Madison-all"
RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-unless-permit"
Version="1.0">
<Description>
Open Access: any user can view, listen to, and/or download any representation of the object,
as long as they're associated with or present at UW-Madison.
</Description>
<Target />
<Rule Effect="Permit" RuleId="permit-UWMadison">
<Target />
<Condition>
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only">
<AttributeDesignator
AttributeId="http://digital.library.wisc.edu/1711.dl/vocabulary/access/population#"
Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
DataType="http://www.w3.org/2001/XMLSchema#string"
MustBePresent="true" />
</Apply>
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">http://digital.library.wisc.edu/1711.dl/vocabulary/access/population#uwmadison</AttributeValue>
</Apply>
</Condition>
</Rule>
<Rule Effect="Deny" RuleId="deny-rule"></Rule>
</Policy>
Loading

0 comments on commit bad1e17

Please sign in to comment.