spec/payloads/payload_spec.rb in ronin-exploits-0.2.1 vs spec/payloads/payload_spec.rb in ronin-exploits-0.3.0
- old
+ new
@@ -1,16 +1,19 @@
require 'ronin/payloads/payload'
require 'spec_helper'
require 'helpers/objects'
+require 'controls/behaviors_examples'
describe Payloads::Payload do
before(:each) do
- @payload = load_payload('test')
- @exploit = load_exploit('example')
+ @payload = load_payload('simple')
+ @controler = @payload
end
+ it_should_behave_like "controls behaviors"
+
it "should require a name attribute" do
payload = Payloads::Payload.new
payload.should_not be_valid
payload.name = 'test'
@@ -39,23 +42,10 @@
it "should initialize all parameters by default" do
@payload.params.should_not be_empty
end
- it "should not have any controls by default" do
- @payload.controls.should be_empty
- end
-
- it "should specify what behaviors the payload controls" do
- @payload.controlling :memory_read, :memory_write
-
- @payload.behaviors.should == [
- Vuln::Behavior[:memory_read],
- Vuln::Behavior[:memory_write]
- ]
- end
-
it "should not have an Arch by default" do
@payload.arch.should be_nil
end
it "should set the Arch when called with a name" do
@@ -74,11 +64,11 @@
@payload.os.name.should == 'FreeBSD'
@payload.os.version.should == '7.1'
end
it "should allow for the extending of Helper modules" do
- @payload.instance_eval { helper :shell }.should == true
+ @payload.instance_eval { helper :rpc }.should == true
end
it "should raise an UnknownHelper when extending an unknown helper" do
lambda {
@payload.instance_eval { helper :obvious_not_there }
@@ -87,30 +77,52 @@
it "should not have an exploit by default" do
@payload.exploit.should be_nil
end
- it "should have 'built' and 'unbiult' states" do
+ it "should be 'unbuilt' by default" do
@payload.should_not be_built
+ end
+
+ it "should have 'built' and 'unbuilt' states" do
+ @payload.should_not be_built
@payload.build!
@payload.should be_built
end
- it "should store the built payload in the @payload instance variable" do
+ it "should store the raw payload in the @raw_payload instance variable" do
@payload.build!
- @payload.payload.should == "code.func"
+ @payload.raw_payload.should == "code.func"
end
- it "should return the built payload when calling build!" do
- @payload.build!.should == "code.func"
+ it "should return the raw payload when calling build!" do
+ @payload.build!
+ @payload.raw_payload.should == "code.func"
end
+ it "should pass the raw payload to the block given to build!" do
+ @payload.build! do |payload|
+ payload.should == @payload
+ end
+ end
+
+ it "should respect the arity of blocks passed to build!" do
+ @payload.build do
+ @payload.should be_built
+ end
+ end
+
it "should use parameters in the building of the payload" do
@payload.custom = 'hello'
- @payload.build!.should == "code.hello"
+ @payload.build!
+ @payload.raw_payload.should == "code.hello"
end
+ it "should be 'undeployed' by default" do
+ @payload.should_not be_deployed
+ end
+
it "should have 'deployed' and 'undeployed' states" do
@payload.should_not be_deployed
@payload.build!
@payload.deploy!
@payload.should be_deployed
@@ -120,39 +132,25 @@
@payload.deploy! do |payload|
payload.should == @payload
end
end
- it "should pass the built payload to the exploit when deploying" do
- @payload.exploit = @exploit
-
- @payload.build!
+ it "should pass the deployed payload to the block given to deploy!" do
@payload.deploy! do |payload|
- payload.exploit.payload.should == "code.func"
+ payload.should be_deployed
end
end
- it "should call the exploit when deployed" do
- @payload.exploit = @exploit
-
- @payload.build!
- @payload.deploy! do |payload|
- payload.exploit.should be_built
- payload.exploit.should be_deployed
+ it "should respect the arity of blocks passed to deploy!" do
+ @payload.deploy! do
+ @payload.should be_deployed
end
end
- it "should build and deploy the payload when called" do
- @payload.call
-
- @payload.should be_built
- @payload.should be_deployed
- end
-
it "should return the name and the version when calling to_s" do
- @payload.to_s.should == 'test 0.1'
+ @payload.to_s.should == 'simple 0.1'
end
it "should have a custom inspect method" do
- @payload.inspect.should == '#<Ronin::Payloads::Payload: test 0.1 {:custom=>"func"}>'
+ @payload.inspect.should == '#<Ronin::Payloads::Payload: simple 0.1 {:custom=>"func"}>'
end
end