|
1 | 1 | require 'ruby_smb/dcerpc/client' |
| 2 | +require 'ipaddr' |
2 | 3 |
|
3 | 4 | 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 |
6 | 7 | end |
7 | 8 |
|
8 | 9 | let(:host) { '1.2.3.4' } |
|
75 | 76 | end |
76 | 77 |
|
77 | 78 | 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') } |
79 | 81 | let(:epm_tcp_socket) { double('EPM TcpSocket') } |
80 | 82 | 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) |
90 | 91 | end |
91 | 92 |
|
92 | | - it 'binds to the Endpoint Mapper endpoint' do |
| 93 | + it 'creates a new client bound to the Endpoint Mapper endpoint' do |
93 | 94 | 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}) |
95 | 96 | end |
96 | 97 |
|
97 | 98 | it 'gets host and port information from the Endpoint Mapper' do |
98 | 99 | 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) |
104 | 101 | end |
105 | 102 |
|
106 | | - it 'closes the EPM socket' do |
| 103 | + it 'closes the EPM client socket' do |
107 | 104 | client.connect |
108 | | - expect(epm_tcp_socket).to have_received(:close) |
| 105 | + expect(epm_client).to have_received(:close) |
109 | 106 | end |
110 | 107 |
|
111 | 108 | it 'connects to the endpoint and returns the socket' do |
112 | 109 | 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]) |
114 | 111 | end |
115 | 112 | end |
116 | 113 | end |
|
330 | 327 |
|
331 | 328 | it 'sends an auth3 request' do |
332 | 329 | 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) |
334 | 331 | end |
335 | 332 | end |
336 | 333 | end |
|
0 commit comments