Merges the db-update branch

This commit is contained in:
erwanlr
2014-09-17 16:12:12 +02:00
40 changed files with 141 additions and 60089 deletions

View File

@@ -1,45 +0,0 @@
# encoding: UTF-8
require 'spec_helper'
describe 'JSON checks' do
after :each do
expect(FileTest.exists?(@file)).to be_truthy
expect { JSON.parse(File.open(@file).read) }.not_to raise_error
end
it 'check plugin_vulns.json for syntax errors' do
@file = PLUGINS_VULNS_FILE
end
it 'check theme_vulns.json for syntax errors' do
@file = THEMES_VULNS_FILE
end
it 'check wp_vulns.json for syntax errors' do
@file = WP_VULNS_FILE
end
end
describe 'JSON content' do
before :all do
@vuln_plugins = json(PLUGINS_VULNS_FILE)
@vuln_themes = json(THEMES_VULNS_FILE)
@vulnerabilities = @vuln_plugins + @vuln_themes
end
after :each do
expect(@result.size).to eq(0), "Items:\n#{@result.join("\n")}"
end
it 'each asset vuln needs a title node' do
@result = []
@vulnerabilities.each do |plugin|
plugin[plugin.keys.inject]['vulnerabilities'].each do |vulnerability|
@result << vulnerability['title'] if vulnerability['title'].nil?
end
end
end
end

View File

@@ -1,74 +0,0 @@
# encoding: UTF-8
require 'spec_helper'
describe GitUpdater do
before :each do
@git_updater = GitUpdater.new
end
describe '#is_installed?' do
after :each do
stub_system_command(@git_updater, /^git .* status/, @stub_value)
expect(@git_updater.is_installed?).to be === @expected
end
it 'should return false if the command is not found' do
@stub_value = 'git: command not found'
@expected = false
end
it 'should return true if the repo is a git one' do
@stub_value = "# On branch master\n# Changed but not updated:"
@expected = true
end
end
describe '#local_revision_number' do
after :each do
stub_system_command(@git_updater, /^git .* log/, @stub_value)
expect(@git_updater.local_revision_number).to be === @expected
end
it 'should return 79c01f3' do
@stub_value = '
commit 79c01f3ed535a8e33876ea091d8217cae7df4028
Author: Moi <tadimm>
Date: Wed Jul 11 23:22:16 2012 +0100'
@expected = '79c01f3'
end
end
describe '#update' do
it 'should do nothing xD' do
stub_system_command(@git_updater, /^git .* pull/, 'Already up-to-date.')
expect(@git_updater.update()).to be === 'Already up-to-date.'
end
end
describe '#has_local_changes?' do
after :each do
stub_system_command(@git_updater, /^git .* diff --exit-code 2>&1/, @stub_value)
expect(@git_updater.has_local_changes?).to be === @expected
end
it 'should return true if there are local changes' do
@stub_value = 'diff'
@expected = true
end
it 'should return false if there are no local changes' do
@stub_value = ''
@expected = false
end
end
describe '#reset_head' do
it 'should reset the local repo' do
stub_system_command(@git_updater, /^git .* reset --hard HEAD/, 'HEAD is now at')
expect(@git_updater.reset_head).to match(/^HEAD is now at/)
end
end
end

View File

@@ -1,86 +0,0 @@
# encoding: UTF-8
require 'spec_helper'
describe SvnUpdater do
before :each do
@svn_updater = SvnUpdater.new
end
describe '#is_installed?' do
after :each do
stub_system_command(@svn_updater, /^svn info/, @stub_value)
expect(@svn_updater.is_installed?).to be === @expected
end
it 'should return false if the svn command is not found' do
@stub_value = 'svn: command not found'
@expected = false
end
it 'should return false if the repository is not manage by svn' do
@stub_value = "svn: '.' is not a working copy"
@expected = false
end
it 'should return true' do
@stub_value = '<?xml version="1.0"?>
<info>
<entry kind="dir" path="." revision="362">
<url>https://wpscan.googlecode.com/svn/trunk</url>
<repository>
<root>https://wpscan.googlecode.com/svn</root>
<uuid>0b0242d5-46e6-2201-410d-bc09fd35266c</uuid>
</repository>
<wc-info>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit revision="362">
<author>author@mail.tld</author>
<date>2012-06-02T06:26:25.309806Z</date>
</commit>
</entry>
</info>'
@expected = true
end
end
describe '#local_revision_number' do
after :each do
stub_system_command(@svn_updater, /^svn info/, @stub_value)
expect(@svn_updater.local_revision_number).to be === @expected
end
it 'should return 399' do
@stub_value = '<?xml version="1.0"?>
<info>
<entry kind="dir" path="." revision="362">
<url>https://wpscan.googlecode.com/svn/trunk</url>
<repository>
<root>https://wpscan.googlecode.com/svn</root>
<uuid>0b0242d5-46e6-2201-410d-bc09fd35266c</uuid>
</repository>
<wc-info>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit revision="362">
<author>author@mail.tld</author>
<date>2012-06-02T06:26:25.309806Z</date>
</commit>
</entry>
</info>'
@expected = '362'
end
end
describe '#update' do
it 'should do nothing xD' do
stub_system_command(@svn_updater, /^svn up/, 'At revision 425.')
expect(@svn_updater.update()).to be === 'At revision 425.'
end
end
end

