|
502 | 502 | expect(from_db).to be_nil |
503 | 503 | end |
504 | 504 | end |
| 505 | + |
| 506 | + context 'when the id is a query predicate' do |
| 507 | + # The delete is issued as an exact match, so the predicate matches no |
| 508 | + # file and nothing is removed. Servers that validate the shape of _id in |
| 509 | + # a delete filter reject the command outright; either way, the bucket |
| 510 | + # must be left intact. |
| 511 | + let!(:file_ids) do |
| 512 | + Array.new(3) { |i| fs.upload_from_stream("file#{i}.txt", StringIO.new('a' * 100)) } |
| 513 | + end |
| 514 | + |
| 515 | + let(:predicate) do |
| 516 | + { '$gt' => BSON::MinKey.new } |
| 517 | + end |
| 518 | + |
| 519 | + it 'does not remove any files' do |
| 520 | + begin |
| 521 | + fs.delete(predicate) |
| 522 | + rescue Mongo::Error |
| 523 | + nil |
| 524 | + end |
| 525 | + |
| 526 | + expect(fs.files_collection.count_documents({})).to eq(3) |
| 527 | + end |
| 528 | + |
| 529 | + it 'does not remove any chunks' do |
| 530 | + begin |
| 531 | + fs.delete(predicate) |
| 532 | + rescue Mongo::Error |
| 533 | + nil |
| 534 | + end |
| 535 | + |
| 536 | + expect(fs.chunks_collection.count_documents({})).to eq(3) |
| 537 | + end |
| 538 | + |
| 539 | + it 'leaves the files downloadable' do |
| 540 | + begin |
| 541 | + fs.delete(predicate) |
| 542 | + rescue Mongo::Error |
| 543 | + nil |
| 544 | + end |
| 545 | + |
| 546 | + file_ids.each do |id| |
| 547 | + io = StringIO.new |
| 548 | + fs.download_to_stream(id, io) |
| 549 | + expect(io.string.length).to eq(100) |
| 550 | + end |
| 551 | + end |
| 552 | + end |
| 553 | + end |
| 554 | + |
| 555 | + describe 'reading with a query predicate as the file id' do |
| 556 | + # The file id must be matched exactly, so a predicate matches no file and |
| 557 | + # cannot be used to read another principal's file, or to read chunks |
| 558 | + # belonging to several files at once. |
| 559 | + let!(:file_ids) do |
| 560 | + Array.new(3) { |i| fs.upload_from_stream("file#{i}.txt", StringIO.new('a' * 100)) } |
| 561 | + end |
| 562 | + |
| 563 | + let(:predicate) do |
| 564 | + { '$gt' => BSON::MinKey.new } |
| 565 | + end |
| 566 | + |
| 567 | + it 'does not download another file' do |
| 568 | + expect do |
| 569 | + fs.download_to_stream(predicate, StringIO.new) |
| 570 | + end.to raise_error(Mongo::Error::FileNotFound) |
| 571 | + end |
| 572 | + |
| 573 | + it 'does not read another file through an open stream' do |
| 574 | + expect do |
| 575 | + fs.open_download_stream(predicate, &:read) |
| 576 | + end.to raise_error(Mongo::Error::FileNotFound) |
| 577 | + end |
| 578 | + |
| 579 | + it 'leaves the files readable by their real ids' do |
| 580 | + begin |
| 581 | + fs.download_to_stream(predicate, StringIO.new) |
| 582 | + rescue Mongo::Error |
| 583 | + nil |
| 584 | + end |
| 585 | + |
| 586 | + file_ids.each do |id| |
| 587 | + io = StringIO.new |
| 588 | + fs.download_to_stream(id, io) |
| 589 | + expect(io.string).to eq('a' * 100) |
| 590 | + end |
| 591 | + end |
505 | 592 | end |
506 | 593 |
|
507 | 594 | context 'when a read stream is opened' do |
|
0 commit comments