Sha256: 1a2c51e1502615994172ff0105fbe3adeb0fa3f3a948060171be6cc1b9a611f8

Contents?: true

Size: 1.31 KB

Versions: 16

Compression:

Stored size: 1.31 KB

Contents

require 'spec_helper'

RSpec.describe RubySMB::Field::Stringz16 do
  subject(:stringz16) { described_class.new }

  it 'starts as an empty string' do
    expect(stringz16).to eq ''
  end

  context 'with a value already set' do
    let(:abcd) { described_class.new('ABCD') }

    it 'should be UTF-16le' do
      expect(abcd).to eq 'ABCD'.encode('utf-16le')
    end

    it 'should include the NULL terminator on binary output' do
      expect(abcd.to_binary_s).to eq "A\x00B\x00C\x00D\x00\x00\x00"
    end
  end

  context 'with a null terminator in the middle' do
    let(:null_terminator) { described_class.new("ABCD\x00EFG") }

    it 'drops everything after the null terminator' do
      expect(null_terminator).to eq 'ABCD'.encode('utf-16le')
    end
  end

  context 'when reading data in' do
    it 'stops at the first double null byte' do
      io = StringIO.new("A\x00B\x00C\x00D\x00\x00\x00E\x00F\x00")
      stringz16.read(io)
      expect(stringz16.to_binary_s).to eq "A\x00B\x00C\x00D\x00\x00\x00"
    end

    it 'handles a zero length string' do
      io = StringIO.new("\x00\x00A\x00")
      stringz16.read(io)
      expect(stringz16).to eq ''
    end

    it 'fails if no null terminator is found' do
      io = StringIO.new("A\x00B\x00C\x00D\x00")
      expect { stringz16.read(io) }.to raise_error(EOFError)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby_smb-2.0.2 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-2.0.1 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-2.0.0 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-1.1.0 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-1.0.5 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-1.0.4 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-1.0.3 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-1.0.2 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-1.0.1 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-1.0.0 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-0.0.24 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-0.0.23 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-0.0.22 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-0.0.21 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-0.0.20 spec/lib/ruby_smb/field/stringz16_spec.rb
ruby_smb-0.0.19 spec/lib/ruby_smb/field/stringz16_spec.rb