File: unknown_block_spec.rb

package info (click to toggle)
ruby-packetfu 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,520 kB
  • sloc: ruby: 8,344; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,081 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: binary -*-
require 'spec_helper'
require 'packetfu'

module PacketFu
  module PcapNG
    describe UnknownBlock do
      before(:each) { @ub = UnknownBlock.new }

      it 'should have correct initialization values' do
        expect(@ub).to be_a(UnknownBlock)
        expect(@ub.endian).to eq(:little)
        expect(@ub.type.to_i).to eq(0)
        expect(@ub.block_len.to_i).to eq(UnknownBlock::MIN_SIZE)
        expect(@ub.block_len2).to eq(@ub.block_len)
      end

      context 'when reading' do
        it 'should accept a String' do
          str = "\xff\xff\xff\xff\x0c\x00\x00\x00\x0c\x00\x00\x00"
          expect { @ub.read(str) }.to_not raise_error
          expect(@ub.type.to_i).to eq(0xffffffff)
          expect(@ub.block_len.to_i).to eq(12)
        end

        it 'should accept an IO' do
          ::File.open(::File.join(__dir__, '../..', 'test', 'sample.pcapng')) do |f|
            @ub.read(f)
          end
          expect(@ub.type.to_i).to eq(0x0a0d0d0a)
          expect(@ub.block_len.to_i).to eq(52)
        end
      end
    end
  end
end