Path: blob/master/spec/app/controllers/enumeration_spec.rb
486 views
# frozen_string_literal: true12describe WPScan::Controller::Enumeration do3subject(:controller) { described_class.new }4let(:target_url) { 'http://wp.lab/' }5let(:cli_args) { "--url #{target_url}" }67before do8## For the --passwords options9allow_any_instance_of(OptParseValidator::OptPath).to receive(:check_file)1011WPScan::ParsedCli.options = rspec_parsed_options(cli_args)12end1314describe '#enum_message' do15after { expect(controller.enum_message(type, detection_mode)).to eql @expected }1617context 'when type argument is incorrect' do18let(:type) { 'spec' }19let(:detection_mode) { :mixed }2021it 'returns nil' do22@expected = nil23end24end2526%w[plugins themes].each do |t|27context "type = #{t}" do28let(:type) { t }29let(:detection_mode) { :mixed }3031context 'when vulnerable' do32let(:cli_args) { "#{super()} -e v#{type[0]}" }3334it 'returns the expected string' do35@expected = "Enumerating Vulnerable #{type.capitalize} (via Passive and Aggressive Methods)"36end37end3839context 'when all' do40let(:cli_args) { "#{super()} -e a#{type[0]}" }41let(:detection_mode) { :passive }4243it 'returns the expected string' do44@expected = "Enumerating All #{type.capitalize} (via Passive Methods)"45end46end4748context 'when most popular' do49let(:cli_args) { "#{super()} -e #{type[0]}" }50let(:detection_mode) { :aggressive }5152it 'returns the expected string' do53@expected = "Enumerating Most Popular #{type.capitalize} (via Aggressive Methods)"54end55end56end57end58end5960describe '#default_opts' do61context 'when no --enumerate' do62it 'contains the correct version_detection' do63expect(controller.default_opts('plugins')[:version_detection]).to include(mode: :mixed)64end65end66end6768describe '#cli_options' do69it 'contains the correct options' do70expect(controller.cli_options.map(&:to_sym)).to eql(71%i[enumerate exclude_content_based72plugins_list plugins_detection plugins_version_all plugins_version_detection plugins_threshold73themes_list themes_detection themes_version_all themes_version_detection themes_threshold74timthumbs_list timthumbs_detection75config_backups_list config_backups_detection76db_exports_list db_exports_detection77medias_detection78users_list users_detection exclude_usernames]79)80end81end8283describe '#enum_users' do84before { expect(controller.formatter).to receive(:output).twice }85after { controller.enum_users }8687context 'when --enumerate has been supplied' do88let(:cli_args) { "#{super()} -e u1-10" }8990it 'calls the target.users with the correct range' do91expect(controller.target).to receive(:users).with(hash_including(range: (1..10)))92end93end9495context 'when --passwords supplied but no --username or --usernames' do96let(:cli_args) { "#{super()} --passwords some-file.txt" }9798it 'calls the target.users with the default range' do99expect(controller.target).to receive(:users).with(hash_including(range: (1..10)))100end101end102end103104describe '#run' do105context 'when no :enumerate' do106before do107expect(controller).to receive(:enum_plugins)108expect(controller).to receive(:enum_config_backups)109110expect(WPScan::ParsedCli.plugins_detection).to eql :passive111end112113it 'calls enum_plugins and enum_config_backups' do114controller.run115end116117context 'when --passwords supplied but no --username or --usernames' do118let(:cli_args) { "#{super()} --passwords some-file.txt" }119120it 'calls the enum_users' do121expect(controller).to receive(:enum_users)122controller.run123end124end125end126127context 'when :enumerate' do128after { controller.run }129130context 'when no option supplied' do131let(:cli_args) { "#{super()} -e" }132133it 'calls the correct enum methods' do134%i[plugins themes timthumbs config_backups db_exports users medias].each do |option|135expect(controller).to receive("enum_#{option}".to_sym)136end137end138end139140%i[p ap vp].each do |option|141context "when #{option}" do142let(:cli_args) { "#{super()} -e #{option}" }143144it 'calls the #enum_plugins' do145expect(controller).to receive(:enum_plugins)146end147end148end149150%i[t at vt].each do |option|151context option.to_s do152let(:cli_args) { "#{super()} -e #{option}" }153154it 'calls the #enum_themes' do155expect(controller).to receive(:enum_themes)156end157end158end159160{ timthumbs: 'tt', config_backups: 'cb', db_exports: 'dbe', medias: 'm', users: 'u' }.each do |option, shortname|161context "when #{option}" do162let(:cli_args) { "#{super()} -e #{shortname}" }163164it "calls the ##{option}" do165expect(controller).to receive("enum_#{option}".to_sym)166end167end168end169end170end171end172173174