From a48d6053abf44ca0c4ea16aaa0f08f4f2f8328ef Mon Sep 17 00:00:00 2001 From: Vincent Herbulot Date: Wed, 1 Oct 2014 11:57:01 +0200 Subject: [PATCH] Added spec for jboss/deployment_file_repository --- .../jboss/deployment_file_repository_spec.rb | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 spec/lib/msf/http/jboss/deployment_file_repository_spec.rb diff --git a/spec/lib/msf/http/jboss/deployment_file_repository_spec.rb b/spec/lib/msf/http/jboss/deployment_file_repository_spec.rb new file mode 100644 index 0000000000..234e5b0f06 --- /dev/null +++ b/spec/lib/msf/http/jboss/deployment_file_repository_spec.rb @@ -0,0 +1,91 @@ +#-*- coding:binary -*- +require 'spec_helper' + +require 'msf/core' +require 'msf/http/jboss' + +describe Msf::HTTP::JBoss::DeploymentFileRepository do + + subject do + mod = ::Msf::Exploit.new + mod.extend Msf::HTTP::JBoss + mod.send(:initialize) + mod + end + + let (:base_name) do + 'dir_blah' + end + + let (:jsp_name) do + 'file_blah' + end + + let (:content) do + '<%@page import="java.io.*%>' + end + + before :each do + allow(subject).to receive(:send_request_cgi) do + case res_code + when nil + res = nil + when 401 + res = Rex::Proto::Http::Response.new(401, "Authentication required") + when 404 + res = Rex::Proto::Http::Response::E404.new + when 200 + res = Rex::Proto::Http::Response::OK.new + else + res = Rex::Proto::Http::Response.new + res.code = res_code + end + + res + end + end + + describe "#upload_file" do + context 'when server timeouts' do + let (:res_code) { nil } + it { expect(subject.upload_file(base_name, jsp_name, content)).to be_nil } + end + + context 'when server returns a 200 response' do + let (:res_code) { 200 } + it { expect(subject.upload_file(base_name, jsp_name, content)).to be_kind_of Rex::Proto::Http::Response } + end + + context 'when server returns a 404 response' do + let (:res_code) { 404 } + it { expect(subject.upload_file(base_name, jsp_name, content)).to be_kind_of Rex::Proto::Http::Response } + end + + context 'when server returns a 401 response' do + let (:res_code) { 401 } + it { expect(subject.upload_file(base_name, jsp_name, content)).to be_kind_of Rex::Proto::Http::Response } + end + end + + describe "#delete_file" do + context 'when server timeouts' do + let (:res_code) { nil } + it { expect(subject.delete_file(base_name, jsp_name, content)).to be_nil } + end + + context 'when server returns a 200 response' do + let (:res_code) { 200 } + it { expect(subject.delete_file(base_name, jsp_name, content)).to be_kind_of Rex::Proto::Http::Response } + end + + context 'when server returns a 404 response' do + let (:res_code) { 404 } + it { expect(subject.delete_file(base_name, jsp_name, content)).to be_kind_of Rex::Proto::Http::Response } + end + + context 'when server returns a 401 response' do + let (:res_code) { 401 } + it { expect(subject.delete_file(base_name, jsp_name, content)).to be_kind_of Rex::Proto::Http::Response } + end + end +end