require 'ronin/exploits/target' require 'spec_helper' describe Exploits::Target do before(:each) do @target = Exploits::Target.new( :data => {:var => 1, :test => 'hello'} ) end it "should not have an Arch by default" do @target.arch.should be_nil end it "should set the Arch when called with a name" do @target.arch :i686 @target.arch.name.should == 'i686' @target.arch.endian == 'little' @target.arch.address_length == 4 end it "should not have an OS by default" do @target.os.should be_nil end it "should set the OS when called with arguments" do @target.os(:name => 'FreeBSD', :version => '7.1') @target.os.name.should == 'FreeBSD' @target.os.version.should == '7.1' end it "should not have a product by default" do @target.product.should be_nil end it "should set the product when called with arguments" do @target.product(:name => 'Apache', :version => '1.3.3.7') @target.product.name.should == 'Apache' @target.product.version.should == '1.3.3.7' end it "should contain target data" do @target.data[:var].should == 1 @target.data[:test].should == 'hello' end it "should provide Hash like access to target data" do @target[:var].should == 1 @target[:test].should == 'hello' end it "should be able to set data like a Hash" do @target[:var] = 2 @target[:var].should == 2 end it "should provide OStruct like access to target data" do @target.var.should == 1 @target.test.should == 'hello' end it "should be able to set data like an OStruct" do @target.var = 2 @target.var.should == 2 end it "should be able to serialize and deserialize it's target data" do @target.save! target = Exploits::Target.get(@target.id) target.data[:var].should == 1 target.data[:test].should == 'hello' end it "should not raise TargetDataMissing when setting new data" do lambda { @target.bla = 'yes' }.should_not raise_error(Exploits::TargetDataMissing) @target.bla.should == 'yes' end it "should raise TargetDataMissing when accessing non-existant data" do lambda { @target.bla }.should raise_error(Exploits::TargetDataMissing) end end