require 'spec_helper' require 'ronin/exploits/params/port' require 'ronin/exploits/exploit' describe Ronin::Exploits::Params::Port do module TestPortParam class TestExploit < Ronin::Exploits::Exploit include Ronin::Exploits::Params::Port end class TextExploitWithDefaultPort < Ronin::Exploits::Exploit include Ronin::Exploits::Params::Port default_port 123 end end describe ".included" do subject { TestPortParam::TestExploit } it "must include Ronin::Exploits::Metadata::DefaultPort" do expect(subject).to include(Ronin::Exploits::Metadata::DefaultPort) end it "must add a required 'port' param to the exploit class" do expect(subject.params[:port]).to_not be_nil expect(subject.params[:port].type).to be_kind_of(Ronin::Core::Params::Types::Integer) expect(subject.params[:port].required?).to be(true) expect(subject.params[:port].default).to be_kind_of(Proc) expect(subject.params[:port].desc).to eq("Remote port to connect to") end end let(:exploit_class) { TestPortParam::TestExploit } let(:port) { 1337 } subject do exploit_class.new( params: {port: port} ) end describe "#port" do it "must return the port param value" do expect(subject.port).to eq(port) end context "when no port param value is set" do subject do exploit_class.new end it "must require a port value" do expect { subject.validate_params }.to raise_error(Ronin::Core::Params::RequiredParam,"param 'port' requires a value") end end context "when the exploit class defines a default_port" do context "and the port param value is set" do it "must override the default_port value" do expect(subject.port).to eq(port) end end context "but no port param value has been set" do let(:exploit_class) { TestPortParam::TextExploitWithDefaultPort } subject { exploit_class.new } it "must default to the default_port value" do expect(subject.port).to eq(exploit_class.default_port) end end end end end