|
| 1 | +#-*- coding:binary -*- |
| 2 | +require 'spec_helper' |
| 3 | + |
| 4 | +require 'msf/core' |
| 5 | +require 'msf/http/jboss' |
| 6 | + |
| 7 | +describe Msf::HTTP::JBoss::DeploymentFileRepository do |
| 8 | + |
| 9 | + subject do |
| 10 | + mod = ::Msf::Exploit.new |
| 11 | + mod.extend Msf::HTTP::JBoss |
| 12 | + mod.send(:initialize) |
| 13 | + mod |
| 14 | + end |
| 15 | + |
| 16 | + let (:base_name) do |
| 17 | + 'dir_blah' |
| 18 | + end |
| 19 | + |
| 20 | + let (:jsp_name) do |
| 21 | + 'file_blah' |
| 22 | + end |
| 23 | + |
| 24 | + let (:content) do |
| 25 | + '<%@page import="java.io.*%>' |
| 26 | + end |
| 27 | + |
| 28 | + before :each do |
| 29 | + allow(subject).to receive(:send_request_cgi) do |
| 30 | + case res_code |
| 31 | + when nil |
| 32 | + res = nil |
| 33 | + when 401 |
| 34 | + res = Rex::Proto::Http::Response.new(401, "Authentication required") |
| 35 | + when 404 |
| 36 | + res = Rex::Proto::Http::Response::E404.new |
| 37 | + when 200 |
| 38 | + res = Rex::Proto::Http::Response::OK.new |
| 39 | + else |
| 40 | + res = Rex::Proto::Http::Response.new |
| 41 | + res.code = res_code |
| 42 | + end |
| 43 | + |
| 44 | + res |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + describe "#upload_file" do |
| 49 | + context 'when server timeouts' do |
| 50 | + let (:res_code) { nil } |
| 51 | + it { expect(subject.upload_file(base_name, jsp_name, content)).to be_nil } |
| 52 | + end |
| 53 | + |
| 54 | + context 'when server returns a 200 response' do |
| 55 | + let (:res_code) { 200 } |
| 56 | + it { expect(subject.upload_file(base_name, jsp_name, content)).to be_kind_of Rex::Proto::Http::Response } |
| 57 | + end |
| 58 | + |
| 59 | + context 'when server returns a 404 response' do |
| 60 | + let (:res_code) { 404 } |
| 61 | + it { expect(subject.upload_file(base_name, jsp_name, content)).to be_kind_of Rex::Proto::Http::Response } |
| 62 | + end |
| 63 | + |
| 64 | + context 'when server returns a 401 response' do |
| 65 | + let (:res_code) { 401 } |
| 66 | + it { expect(subject.upload_file(base_name, jsp_name, content)).to be_kind_of Rex::Proto::Http::Response } |
| 67 | + end |
| 68 | + end |
| 69 | + |
| 70 | + describe "#delete_file" do |
| 71 | + context 'when server timeouts' do |
| 72 | + let (:res_code) { nil } |
| 73 | + it { expect(subject.delete_file(base_name, jsp_name, content)).to be_nil } |
| 74 | + end |
| 75 | + |
| 76 | + context 'when server returns a 200 response' do |
| 77 | + let (:res_code) { 200 } |
| 78 | + it { expect(subject.delete_file(base_name, jsp_name, content)).to be_kind_of Rex::Proto::Http::Response } |
| 79 | + end |
| 80 | + |
| 81 | + context 'when server returns a 404 response' do |
| 82 | + let (:res_code) { 404 } |
| 83 | + it { expect(subject.delete_file(base_name, jsp_name, content)).to be_kind_of Rex::Proto::Http::Response } |
| 84 | + end |
| 85 | + |
| 86 | + context 'when server returns a 401 response' do |
| 87 | + let (:res_code) { 401 } |
| 88 | + it { expect(subject.delete_file(base_name, jsp_name, content)).to be_kind_of Rex::Proto::Http::Response } |
| 89 | + end |
| 90 | + end |
| 91 | +end |
0 commit comments