|
90 | 90 | end
|
91 | 91 |
|
92 | 92 | describe "#length" do
|
| 93 | + subject(:difat_length) do |
| 94 | + difat.length |
| 95 | + end |
| 96 | + |
93 | 97 | context "when @entries is empty" do
|
94 | 98 | it "returns 0" do
|
95 |
| - expect(difat.length).to eq(0) |
| 99 | + is_expected.to eq(0) |
96 | 100 | end
|
97 | 101 | end
|
98 | 102 |
|
99 | 103 | context "when @entries isn't empty" do
|
100 | 104 | it "returns the @entries length" do
|
101 | 105 | difat[0] = 1
|
102 | 106 | difat[1] = 2
|
103 |
| - expect(difat.length).to eq(2) |
| 107 | + is_expected.to eq(2) |
104 | 108 | end
|
105 | 109 | end
|
106 | 110 | end
|
|
164 | 168 | end
|
165 | 169 |
|
166 | 170 | describe "#to_s" do
|
| 171 | + subject(:difat_string) do |
| 172 | + difat.to_s |
| 173 | + end |
| 174 | + |
167 | 175 | it "returns an String" do
|
168 |
| - expect(difat.to_s).to be_an(String) |
| 176 | + is_expected.to be_an(String) |
169 | 177 | end
|
170 | 178 |
|
171 | 179 | it "starts with {" do
|
172 |
| - expect(difat.to_s).to start_with('{') |
| 180 | + is_expected.to start_with('{') |
173 | 181 | end
|
174 | 182 |
|
175 | 183 | it "ends with }" do
|
176 |
| - expect(difat.to_s).to end_with('}') |
| 184 | + is_expected.to end_with('}') |
177 | 185 | end
|
178 | 186 |
|
179 | 187 | it "contains @entries values" do
|
180 | 188 | difat + [Rex::OLE::SECT_FAT, 1, 2, 3, Rex::OLE::SECT_DIF, Rex::OLE::SECT_FREE, Rex::OLE::SECT_END]
|
181 |
| - expect(difat.to_s).to match(/FAT, 0x1, 0x2, 0x3, DIF, FREE, END/) |
| 189 | + is_expected.to match(/FAT, 0x1, 0x2, 0x3, DIF, FREE, END/) |
182 | 190 | end
|
183 | 191 | end
|
184 | 192 |
|
185 | 193 | describe "#read" do
|
186 |
| - |
| 194 | + context "when difat is empty" do |
| 195 | + it "returns nil" do |
| 196 | + expect(difat.read).to be_nil |
| 197 | + end |
| 198 | + end |
187 | 199 | end
|
188 | 200 |
|
189 | 201 | describe "#write" do
|
| 202 | + context "when entries is empty" do |
| 203 | + it "returns 0" do |
| 204 | + expect(difat.write).to eq(0) |
| 205 | + end |
| 206 | + |
| 207 | + it "fills the first 109 FAT sectors in the storage header" do |
| 208 | + difat.write |
| 209 | + storage = difat.instance_variable_get(:@stg) |
| 210 | + expect(storage.header._sectFat.length).to eq(109) |
| 211 | + end |
| 212 | + |
| 213 | + it "fills the first 109 FAT sectors in the storage header with SECT_FREE" do |
| 214 | + difat.write |
| 215 | + storage = difat.instance_variable_get(:@stg) |
| 216 | + storage.header._sectFat.each { |s| |
| 217 | + expect(s).to eq(Rex::OLE::SECT_FREE) |
| 218 | + } |
| 219 | + end |
| 220 | + end |
| 221 | + |
| 222 | + context "when entries length is less than 109" do |
| 223 | + let(:entries) { [1] * 20 } |
| 224 | + |
| 225 | + it "returns the number of entries" do |
| 226 | + difat + entries |
| 227 | + expect(difat.write).to eq(20) |
| 228 | + end |
| 229 | + |
| 230 | + it "fills the first 109 FAT sectors in the storage header" do |
| 231 | + difat + entries |
| 232 | + difat.write |
| 233 | + storage = difat.instance_variable_get(:@stg) |
| 234 | + expect(storage.header._sectFat.length).to eq(109) |
| 235 | + end |
| 236 | + |
| 237 | + it "fills the first FAT sectors with the entries" do |
| 238 | + difat + entries |
| 239 | + difat.write |
| 240 | + storage = difat.instance_variable_get(:@stg) |
| 241 | + (0..entries.length - 1).each { |i| |
| 242 | + expect(storage.header._sectFat[i]).to eq(1) |
| 243 | + } |
| 244 | + end |
| 245 | + |
| 246 | + it "fills the remaining FAT sectors with FREE sectors" do |
| 247 | + difat + entries |
| 248 | + difat.write |
| 249 | + storage = difat.instance_variable_get(:@stg) |
| 250 | + (entries.length..109 - 1).each { |i| |
| 251 | + expect(storage.header._sectFat[i]).to eq(Rex::OLE::SECT_FREE) |
| 252 | + } |
| 253 | + end |
| 254 | + end |
| 255 | + |
| 256 | + context "when entries length is 109" do |
| 257 | + let(:entries) { [1] * 109 } |
| 258 | + |
| 259 | + it "returns the number of entries" do |
| 260 | + difat + entries |
| 261 | + expect(difat.write).to eq(109) |
| 262 | + end |
| 263 | + |
| 264 | + it "fills the first 109 FAT sectors in the storage header" do |
| 265 | + difat + entries |
| 266 | + difat.write |
| 267 | + storage = difat.instance_variable_get(:@stg) |
| 268 | + expect(storage.header._sectFat.length).to eq(109) |
| 269 | + end |
| 270 | + |
| 271 | + it "fills the first 109 FAT sectors with the entries" do |
| 272 | + difat + entries |
| 273 | + difat.write |
| 274 | + storage = difat.instance_variable_get(:@stg) |
| 275 | + (0..storage.header._sectFat.length - 1).each { |i| |
| 276 | + expect(storage.header._sectFat[i]).to eq(1) |
| 277 | + } |
| 278 | + end |
| 279 | + end |
| 280 | + |
| 281 | + context "when entries length is greater than 109" do |
| 282 | + let(:entries) { [1] * 110 } |
| 283 | + |
| 284 | + it "raises a RuntimeError" do |
| 285 | + difat + entries |
| 286 | + expect { difat.write }.to raise_error(RuntimeError) |
| 287 | + end |
| 288 | + end |
190 | 289 |
|
191 | 290 | end
|
192 | 291 | end
|
0 commit comments