|
| 1 | +# -*- coding:binary -*- |
| 2 | +require 'spec_helper' |
| 3 | + |
| 4 | +require 'rex/ole' |
| 5 | + |
| 6 | +describe Rex::OLE::MiniFAT do |
| 7 | + |
| 8 | + let(:storage) do |
| 9 | + Rex::OLE::Storage.new |
| 10 | + end |
| 11 | + |
| 12 | + subject(:minifat) do |
| 13 | + described_class.new(storage) |
| 14 | + end |
| 15 | + |
| 16 | + describe "#allocate_sector" do |
| 17 | + context "when entries is empty" do |
| 18 | + it "returns index 0" do |
| 19 | + expect(minifat.allocate_sector).to eq(0) |
| 20 | + end |
| 21 | + |
| 22 | + it "allocates idx_per_sect entries" do |
| 23 | + minifat.allocate_sector |
| 24 | + storage = minifat.instance_variable_get(:@stg) |
| 25 | + expect(minifat.length).to eq(storage.header.idx_per_sect) |
| 26 | + end |
| 27 | + |
| 28 | + it "marks the first entry as SECT_END" do |
| 29 | + minifat.allocate_sector |
| 30 | + expect(minifat[0]).to eq(Rex::OLE::SECT_END) |
| 31 | + end |
| 32 | + |
| 33 | + it "marks the remaining entries as SECT_FREE" do |
| 34 | + minifat.allocate_sector |
| 35 | + storage = minifat.instance_variable_get(:@stg) |
| 36 | + (1..storage.header.idx_per_sect - 1).each do |i| |
| 37 | + expect(minifat[i]).to eq(Rex::OLE::SECT_FREE) |
| 38 | + end |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + context "when entries include a free sector" do |
| 43 | + it "returns the free sector index entry" do |
| 44 | + minifat + [1, 2, Rex::OLE::SECT_FREE] |
| 45 | + expect(minifat.allocate_sector).to eq(2) |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + context "when entries don't include a free sector" do |
| 50 | + it "returns index of a new entry" do |
| 51 | + minifat + [1, 2, 3] |
| 52 | + expect(minifat.allocate_sector).to eq(3) |
| 53 | + end |
| 54 | + |
| 55 | + it "allocates idx_per_sect entries" do |
| 56 | + minifat + [1, 2, 3] |
| 57 | + minifat.allocate_sector |
| 58 | + storage = minifat.instance_variable_get(:@stg) |
| 59 | + expect(minifat.length).to eq(storage.header.idx_per_sect + 3) |
| 60 | + end |
| 61 | + |
| 62 | + it "marks the first entry as SECT_END" do |
| 63 | + minifat + [1, 2, 3] |
| 64 | + minifat.allocate_sector |
| 65 | + expect(minifat[3]).to eq(Rex::OLE::SECT_END) |
| 66 | + end |
| 67 | + |
| 68 | + it "marks the remaining entries as SECT_FREE" do |
| 69 | + minifat + [1, 2, 3] |
| 70 | + minifat.allocate_sector |
| 71 | + storage = minifat.instance_variable_get(:@stg) |
| 72 | + (4..3 + storage.header.idx_per_sect - 1).each do |i| |
| 73 | + expect(minifat[i]).to eq(Rex::OLE::SECT_FREE) |
| 74 | + end |
| 75 | + end |
| 76 | + end |
| 77 | + end |
| 78 | + |
| 79 | + describe "#read" do |
| 80 | + context "when the MiniFAT in the storage is empty" do |
| 81 | + it "returns zero" do |
| 82 | + expect(minifat.read).to eq(0) |
| 83 | + end |
| 84 | + end |
| 85 | + end |
| 86 | + |
| 87 | + describe "#write" do |
| 88 | + context "when entries is empty" do |
| 89 | + it "returns nil" do |
| 90 | + expect(minifat.write).to be_nil |
| 91 | + end |
| 92 | + end |
| 93 | + end |
| 94 | + |
| 95 | +end |
0 commit comments