Skip to content

Commit 562da99

Browse files
committed
Update the client spec
1 parent e8109e7 commit 562da99

1 file changed

Lines changed: 20 additions & 23 deletions

File tree

spec/lib/ruby_smb/dcerpc/client_spec.rb

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
require 'ruby_smb/dcerpc/client'
2+
require 'ipaddr'
23

34
RSpec.describe RubySMB::Dcerpc::Client do
4-
it 'includes the RubySMB::Dcerpc::Epm class' do
5-
expect(described_class < RubySMB::Dcerpc::Epm).to be true
5+
it 'includes the RubySMB::PeerInfo class' do
6+
expect(described_class < RubySMB::PeerInfo).to be true
67
end
78

89
let(:host) { '1.2.3.4' }
@@ -75,42 +76,38 @@
7576
end
7677

7778
context 'without TCP port' do
78-
let(:host_port) { {host: '0.9.8.7', port: 999} }
79+
let(:host_port) { {host: '192.0.2.1', port: 999} }
80+
let(:epm_client) { double('EPM DCERPC Client') }
7981
let(:epm_tcp_socket) { double('EPM TcpSocket') }
8082
before :example do
81-
allow(TCPSocket).to receive(:new).with(host, 135).and_return(epm_tcp_socket)
82-
allow(client).to receive(:bind)
83-
allow(client).to receive(:get_host_port_from_ept_mapper).and_return(host_port)
84-
allow(epm_tcp_socket).to receive(:close)
85-
end
86-
87-
it 'connects to port 135' do
88-
client.connect
89-
expect(TCPSocket).to have_received(:new).with(host, 135)
83+
allow(described_class).to receive(:new).with(host, endpoint).and_call_original
84+
allow(described_class).to receive(:new).with(host, RubySMB::Dcerpc::Epm, {:read_timeout => 30}).and_return(epm_client)
85+
allow(epm_client).to receive(:connect)
86+
allow(epm_client).to receive(:bind)
87+
allow(epm_client).to receive(:ept_map_endpoint).with(endpoint).and_return(
88+
[{address: IPAddr.new(host_port[:host], Socket::AF_INET), port: host_port[:port]}]
89+
)
90+
allow(epm_client).to receive(:close)
9091
end
9192

92-
it 'binds to the Endpoint Mapper endpoint' do
93+
it 'creates a new client bound to the Endpoint Mapper endpoint' do
9394
client.connect
94-
expect(client).to have_received(:bind).with(endpoint: RubySMB::Dcerpc::Epm)
95+
expect(described_class).to have_received(:new).with(host, RubySMB::Dcerpc::Epm, {:read_timeout => 30})
9596
end
9697

9798
it 'gets host and port information from the Endpoint Mapper' do
9899
client.connect
99-
expect(client).to have_received(:get_host_port_from_ept_mapper).with(
100-
uuid: endpoint::UUID,
101-
maj_ver: endpoint::VER_MAJOR,
102-
min_ver: endpoint::VER_MINOR
103-
)
100+
expect(epm_client).to have_received(:ept_map_endpoint).with(endpoint)
104101
end
105102

106-
it 'closes the EPM socket' do
103+
it 'closes the EPM client socket' do
107104
client.connect
108-
expect(epm_tcp_socket).to have_received(:close)
105+
expect(epm_client).to have_received(:close)
109106
end
110107

111108
it 'connects to the endpoint and returns the socket' do
112109
expect(client.connect).to eq(tcp_socket)
113-
expect(TCPSocket).to have_received(:new).with(host, 999)
110+
expect(TCPSocket).to have_received(:new).with(host, host_port[:port])
114111
end
115112
end
116113
end
@@ -330,7 +327,7 @@
330327

331328
it 'sends an auth3 request' do
332329
client.bind(**kwargs)
333-
expect(client).to have_received(:auth_provider_complete_handshake).with(bindack_response, auth_type: kwargs[:auth_type], auth_level: kwargs[:auth_level])
330+
expect(client).to have_received(:auth_provider_complete_handshake).with(bindack_response, auth_type: kwargs[:auth_type], auth_level: kwargs[:auth_level], endpoint: endpoint)
334331
end
335332
end
336333
end

0 commit comments

Comments
 (0)