require 'spec_helper' require 'ronin/exploits/params/filename' require 'ronin/exploits/exploit' describe Ronin::Exploits::Params::Filename do module TestFilenameParam class TestExploit < Ronin::Exploits::Exploit include Ronin::Exploits::Params::Filename end class TextExploitWithDefaultFilename < Ronin::Exploits::Exploit include Ronin::Exploits::Params::Filename default_filename 'exploit.docx' end end describe ".included" do subject { TestFilenameParam::TestExploit } it "must include Ronin::Exploits::Metadata::DefaultFilename" do expect(subject).to include(Ronin::Exploits::Metadata::DefaultFilename) end it "must add a required 'filename' param to the exploit class" do expect(subject.params[:filename]).to_not be_nil expect(subject.params[:filename].type).to be_kind_of(Ronin::Core::Params::Types::String) expect(subject.params[:filename].required?).to be(true) expect(subject.params[:filename].default).to be_kind_of(Proc) expect(subject.params[:filename].desc).to eq("The filename for the exploit") end end let(:exploit_class) { TestFilenameParam::TestExploit } let(:filename) { 'my-file.txt' } subject do exploit_class.new( params: {filename: filename} ) end describe "#filename" do it "must return the filename param value" do expect(subject.filename).to eq(filename) end context "when no filename param value is set" do subject do exploit_class.new end it "must require a filename value" do expect { subject.validate_params }.to raise_error(Ronin::Core::Params::RequiredParam,"param 'filename' requires a value") end end context "when the exploit class defines a default_filename" do context "and the filename param value is set" do it "must override the default_filename value" do expect(subject.filename).to eq(filename) end end context "but no filename param value has been set" do let(:exploit_class) { TestFilenameParam::TextExploitWithDefaultFilename } subject { exploit_class.new } it "must default to the default_filename value" do expect(subject.filename).to eq(exploit_class.default_filename) end end end end end