This commit is contained in:
erwanlr
2013-07-16 17:46:41 +02:00
parent 85b4f987bb
commit 0f8f49f19c
3 changed files with 79 additions and 3 deletions

View File

@@ -45,7 +45,11 @@ class CacheFileStore
def write_entry(key, data_to_store, cache_ttl) def write_entry(key, data_to_store, cache_ttl)
if cache_ttl > 0 if cache_ttl > 0
File.open(get_entry_file_path(key), 'w') do |f| 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 end
end end

View File

@@ -39,8 +39,8 @@ class WpPlugins < WpItems
wp_plugins = WpPlugins.new(wp_target) wp_plugins = WpPlugins.new(wp_target)
if headers if headers
powered_by = headers['X-Powered-By'] powered_by = headers['X-Powered-By'].to_s
wp_super_cache = headers['wp-super-cache'] wp_super_cache = headers['wp-super-cache'].to_s
if matches = /W3 Total Cache\/([0-9.]+)/i.match(powered_by) if matches = /W3 Total Cache\/([0-9.]+)/i.match(powered_by)
wp_plugins.add('w3-total-cache', version: matches[1]) wp_plugins.add('w3-total-cache', version: matches[1])

View File

@@ -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