View File

@@ -1,29 +0,0 @@
# encoding: UTF-8
require 'spec_helper'
describe UpdaterFactory do
describe '#available_updaters_classes' do
after :each do
expect(UpdaterFactory.available_updaters_classes.sort).to be === @expected.sort
end
it 'should return [:GitUpdater, :SvnUpdater]' do
@expected = [:GitUpdater, :SvnUpdater]
end
it 'should return [:TestUpdater, :GitUpdater, :SvnUpdater]' do
class TestUpdater < Updater
end
@expected = [:GitUpdater, :SvnUpdater, :TestUpdater]
end
end
# TODO : Find a way to test that
describe '#get_updater' do
end
end

View File

@@ -1,27 +0,0 @@
# encoding: UTF-8
require 'spec_helper'
describe Updater do
before :all do
class TestUpdater < Updater
end
end
after :all do
Object.send(:remove_const, :TestUpdater)
end
describe 'non implementation of #is_installed?, #has_update? and #update' do
it 'should raise errors' do
test_updater = TestUpdater.new
methods_to_call = [:is_installed?, :update, :local_revision_number]
methods_to_call.each do |method_to_call|
expect { test_updater.send(method_to_call) }.to raise_error(NotImplementedError)
end
end
end
end

View File

@@ -1,5 +0,0 @@
# encoding: UTF-8
require File.expand_path(File.dirname(__FILE__) + '/../../wpstools_helper')
# TODO

View File

@@ -1,5 +0,0 @@
# encoding: UTF-8
require File.expand_path(File.dirname(__FILE__) + '/../../wpstools_helper')
# TODO

View File

@@ -1,6 +1,4 @@
# encoding: UTF-8
require 'spec_helper'
require WPSTOOLS_LIB_DIR + '/wpstools_helper'

View File

@@ -6,7 +6,7 @@ shared_examples 'WpTarget::Malwares' do
let(:malwares_file) { fixtures_dir + '/malwares.txt' }
describe '#malwares_file' do
it "returns the correct file path" do
it 'returns the correct file path' do
expect(WpTarget::Malwares.malwares_file(malwares_file)).to be === malwares_file
end
end
@@ -14,10 +14,12 @@ shared_examples 'WpTarget::Malwares' do
describe '#malwares & #has_malwares' do
after :each do
if @fixture
stub_request_to_fixture(url: wp_target.url, fixture: File.new(fixtures_dir + @fixture))
stub_request_to_fixture(
url: wp_target.url, fixture: File.new(File.join(fixtures_dir, @fixture))
)
end
malwares = wp_target.malwares(@malwares_file_path)
malwares = wp_target.malwares(malwares_file)
expect(malwares.sort).to be === @expected.sort
expect(wp_target.has_malwares?).to be === (@expected.empty? ? false : true)

View File

@@ -1,52 +0,0 @@
# encoding: UTF-8
require 'spec_helper'
describe 'XSD checks' do
after :each do
expect(FileTest.exists?(@file)).to be_truthy
xsd = Nokogiri::XML::Schema(File.read(@xsd))
doc = Nokogiri::XML(File.read(@file))
errors = []
xsd.validate(doc).each do |error|
errors << "#{@file}:#{error.line}: #{error.message}"
end
unless errors.empty?
fail errors.join("\n")
end
end
it 'check wp_versions.xml for syntax errors' do
@file = WP_VERSIONS_FILE
@xsd = WP_VERSIONS_XSD
end
it 'check local_vulnerable_files.xml for syntax errors' do
@file = LOCAL_FILES_FILE
@xsd = LOCAL_FILES_XSD
end
end
describe 'Well formed XML checks' do
after :each do
expect(FileTest.exists?(@file)).to be_truthy
begin
Nokogiri::XML(File.open(@file)) { |config| config.options = Nokogiri::XML::ParseOptions::STRICT }
rescue Nokogiri::XML::SyntaxError => e
fail "#{@file}:#{e.line},#{e.column}: #{e.message}"
end
end
it 'check wp_versions.xml for syntax errors' do
@file = WP_VERSIONS_FILE
end
it 'check local_vulnerable_files.xml for syntax errors' do
@file = LOCAL_FILES_FILE
end
end