Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/lib/rex/proto/thrift/client_spec.rb
Views: 11788
# -*- coding: binary -*-1require 'spec_helper'2require 'rex/text'34RSpec.describe Rex::Proto::Thrift::Client do5let(:target_host) { '127.0.0.1' }6let(:target_port) { 1234 }7subject(:instance) { described_class.new(target_host, target_port) }89it { should respond_to :host }10it { should respond_to :port }11it { should respond_to :ssl }12it { should respond_to :timeout }1314it 'should default SSL to false' do15expect(instance.ssl).to eq false16end1718describe '#call' do19let(:method_name) { Rex::Text.rand_text_alphanumeric(10) }2021it 'calls the function and returns the result' do22allow(Rex::Proto::Thrift::ThriftHeader).to receive(:new).and_call_original23expect(subject).to receive(:send_raw).with("\x80\x01\x00\x01\x00\x00\x00\n#{method_name}\x00\x00\x00\x00\x00".b).and_return(nil)24expect(subject).to receive(:recv_raw).with(timeout: subject.timeout).and_return("\x80\x01\x00\x02\x00\x00\x00\n#{method_name}\x00\x00\x00\x00\x00".b)25result = instance.call(method_name, { data_type: Rex::Proto::Thrift::ThriftDataType::T_STOP })26expect(Rex::Proto::Thrift::ThriftHeader).to have_received(:new).with(method_name: method_name, message_type: Rex::Proto::Thrift::ThriftMessageType::CALL)27expect(result).to be_a Array28expect(result[0]).to eq({ data_type: Rex::Proto::Thrift::ThriftDataType::T_STOP })29end3031it 'raises UnexpectedReplyError on an unexpected message type' do32expect(subject).to receive(:send_raw).with("\x80\x01\x00\x01\x00\x00\x00\n#{method_name}\x00\x00\x00\x00\x00".b).and_return(nil)33expect(subject).to receive(:recv_raw).with(timeout: subject.timeout).and_return("\x80\x01\x00\x01\x00\x00\x00\n#{method_name}\x00\x00\x00\x00\x00".b)34expect {35instance.call(method_name, { data_type: Rex::Proto::Thrift::ThriftDataType::T_STOP })36}.to raise_error(Rex::Proto::Thrift::Error::UnexpectedReplyError)37end3839it 'raises UnexpectedReplyError on an unexpected method name' do40expect(subject).to receive(:send_raw).with("\x80\x01\x00\x01\x00\x00\x00\n#{method_name}\x00\x00\x00\x00\x00".b).and_return(nil)41expect(subject).to receive(:recv_raw).with(timeout: subject.timeout).and_return("\x80\x01\x00\x02\x00\x00\x00\n#{method_name.swapcase}\x00\x00\x00\x00\x00".b)42expect {43instance.call(method_name, { data_type: Rex::Proto::Thrift::ThriftDataType::T_STOP })44}.to raise_error(Rex::Proto::Thrift::Error::UnexpectedReplyError)45end46end4748describe '#connect' do49it 'creates a rex socket' do50expect(Rex::Socket::Tcp).to receive(:create)51instance.connect52end53end54end555657