File: shb_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 (42 lines) | stat: -rw-r--r-- 1,393 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
37
38
39
40
41
42
# -*- coding: binary -*-
require 'spec_helper'
require 'packetfu'

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

      it 'should have correct initialization values' do
        expect(@shb).to be_a(SHB)
        expect(@shb.endian).to eq(:little)
        expect(@shb.type.to_i).to eq(PcapNG::SHB_TYPE.to_i)
        expect(@shb.block_len.to_i).to eq(SHB::MIN_SIZE)
        expect(@shb.magic.to_s).to eq(SHB::MAGIC_LITTLE)
        expect(@shb.ver_major.to_i).to eq(1)
        expect(@shb.ver_minor.to_i).to eq(0)
        expect(@shb.section_len.to_i).to eq(0xffffffff_ffffffff)
        expect(@shb.block_len2).to eq(@shb.block_len)
        expect(@shb.interfaces).to eq([])
        expect(@shb.unknown_blocks).to eq([])
      end

      context 'when reading' do
        it 'should accept a String' do
          str = ::File.read(::File.join(__dir__, '../..', 'test', 'sample.pcapng'), 52)
          expect { @shb.read(str) }.to_not raise_error
          expect(@shb.block_len.to_i).to eq(52)
          expect(@shb.has_options?).to be(true)
        end

        it 'should accept an IO' do
          ::File.open(::File.join(__dir__, '../..', 'test', 'sample.pcapng')) do |f|
            @shb.read(f)
          end
          expect(@shb.block_len.to_i).to eq(52)
          expect(@shb.has_options?).to be(true)
        end
      end
    end
  end
end