diff --git a/lib/common/collections/wp_users/detectable.rb b/lib/common/collections/wp_users/detectable.rb index 8eca7466..929b9b0e 100755 --- a/lib/common/collections/wp_users/detectable.rb +++ b/lib/common/collections/wp_users/detectable.rb @@ -3,10 +3,23 @@ class WpUsers < WpItems module Detectable + # @return [ Hash ] def request_params; {} end - # options: - # :range - default 1..10 + # No passive detection + # + # @return [ WpUsers ] + def passive_detection(wp_target, options = {}) + new + end + + protected + + # @param [ WpTarget ] wp_target + # @param [ Hash ] options + # @option options [ Range ] :range ((1..10)) + # + # @return [ Array ] def targets_items(wp_target, options = {}) range = options[:range] || (1..10) targets = [] @@ -17,11 +30,5 @@ class WpUsers < WpItems targets end - # No passive detection - # @return [ WpUsers ] - def passive_detection(wp_target, options = {}) - new - end - end end diff --git a/lib/common/models/wp_user.rb b/lib/common/models/wp_user.rb index 44e8fe34..6e549622 100755 --- a/lib/common/models/wp_user.rb +++ b/lib/common/models/wp_user.rb @@ -18,6 +18,14 @@ class WpUser < WpItem end end + # @return [ String ] + def to_s + s = "#{id}" + s += " | #{login}" if login + s += " | #{display_name}" if display_name + s + end + # @param [ WpUser ] other def <=>(other) id <=> other.id diff --git a/spec/lib/common/collections/wp_users/detectable_spec.rb b/spec/lib/common/collections/wp_users/detectable_spec.rb new file mode 100644 index 00000000..c3581f92 --- /dev/null +++ b/spec/lib/common/collections/wp_users/detectable_spec.rb @@ -0,0 +1,59 @@ +# encoding: UTF-8 + +require 'spec_helper' +require WPSCAN_LIB_DIR + '/wp_target' + +describe 'WpUsers::Detectable' do + subject(:wp_users) { WpUsers } + let(:wp_content_dir) { 'wp-content' } + let(:wp_plugins_dir) { wp_content_dir + '/plugins' } + let(:wp_target) { WpTarget.new(url, wp_content_dir: wp_content_dir, wp_plugins_dir: wp_plugins_dir) } + let(:url) { 'http://example.com/' } + let(:uri) { URI.parse(url) } + + def create_from_range(range) + result = [] + + range.each do |current_id| + result << WpUser.new(uri, id: current_id) + end + result + end + + describe '::request_params' do + it 'return an empty Hash' do + subject.request_params.should === {} + end + end + + describe '::passive_detection' do + it 'return an empty WpUsers' do + subject.passive_detection(wp_target).should == subject.new + end + end + + describe '::targets_items' do + after do + targets = subject.send(:targets_items, wp_target, options) + + targets.should == @expected + end + + context 'when no :range' do + let(:options) { {} } + + it 'returns Array with id from 1 to 10' do + @expected = create_from_range((1..10)) + end + end + + context 'when :range' do + let(:options) { { range: (1..2) } } + + it 'returns Array with id from 1 to 2' do + @expected = create_from_range((1..2)) + end + end + end + +end