|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative '../../../../../spec_helper' |
| 4 | +require 'wpxf/modules' |
| 5 | + |
| 6 | +describe Wpxf::Auxiliary::LoadScriptsDos do |
| 7 | + let(:subject) { described_class.new } |
| 8 | + let(:wordpress_and_online?) { true } |
| 9 | + |
| 10 | + before :each, 'setup subject' do |
| 11 | + allow(subject).to receive(:wordpress_and_online?).and_return(wordpress_and_online?) |
| 12 | + allow(subject).to receive(:queue_request).and_call_original |
| 13 | + allow(subject).to receive(:execute_queued_requests).and_call_original |
| 14 | + allow(subject).to receive(:emit_error) |
| 15 | + allow(subject).to receive(:emit_warning) |
| 16 | + allow(subject).to receive(:emit_success) |
| 17 | + |
| 18 | + subject.set_option_value('host', '127.0.0.1') |
| 19 | + subject.set_option_value('max_requests', 50) |
| 20 | + subject.set_option_value('check_wordpress_and_online', false) |
| 21 | + end |
| 22 | + |
| 23 | + context 'if the target is running any version of WordPress' do |
| 24 | + let(:wordpress_and_online?) { true } |
| 25 | + |
| 26 | + it 'should consider it vulnerable' do |
| 27 | + expect(subject.check).to eql :vulnerable |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + context 'if the target does not appear to be running WordPress' do |
| 32 | + let(:wordpress_and_online?) { false } |
| 33 | + |
| 34 | + it 'should consider the vulnerability status to be unknown' do |
| 35 | + expect(subject.check).to eql :unknown |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + it 'should queue and execute the specified numbers of requests' do |
| 40 | + subject.run |
| 41 | + expect(subject).to have_received(:queue_request) |
| 42 | + .exactly(50).times |
| 43 | + |
| 44 | + expect(subject).to have_received(:execute_queued_requests) |
| 45 | + expect(subject.complete_requests).to eql 50 |
| 46 | + end |
| 47 | + |
| 48 | + it 'should emit a process update every 10 requests that are executed' do |
| 49 | + subject.run |
| 50 | + expect(subject).to have_received(:emit_warning).exactly(5).times |
| 51 | + end |
| 52 | + |
| 53 | + context 'if the target appears to be online after executing the requests' do |
| 54 | + let(:wordpress_and_online?) { true } |
| 55 | + |
| 56 | + it 'should emit an error' do |
| 57 | + subject.run |
| 58 | + expect(subject).to have_received(:emit_error) |
| 59 | + .with("FAILED: #{subject.full_uri} appears to still be online") |
| 60 | + .exactly(1).times |
| 61 | + end |
| 62 | + |
| 63 | + it 'should fail the module execution' do |
| 64 | + expect(subject.run).to be false |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + context 'if the target appears to be offline after executing the requests' do |
| 69 | + let(:wordpress_and_online?) { false } |
| 70 | + |
| 71 | + it 'should emit a success message' do |
| 72 | + subject.run |
| 73 | + expect(subject).to have_received(:emit_success) |
| 74 | + .with("#{subject.full_uri} appears to be down") |
| 75 | + .exactly(1).times |
| 76 | + end |
| 77 | + |
| 78 | + it 'should successfully complete the module execution' do |
| 79 | + expect(subject.run).to be true |
| 80 | + end |
| 81 | + end |
| 82 | +end |
0 commit comments