Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensures that external resources are not exported by default. #158

Merged
merged 2 commits into from
Feb 3, 2021

Conversation

dbernstein
Copy link
Contributor

@dbernstein dbernstein commented Jan 12, 2021

Users must now specify --external=true to export proxied and redirected external resources.

Resolves: https://jira.lyrasis.org/browse/FCREPO-3416

This PR is covered by new integration test.

To test manually:

  1. start up fcrepo 5.1.1 with allowed external content
cat "https://" > allowed_external_paths.txt
java -Dfcrepo.external.content.allowed=./allowed_external_paths.txt -jar fcrepo-webapp-5.1.1-jetty-console.jar --headless
  1. create a proxied resource pointing at the newly created binary.
curl -i -H"Link: <https://wiki.lyrasis.org/download/attachments/4980737/atl.site.logo>; rel=\"http://fedoraent\"; handling=\"proxy\"; type=\"image/png\"" -XPUT -ufedoraAdmin:fedoraAdmin http://localhost:8080/rest/proxy_test
  1. perform an export
 java -jar fcrepo-import-export-1.1.0-SNAPSHOT.jar -b -d export-3416 -u fedoraAdmin:fedoraAdmin  -b -m export -r http://localhost:8080/rest
  1. verify that the external resource file is zero length
ls -lastR export-3416/ | grep proxy_test.external
  1. perform export again with --external flag enabled
# remove previous export
 rm -rf export-3416
# run export
 java -jar target/fcrepo-import-export-1.1.0-SNAPSHOT.jar -b -d export-3416 -u fedoraAdmin:fedoraAdmin  -b --external -m export -r http://localhost:8080/rest
  1. verify that the external resource non-zero length.
ls -lastR export-3416/ | grep proxy_test.external

Users must now specify --external=true to export proxied and redirected external resources.

Resolves: https://jira.lyrasis.org/browse/FCREPO-3416
Copy link

@awoods awoods left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as advertised. Should be good to go, pending response to code review comments.

//only retrieve content of external resources when retrieve external flag is enabled
//otherwise write a zero length file.
final InputStream is = external && !config.retrieveExternal() ?
IOUtils.toInputStream("", Charset.defaultCharset()) : response.getBody();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not seeing this InputStream being closed anywhere. Is it happening?

final Map<String,String> headers = new HashMap<>();
headers.put("Link", "<" + binaryURI.toString() + ">;" +
" rel=\"http://fedora.info/definitions/fcrepo#ExternalContent\"; " +
" handling=\"redirect\"; " +
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness, may as well add another test for proxy.

* ensure inputstream is closed
* add test to verify that proxy handling works as well.
@awoods awoods merged commit e7aa8bd into fcrepo-exts:main Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants