Path: blob/master/spec/app/controllers/wp_version_spec.rb
486 views
# frozen_string_literal: true12def it_calls_the_formatter_with_the_correct_parameter(version)3it 'calls the formatter with the correct parameter' do4expect(controller.formatter).to receive(:output)5.with('version', hash_including(version: version), 'wp_version')6end7end89describe WPScan::Finders::WpVersionFinders do10subject(:finders) { described_class.new }1112describe 'filter_findings' do13context 'when super returns false (nothing found)' do14before do15expect_any_instance_of(WPScan::Finders::UniqueFinders).to receive(:filter_findings).and_return(false)16end1718its(:filter_findings) { should be false }19end20end21end2223describe WPScan::Controller::WpVersion do24subject(:controller) { described_class.new }25let(:target_url) { 'http://ex.lo/' }26let(:cli_args) { "--url #{target_url}" }2728before do29WPScan::ParsedCli.options = rspec_parsed_options(cli_args)30end3132describe '#cli_options' do33its(:cli_options) { should_not be_empty }34its(:cli_options) { should be_a Array }3536it 'contains to correct options' do37expect(controller.cli_options.map(&:to_sym)).to eq %i[wp_version_all wp_version_detection]38end39end4041describe '#run' do42before do43expect(controller.target).to receive(:wp_version)44.with(45hash_including(46mode: WPScan::ParsedCli.wp_version_detection || WPScan::ParsedCli.detection_mode,47confidence_threshold: WPScan::ParsedCli.wp_version_all ? 0 : 10048)49).and_return(stubbed)50end5152after { controller.run }5354%i[mixed passive aggressive].each do |mode|55context "when --detection-mode #{mode}" do56let(:cli_args) { "#{super()} --detection-mode #{mode}" }5758[WPScan::Model::WpVersion.new('4.0')].each do |version|59context "when version = #{version}" do60let(:stubbed) { version }6162it_calls_the_formatter_with_the_correct_parameter(version)63end64end65end66end6768context 'when --wp-version-all supplied' do69let(:cli_args) { "#{super()} --wp-version-all" }70let(:stubbed) { WPScan::Model::WpVersion.new('3.9.1') }7172it_calls_the_formatter_with_the_correct_parameter(WPScan::Model::WpVersion.new('3.9.1'))73end7475context 'when --wp-version-detection mode supplied' do76let(:cli_args) { "#{super()} --detection-mode mixed --wp-version-detection passive" }77let(:stubbed) { WPScan::Model::WpVersion.new('4.4') }7879it_calls_the_formatter_with_the_correct_parameter(WPScan::Model::WpVersion.new('4.4'))80end81end82end838485