diff --git a/spec/lib/common/models/wp_item_spec.rb b/spec/lib/common/models/wp_item_spec.rb index f4779e54..2c96fed5 100644 --- a/spec/lib/common/models/wp_item_spec.rb +++ b/spec/lib/common/models/wp_item_spec.rb @@ -12,9 +12,9 @@ describe WpItem do end it_behaves_like 'WpItem::Versionable' it_behaves_like 'WpItem::Vulnerable' do - let(:vulns_file) { MODELS_FIXTURES + '/wp_item/vulnerable/vulns_items.xml' } + let(:vulns_file) { MODELS_FIXTURES + '/wp_item/vulnerable/items_vulns.xml' } let(:vulns_xpath) { "//item[@name='neo']/vulnerability" } - let(:expected_vulns) { Vulnerabilities.new << Vulnerability.new("I'm the one", 'XSS', ["http://ref1.com"]) } + let(:expected_vulns) { Vulnerabilities.new << Vulnerability.new("I'm the one", 'XSS', ['http://ref1.com']) } end subject(:wp_item) { WpItem.new(uri, options) } diff --git a/spec/lib/common/models/wp_plugin_spec.rb b/spec/lib/common/models/wp_plugin_spec.rb index 7afe2ea0..f67165d9 100644 --- a/spec/lib/common/models/wp_plugin_spec.rb +++ b/spec/lib/common/models/wp_plugin_spec.rb @@ -3,6 +3,13 @@ require 'spec_helper' describe WpPlugin do + it_behaves_like 'WpPlugin::Vulnerable' + it_behaves_like 'WpItem::Vulnerable' do + let(:options) { { name: 'white-rabbit' } } + let(:vulns_file) { MODELS_FIXTURES + '/wp_plugin/vulnerable/plugins_vulns.xml' } + let(:expected_vulns) { Vulnerabilities.new << Vulnerability.new('Follow me!', 'REDIRECT', ['http://ref2.com']) } + end + subject(:wp_plugin) { WpPlugin.new(uri, options) } let(:uri) { URI.parse('http://example.com') } let(:options) { { name: 'plugin-name' } } diff --git a/spec/samples/common/models/wp_item/vulnerable/vulns_items.xml b/spec/samples/common/models/wp_item/vulnerable/items_vulns.xml similarity index 100% rename from spec/samples/common/models/wp_item/vulnerable/vulns_items.xml rename to spec/samples/common/models/wp_item/vulnerable/items_vulns.xml diff --git a/spec/samples/common/models/wp_plugin/vulnerable/plugins_vulns.xml b/spec/samples/common/models/wp_plugin/vulnerable/plugins_vulns.xml new file mode 100644 index 00000000..7a6851e5 --- /dev/null +++ b/spec/samples/common/models/wp_plugin/vulnerable/plugins_vulns.xml @@ -0,0 +1,19 @@ + + + + + + I should not appear in the results + http://ref1.com + RCE + + + + + + Follow me! + http://ref2.com + REDIRECT + + + diff --git a/spec/shared_examples/wp_item_vulnerable.rb b/spec/shared_examples/wp_item_vulnerable.rb index 29fba77d..0dbf17f8 100644 --- a/spec/shared_examples/wp_item_vulnerable.rb +++ b/spec/shared_examples/wp_item_vulnerable.rb @@ -2,17 +2,19 @@ shared_examples 'WpItem::Vulnerable' do - # 3 variables have to be set in the described class or subject: - # let(:vulns_file) { } - # let(:vulns_xpath) { } - # let(:expected_vulns) { } The expected Vulnerabilities when using vulns_file and vulns_xpath + # 2 variables have to be set in the described class or subject: + # let(:vulns_file) { } + # let(:expected_vulns) { } The expected Vulnerabilities when using vulns_file and vulns_xpath + # + # 1 variable is optional, used if supplied, otherwise subject.vulns_xpath is used + # let(:vulns_xpath) { } describe '#vulnerabilities' do let(:empty_file) { MODELS_FIXTURES + '/wp_item/vulnerable/empty.xml' } after do subject.vulns_file = @vulns_file - subject.vulns_xpath = vulns_xpath + subject.vulns_xpath = vulns_xpath if defined?(vulns_xpath) result = subject.vulnerabilities result.should be_a Vulnerabilities diff --git a/spec/shared_examples/wp_plugin_vulnerable.rb b/spec/shared_examples/wp_plugin_vulnerable.rb new file mode 100644 index 00000000..255b84cc --- /dev/null +++ b/spec/shared_examples/wp_plugin_vulnerable.rb @@ -0,0 +1,26 @@ +# encoding: UTF-8 + +shared_examples 'WpPlugin::Vulnerable' do + + describe '#vulns_file' do + after { subject.vulns_file.should == @expected } + + context 'when :vulns_file is no set' do + it 'returns the default one' do + @expected = PLUGINS_VULNS_FILE + end + end + + context 'when the :vulns_file is already set' do + it 'returns it' do + @expected = 'test.xml' + subject.vulns_file = @expected + end + end + end + + describe '#vulns_xpath' do + its(:vulns_xpath) { should == "//plugin[@name='plugin-name']/vulnerability" } + end + +end