diff --git a/lib/common/cache_file_store.rb b/lib/common/cache_file_store.rb index 604e1257..a9df5d5b 100644 --- a/lib/common/cache_file_store.rb +++ b/lib/common/cache_file_store.rb @@ -45,7 +45,11 @@ class CacheFileStore def write_entry(key, data_to_store, cache_ttl) if cache_ttl > 0 File.open(get_entry_file_path(key), 'w') do |f| - f.write(@serializer.dump(data_to_store)) + begin + f.write(@serializer.dump(data_to_store)) + rescue + nil # spec fix for "can't dump hash with default proc" when stub_request with response headers + end end end end diff --git a/lib/common/collections/wp_plugins/detectable.rb b/lib/common/collections/wp_plugins/detectable.rb index 5c3db5ca..1c8a5df2 100644 --- a/lib/common/collections/wp_plugins/detectable.rb +++ b/lib/common/collections/wp_plugins/detectable.rb @@ -39,8 +39,8 @@ class WpPlugins < WpItems wp_plugins = WpPlugins.new(wp_target) if headers - powered_by = headers['X-Powered-By'] - wp_super_cache = headers['wp-super-cache'] + powered_by = headers['X-Powered-By'].to_s + wp_super_cache = headers['wp-super-cache'].to_s if matches = /W3 Total Cache\/([0-9.]+)/i.match(powered_by) wp_plugins.add('w3-total-cache', version: matches[1]) diff --git a/spec/lib/common/collections/wp_plugins/detectable_spec.rb b/spec/lib/common/collections/wp_plugins/detectable_spec.rb new file mode 100644 index 00000000..9d7bf2fe --- /dev/null +++ b/spec/lib/common/collections/wp_plugins/detectable_spec.rb @@ -0,0 +1,72 @@ +# encoding: UTF-8 + +require 'spec_helper' +require WPSCAN_LIB_DIR + '/wp_target' + +describe 'WpPlugins::Detectable' do + subject(:wp_plugins) { WpPlugins } + 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) } + + describe '::from_header' do + context 'when no header' do + it 'returns an empty WpPlugins' do + stub_request(:get, url).to_return(status: 200) + subject.send(:from_header, wp_target).should == subject.new + end + end + + context 'when headers' do + let(:headers) { { } } + let(:expected) { subject.new(wp_target) } + + after :each do + stub_request(:get, url).to_return(status: 200, headers: headers, body: '') + subject.send(:from_header, wp_target).should == expected + end + + context 'when w3-total-cache detected' do + it 'returns the w3-total-cache' do + headers['X-Powered-BY'] = 'W3 Total Cache/0.9' + expected.add('w3-total-cache', version: '0.9') + end + end + + context 'when wp-super-cache detected' do + it 'returns the wp-super-cache' do + headers['WP-Super-Cache'] = 'Served supercache file from PHP' + expected.add('wp-super-cache') + end + end + + context 'when a header key with mutiple values' do + let(:headers) { { 'X-Powered-BY' => ['PHP/5.4.9', 'ASP.NET'] } } + + context 'when no cache plugin' do + it 'returns an empty WpPlugins' do + # Handled + end + end + + context 'when a cache plugin' do + it 'returns the correct plugin' do + headers['X-Powered-BY'] << 'W3 Total Cache/0.9.2.5' + + expected.add('w3-total-cache', version: '0.9.2.5') + end + end + end + end + end + + describe '::from_content' do + # TODO + end + + describe '::passive_detection' do + # TODO + end +end