Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
Add additional checksum verification in specs
Browse files Browse the repository at this point in the history
This adds an additional checksum verification to
the external files conversion spec. This ensures
that the FixityService returns the sha1 we expect
for the world.png file.

It also ensures that the checksums are the same
when the existing file is placed in `/tmp` and
that the file that is downloaded from a redirect
also has the correct checksum.
  • Loading branch information
little9 committed Sep 7, 2018
1 parent 2b5dcd0 commit 20e2732
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions spec/services/external_files_conversion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'rails_helper'
require 'fileutils'
require 'digest'

describe ExternalFilesConversion do
context 'running a conversion from internal to external file storage' do
Expand All @@ -10,22 +11,39 @@
let(:user) { create(:user) }
let(:work) { create(:public_work_with_png, depositor: user.login) }
let(:file_set) { work.file_sets.first }
let(:filepath) { File.join(fixture_path, 'world.png') }
let(:filepath) { File.join(fixture_path, 'test.pdf') }
let(:fedora_sha1) { 'urn:sha1:ad13c5e7cc6d8198f25e003bd2965b3544e52a32' }
let(:fedora_sha1_without_urn) { 'ad13c5e7cc6d8198f25e003bd2965b3544e52a32' }
let(:sha1) { Digest::SHA1.new }

before do
allow(CharacterizeJob).to receive(:perform_later)
end

it 'converts all works of a given Class' do
it 'converts all works of a given Class and has the correct checksums' do
ENV['REPOSITORY_EXTERNAL_FILES'] = 'false'
file_set
response = Net::HTTP.get_response(URI(file_set.files.first.uri.to_s))
expect(response.to_s).to match(/OK/)
ENV['REPOSITORY_EXTERNAL_FILES'] = 'true'
full_conversion
response = Net::HTTP.get_response(URI(file_set.files.first.uri.to_s))
expect(response['content-disposition']).to match(/world.png/)
expect(file_set.original_file.original_name).to eq('world.png')
expect(response['content-disposition']).to match(/test.pdf/)
expect(file_set.original_file.original_name).to eq('test.pdf')

# Test the fixity service checksum
fs = ActiveFedora::FixityService.new(file_set.files.first.uri)
expect(fs.expected_message_digest).to eq(fedora_sha1)

# Check the checksum of the temp file
latest_file_directory = Dir.entries(Rails.root.join('tmp', 'external_internal_conversion')).sort.last
world_png = Rails.root.join('tmp', 'external_internal_conversion', latest_file_directory, 'test.pdf')
world_png_file = File.read(world_png)
expect(sha1.hexdigest(File.read(world_png_file))).to eq(fedora_sha1_without_urn)
world_png_file.close

# Check the checksum of the redirect repository file
expect(sha1.hexdigest(open(response.uri).read)).to eq(fedora_sha1_without_urn)
expect(response.to_s).to match(/HTTPTemporaryRedirect/)
end
it 'converts a single work of a given Class' do
Expand All @@ -36,8 +54,8 @@
ENV['REPOSITORY_EXTERNAL_FILES'] = 'true'
single_work_conversion
response = Net::HTTP.get_response(URI(file_set.files.first.uri.to_s))
expect(response['content-disposition']).to match(/world.png/)
expect(file_set.original_file.original_name).to eq('world.png')
expect(response['content-disposition']).to match(/test.pdf/)
expect(file_set.original_file.original_name).to eq('test.pdf')
expect(response.to_s).to match(/HTTPTemporaryRedirect/)
end
context 'running from a file' do
Expand Down Expand Up @@ -69,8 +87,8 @@
ENV['REPOSITORY_EXTERNAL_FILES'] = 'true'
described_class.new(GenericWork).convert(file: pidfile)
response = Net::HTTP.get_response(URI(file_set1.files.first.uri.to_s))
expect(response['content-disposition']).to match(/world.png/)
expect(file_set1.original_file.original_name).to eq('world.png')
expect(response['content-disposition']).to match(/test.pdf/)
expect(file_set1.original_file.original_name).to eq('test.pdf')
expect(response.to_s).to match(/HTTPTemporaryRedirect/)
end
it "adds any ids it can't convert to an error file" do
Expand Down

0 comments on commit 20e2732

Please sign in to comment.