require 'spec_helper' require 'ronin/exploits/mixins/remote_udp' require 'ronin/exploits/exploit' describe Ronin::Exploits::Mixins::RemoteUDP do module TestMixinsRemoteUDP class TestExploit < Ronin::Exploits::Exploit include Ronin::Exploits::Mixins::RemoteUDP end end let(:test_class) { TestMixinsRemoteUDP::TestExploit } describe ".included" do subject { test_class } it "must include Ronin::Support::Network::UDP::Mixin" do expect(subject).to include(Ronin::Support::Network::UDP::Mixin) end it "must include Ronin::Exploits::Params::Host" do expect(subject).to include(Ronin::Exploits::Params::Host) end it "must include Ronin::Exploits::Params::Port" do expect(subject).to include(Ronin::Exploits::Params::Port) end it "must include Ronin::Exploits::Params::BindHost" do expect(subject).to include(Ronin::Exploits::Params::BindHost) end it "must include Ronin::Exploits::Params::BindPort" do expect(subject).to include(Ronin::Exploits::Params::BindPort) end end let(:host) { 'example.com' } let(:port) { 1337 } let(:bind_host) { 'localhost' } let(:bind_port) { 9000 } subject do test_class.new( params: { host: host, port: port, bind_host: bind_host, bind_port: bind_port } ) end describe "#udp_open?" do context "when given no arguments" do it "must call Ronin::Support::Network::UDP.open? with #host, #port, bind_host: #bind_host, bind_port: #bind_port" do expect(Ronin::Support::Network::UDP).to receive(:open?).with( subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) subject.udp_open? end context "when debug messages are enabled" do before { Ronin::Support::CLI::Printing.debug = true } it "must print a debugging message" do allow(Ronin::Support::Network::UDP).to receive(:open?).with( subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) expect(subject).to receive(:print_debug).with( "Testing if #{subject.host}:#{subject.port} is open ..." ) subject.udp_open? end after { Ronin::Support::CLI::Printing.debug = false } end end end describe "#udp_connect" do context "when given no arguments" do it "must call Ronin::Support::Network::UDP.connect with #host, #port, bind_host: #bind_host, bind_port: #bind_port" do expect(Ronin::Support::Network::UDP).to receive(:connect).with( subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) subject.udp_connect end context "when debug messages are enabled" do before { Ronin::Support::CLI::Printing.debug = true } it "must print a debugging message" do allow(Ronin::Support::Network::UDP).to receive(:connect).with( subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) expect(subject).to receive(:print_debug).with( "Connecting to #{subject.host}:#{subject.port} ..." ) subject.udp_connect end after { Ronin::Support::CLI::Printing.debug = false } end end end describe "#udp_connect_and_send" do context "when given one argument" do let(:data) { 'foo' } it "must call Ronin::Support::Network::UDP.connect_and_send with data, #host, #port, bind_host: #bind_host, bind_port: #bind_port" do expect(Ronin::Support::Network::UDP).to receive(:connect_and_send).with( data, subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) subject.udp_connect_and_send(data) end context "when debug messages are enabled" do before { Ronin::Support::CLI::Printing.debug = true } it "must print a debugging message" do allow(Ronin::Support::Network::UDP).to receive(:connect_and_send).with( data, subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) expect(subject).to receive(:print_debug).with( "Connecting to #{subject.host}:#{subject.port} and sending #{data.inspect} ..." ) subject.udp_connect_and_send(data) end after { Ronin::Support::CLI::Printing.debug = false } end end end describe "#udp_banner" do context "when given no arguments" do it "must call Ronin::Support::Network::UDP.banner with #host, #port, bind_host: #bind_host, bind_port: #bind_port" do expect(Ronin::Support::Network::UDP).to receive(:banner).with( subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) subject.udp_banner end context "when debug messages are enabled" do before { Ronin::Support::CLI::Printing.debug = true } it "must print a debugging message" do allow(Ronin::Support::Network::UDP).to receive(:banner).with( subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) expect(subject).to receive(:print_debug).with( "Fetching the banner for #{subject.host}:#{subject.port} ..." ) subject.udp_banner end after { Ronin::Support::CLI::Printing.debug = false } end end end describe "#udp_send" do context "when given one argument" do let(:data) { 'foo' } it "must call Ronin::Support::Network::UDP.send with data, #host, #port, bind_host: #bind_host, bind_port: #bind_port" do expect(Ronin::Support::Network::UDP).to receive(:send).with( data, subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) subject.udp_send(data) end context "when debug messages are enabled" do before { Ronin::Support::CLI::Printing.debug = true } it "must print a debugging message" do allow(Ronin::Support::Network::UDP).to receive(:send).with( data, subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) expect(subject).to receive(:print_debug).with( "Sending #{data.inspect} to #{subject.host}:#{subject.port} ..." ) subject.udp_send(data) end after { Ronin::Support::CLI::Printing.debug = false } end end end end