Sha256: dea664632119c7b0fc661706b4ec1a30b13ec5d624c26415556d97b3c2e554a9

Contents?: true

Size: 1.92 KB

Versions: 40

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'

describe Net::NTLM::TargetInfo do
  let(:key1) { Net::NTLM::TargetInfo::MSV_AV_NB_COMPUTER_NAME }
  let(:value1) { 'some data' }
  let(:key2) { Net::NTLM::TargetInfo::MSV_AV_NB_DOMAIN_NAME }
  let(:value2) { 'some other data' }  
  let(:data) do
    dt = key1.dup
    dt << [value1.length].pack('S')
    dt << value1
    dt << key2.dup
    dt << [value2.length].pack('S')
    dt << value2
    dt << Net::NTLM::TargetInfo::MSV_AV_EOL
    dt << [0].pack('S')
    dt.force_encoding(Encoding::ASCII_8BIT)
  end

  subject { Net::NTLM::TargetInfo.new(data) }

  describe 'invalid data' do

    context 'invalid pair id' do
      let(:data) { "\xFF\x00" }

      it 'returns an error' do
        expect{subject}.to raise_error Net::NTLM::InvalidTargetDataError
      end    
    end
  end

  describe '#av_pairs' do

    it 'returns the pair values with the given keys' do
      expect(subject.av_pairs[key1]).to eq value1
      expect(subject.av_pairs[key2]).to eq value2
    end

    context "target data is nil" do
      subject { Net::NTLM::TargetInfo.new(nil) }

      it 'returns the pair values with the given keys' do
        expect(subject.av_pairs).to be_empty
      end
    end
  end

  describe '#to_s' do
    let(:data) do
      dt = key1.dup
      dt << [value1.length].pack('S')
      dt << value1
      dt << key2.dup
      dt << [value2.length].pack('S')
      dt << value2
      dt.force_encoding(Encoding::ASCII_8BIT)
    end
    let(:new_key) { Net::NTLM::TargetInfo::MSV_AV_CHANNEL_BINDINGS }
    let(:new_value) { 'bindings' }
    let(:new_data) do
      dt = data
      dt << new_key
      dt << [new_value.length].pack('S')
      dt << new_value
      dt << Net::NTLM::TargetInfo::MSV_AV_EOL
      dt << [0].pack('S')
      dt.force_encoding(Encoding::ASCII_8BIT)
    end

    it 'returns bytes with any new data added' do
      subject.av_pairs[new_key] = new_value
      expect(subject.to_s).to eq new_data
    end
  end
end

Version data entries

40 entries across 32 versions & 3 rubygems

Version Path
rubyntlm-0.6.5 spec/lib/net/ntlm/target_info_spec.rb
rubyntlm-0.6.4 spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/rubyntlm-0.6.3/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/rubyntlm-0.6.3/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/rubyntlm-0.6.3/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/rubyntlm-0.6.2/spec/lib/net/ntlm/target_info_spec.rb
rubyntlm-0.6.3 spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/rubyntlm-0.6.2/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/rubyntlm-0.6.2/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/rubyntlm-0.6.2/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/rubyntlm-0.6.2/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rubyntlm-0.6.2/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/rubyntlm-0.6.2/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/rubyntlm-0.6.2/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/rubyntlm-0.6.2/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/rubyntlm-0.6.2/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/rubyntlm-0.6.2/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/rubyntlm-0.6.2/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/rubyntlm-0.6.2/spec/lib/net/ntlm/target_info_spec.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/rubyntlm-0.6.2/spec/lib/net/ntlm/target_info_spec.rb