diff options
Diffstat (limited to 'spec/uploaders')
-rw-r--r-- | spec/uploaders/file_uploader_spec.rb | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/spec/uploaders/file_uploader_spec.rb b/spec/uploaders/file_uploader_spec.rb index efdbea85d4a..5fd64da6328 100644 --- a/spec/uploaders/file_uploader_spec.rb +++ b/spec/uploaders/file_uploader_spec.rb @@ -145,11 +145,39 @@ describe FileUploader do end describe '.extract_dynamic_path' do - it 'works with hashed storage' do - path = 'export/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a/test/uploads/72a497a02fe3ee09edae2ed06d390038/dummy.txt' + context 'with a 32-byte hexadecimal secret in the path' do + let(:secret) { SecureRandom.hex } + let(:path) { "export/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a/test/uploads/#{secret}/dummy.txt" } - expect(described_class.extract_dynamic_path(path)[:identifier]).to eq('dummy.txt') - expect(described_class.extract_dynamic_path(path)[:secret]).to eq('72a497a02fe3ee09edae2ed06d390038') + it 'extracts the secret' do + expect(described_class.extract_dynamic_path(path)[:secret]).to eq(secret) + end + + it 'extracts the identifier' do + expect(described_class.extract_dynamic_path(path)[:identifier]).to eq('dummy.txt') + end + end + + context 'with a 10-byte hexadecimal secret in the path' do + let(:secret) { SecureRandom.hex(10) } + let(:path) { "export/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a/test/uploads/#{secret}/dummy.txt" } + + it 'extracts the secret' do + expect(described_class.extract_dynamic_path(path)[:secret]).to eq(secret) + end + + it 'extracts the identifier' do + expect(described_class.extract_dynamic_path(path)[:identifier]).to eq('dummy.txt') + end + end + + context 'with an invalid secret in the path' do + let(:secret) { 'foo' } + let(:path) { "export/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a/test/uploads/#{secret}/dummy.txt" } + + it 'returns nil' do + expect(described_class.extract_dynamic_path(path)).to be_nil + end end end |