From b458b8ad632b459910ec554be7e4bd83d844f44e Mon Sep 17 00:00:00 2001 From: Joe Vennix Date: Sun, 2 Mar 2014 20:23:20 -0600 Subject: [PATCH] Add specs for new methods. --- lib/rex/exploitation/js/network.rb | 4 ++-- spec/lib/rex/exploitation/js/network_spec.rb | 6 +++++ .../lib/rex/proto/http/client_request_spec.rb | 24 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/rex/exploitation/js/network.rb b/lib/rex/exploitation/js/network.rb index e0b211622c..40b735e132 100644 --- a/lib/rex/exploitation/js/network.rb +++ b/lib/rex/exploitation/js/network.rb @@ -57,8 +57,8 @@ class Network # @param [Hash] opts the options hash # @option opts [Boolean] :obfuscate toggles js obfuscation. defaults to true. - # @return [String] javascript code to perform a POST of the specified params - def self.ajax_post(opts={}) + # @return [String] javascript code to build and submit a form that POSTs the params + def self.form_post(opts={}) should_obfuscate = opts.fetch(:obfuscate, true) js = ::File.read(::File.join(Msf::Config.data_directory, "js", "network", "form_post.js")) diff --git a/spec/lib/rex/exploitation/js/network_spec.rb b/spec/lib/rex/exploitation/js/network_spec.rb index 9f74c6bf43..c4b48e53ee 100644 --- a/spec/lib/rex/exploitation/js/network_spec.rb +++ b/spec/lib/rex/exploitation/js/network_spec.rb @@ -16,7 +16,13 @@ describe Rex::Exploitation::Js::Network do js = Rex::Exploitation::Js::Network.ajax_post js.should =~ /function postInfo/ end + end + context ".form_post" do + it "should load the postForm javascript" do + js = Rex::Exploitation::Js::Network.form_post + js.should =~ /function postForm/ + end end end diff --git a/spec/lib/rex/proto/http/client_request_spec.rb b/spec/lib/rex/proto/http/client_request_spec.rb index c76a9d2dee..e80883a72f 100644 --- a/spec/lib/rex/proto/http/client_request_spec.rb +++ b/spec/lib/rex/proto/http/client_request_spec.rb @@ -216,6 +216,14 @@ describe Rex::Proto::Http::ClientRequest do str.should include("bar=baz") str.should include("frobnicate=the froozle?") end + + describe "#serialize_get_params" do + subject(:serialize_get_params) { client_request.serialize_get_params } + + it { should include("foo[]=bar") } + it { should include("bar=baz") } + it { should include("frobnicate=the froozle?") } + end end context "with 'encode_params'" do @@ -227,6 +235,14 @@ describe Rex::Proto::Http::ClientRequest do str.should include("bar=baz") str.should include("frobnicate=the%20froozle%3f") end + + describe "#serialize_get_params" do + subject(:serialize_get_params) { client_request.serialize_get_params } + + it { should include("foo%5b%5d=bar") } + it { should include("bar=baz") } + it { should include("frobnicate=the%20froozle%3f") } + end end context "and 'uri_encode_mode' = hex-all" do @@ -237,6 +253,14 @@ describe Rex::Proto::Http::ClientRequest do str.should include("%62%61%72=%62%61%7a") str.should include("%66%72%6f%62%6e%69%63%61%74%65=%74%68%65%20%66%72%6f%6f%7a%6c%65%3f") end + + describe "#serialize_get_params" do + subject(:serialize_get_params) { client_request.serialize_get_params } + + it { should include("%66%6f%6f%5b%5d=%62%61%72") } + it { should include("%62%61%72=%62%61%7a") } + it { should include("%66%72%6f%62%6e%69%63%61%74%65=%74%68%65%20%66%72%6f%6f%7a%6c%65%3f") } + end end describe "#to_s" do