|
45 | 45 | allow(ENV).to receive(:[]).with('AWS_REGION').and_return('us-east-2') |
46 | 46 | expect(subject.host).to eq 'mybucket.domain' |
47 | 47 | expect(subject.path).to eq '/mykey.mp4' |
48 | | - expect(subject.query).to include('response-content-disposition=attachment%3B%20filename%3Dmykey.mp4', 'X-Amz-Algorithm', |
| 48 | + expect(subject.query).to include('response-content-disposition=attachment%3B%20filename%3Dmykey.mp4', 'X-Amz-Algorithm', |
49 | 49 | 'X-Amz-Credential', 'X-Amz-Expires', 'X-Amz-SignedHeaders', 'X-Amz-Signature') |
50 | 50 | end |
51 | 51 |
|
|
60 | 60 | allow(ENV).to receive(:[]).with('AWS_REGION').and_return('us-east-2') |
61 | 61 | expect(subject.host).to eq 'mybucket.s3.us-stubbed-1.amazonaws.com' |
62 | 62 | expect(subject.path).to eq '/mykey.mp4' |
63 | | - expect(subject.query).to include('response-content-disposition=attachment%3B%20filename%3Dmykey.mp4', 'X-Amz-Algorithm', |
| 63 | + expect(subject.query).to include('response-content-disposition=attachment%3B%20filename%3Dmykey.mp4', 'X-Amz-Algorithm', |
64 | 64 | 'X-Amz-Credential', 'X-Amz-Expires', 'X-Amz-SignedHeaders', 'X-Amz-Signature') |
65 | 65 | end |
66 | 66 | end |
|
168 | 168 | describe '#remove_fs_dir' do |
169 | 169 | let(:file_path) { "/tmp/dropbox/test/mykey.mp4" } |
170 | 170 | let(:locator) { FileLocator.new(file_path) } |
171 | | - |
| 171 | + |
172 | 172 | it 'deletes fs dir' do |
173 | 173 | allow(File).to receive(:exist?).with(file_path) { true } |
174 | 174 | expect(locator.exist?).to be_truthy |
|
177 | 177 | expect(locator.exist?).to be_falsey |
178 | 178 | end |
179 | 179 | end |
180 | | - |
| 180 | + |
181 | 181 | describe '#remove_s3_dir' do |
182 | 182 | let(:old_bucket) { Settings.encoding.masterfile_bucket } |
183 | 183 | let(:old_path) { Settings.dropbox.path } |
184 | 184 |
|
185 | 185 | let(:dropbox_path) { "s3://#{test_bucket}/dropbox/test_collection" } |
186 | 186 | let(:test_bucket) { "test_bucket" } |
187 | | - let(:dropbox_prefix) { "/dropbox/test_collection/"} |
| 187 | + let(:dropbox_prefix) { "/dropbox/test_collection/" } |
188 | 188 | let(:s3_res) { Aws::S3::Resource.new } |
189 | 189 | let(:s3_bucket) { Aws::S3::Bucket.new(test_bucket) } |
190 | 190 |
|
|
225 | 225 | end |
226 | 226 | end |
227 | 227 | end |
| 228 | + |
| 229 | + describe "#magic_bytes" do |
| 230 | + let(:locator) { FileLocator.new(source) } |
| 231 | + let(:source) { "file://#{Rails.root.join('spec', 'fixtures', 'videoshort.mp4')}" } |
| 232 | + |
| 233 | + context "local file" do |
| 234 | + it "returns the first 16 bytes" do |
| 235 | + expect(locator.magic_bytes.length).to eq 16 |
| 236 | + end |
| 237 | + |
| 238 | + it 'successfully returns correct mimetype' do |
| 239 | + expect(Marcel::MimeType.for(locator.magic_bytes)).to eq 'video/mp4' |
| 240 | + end |
| 241 | + end |
| 242 | + |
| 243 | + context "s3 file" do |
| 244 | + let(:client) { Aws::S3::Client.new(stub_responses: true) } |
| 245 | + let(:bucket) { "mybucket" } |
| 246 | + let(:key) { "meow.wav" } |
| 247 | + let(:source) { "s3://#{bucket}/#{key}" } |
| 248 | + let(:object_body) { File.read(Rails.root.join('spec', 'fixtures', 'videoshort.mp4')) } |
| 249 | + |
| 250 | + before do |
| 251 | + client.stub_responses(:get_object, lambda { |context| |
| 252 | + range = context.params[:range] |
| 253 | + from, to = range.match(/bytes=(\d+)-(\d+)/)[1..2].map(&:to_i) |
| 254 | + # Return the specific byte range of the content |
| 255 | + { body: object_body[from..to], content_range: "bytes #{from}-#{to}/#{object_body.length}" } |
| 256 | + }) |
| 257 | + |
| 258 | + allow(Aws::S3::Client).to receive(:new).and_return(client) |
| 259 | + end |
| 260 | + |
| 261 | + it "returns the first 16 bytes" do |
| 262 | + expect(locator.magic_bytes.length).to eq 16 |
| 263 | + end |
| 264 | + |
| 265 | + it 'successfully returns correct mimetype' do |
| 266 | + expect(Marcel::MimeType.for(locator.magic_bytes)).to eq 'video/mp4' |
| 267 | + end |
| 268 | + end |
| 269 | + |
| 270 | + context "other file" do |
| 271 | + let(:file_path) { "bogus://#{source}" } |
| 272 | + it "returns the first 16 bytes" do |
| 273 | + allow(URI).to receive(:open).with(file_path).and_return(URI.open(Rails.root.join('spec', 'fixtures', 'videoshort.mp4').to_s)) |
| 274 | + expect(locator.magic_bytes.length).to eq 16 |
| 275 | + end |
| 276 | + |
| 277 | + it 'successfully returns correct mimetype' do |
| 278 | + expect(Marcel::MimeType.for(locator.magic_bytes)).to eq 'video/mp4' |
| 279 | + end |
| 280 | + end |
| 281 | + end |
228 | 282 | end |
0 commit comments