Rspec indentation & code factoring
This commit is contained in:
@@ -21,12 +21,13 @@ require File.expand_path(File.dirname(__FILE__) + '/wpscan_helper')
|
|||||||
describe WpPlugin do
|
describe WpPlugin do
|
||||||
describe "#initialize" do
|
describe "#initialize" do
|
||||||
it "should create a correct instance" do
|
it "should create a correct instance" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
instance = WpItem.new(
|
||||||
:path => "test/asdf.php",
|
:base_url => "http://sub.example.com/path/to/wordpress/",
|
||||||
:vulns_file => "XXX.xml",
|
:path => "test/asdf.php",
|
||||||
:name => "test",
|
:vulns_file => "XXX.xml",
|
||||||
:vulns_xpath => "XX",
|
:name => "test",
|
||||||
:type => "plugins"
|
:vulns_xpath => "XX",
|
||||||
|
:type => "plugins"
|
||||||
)
|
)
|
||||||
instance.wp_content_dir.should == "wp-content"
|
instance.wp_content_dir.should == "wp-content"
|
||||||
instance.base_url.should == "http://sub.example.com/path/to/wordpress/"
|
instance.base_url.should == "http://sub.example.com/path/to/wordpress/"
|
||||||
@@ -35,109 +36,79 @@ describe WpPlugin do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#get_full_url" do
|
describe "#get_full_url" do
|
||||||
|
after :each do
|
||||||
|
arguments = {
|
||||||
|
:base_url => "http://sub.example.com/path/to/wordpress/",
|
||||||
|
:path => "test/asdf.php",
|
||||||
|
:vulns_file => "XXX.xml",
|
||||||
|
:name => "test",
|
||||||
|
:vulns_xpath => "XX",
|
||||||
|
:type => "plugins",
|
||||||
|
:wp_content_dir => @wp_content_dir
|
||||||
|
}
|
||||||
|
|
||||||
|
instance = WpItem.new(arguments)
|
||||||
|
instance.get_full_url.to_s.should === @expected
|
||||||
|
end
|
||||||
|
|
||||||
it "should return the correct url" do
|
it "should return the correct url" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@expected = "http://sub.example.com/path/to/wordpress/wp-content/plugins/test/asdf.php"
|
||||||
:path => "test/asdf.php",
|
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins"
|
|
||||||
)
|
|
||||||
instance.get_full_url.to_s.should == "http://sub.example.com/path/to/wordpress/wp-content/plugins/test/asdf.php"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the correct url (custom wp_content_dir)" do
|
it "should return the correct url (custom wp_content_dir)" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@wp_content_dir = "custom"
|
||||||
:path => "test/asdf.php",
|
@expected = "http://sub.example.com/path/to/wordpress/custom/plugins/test/asdf.php"
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins",
|
|
||||||
:wp_content_dir => "custom"
|
|
||||||
)
|
|
||||||
instance.get_full_url.to_s.should == "http://sub.example.com/path/to/wordpress/custom/plugins/test/asdf.php"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should trim / and add missing / before concatenating url" do
|
it "should trim / and add missing / before concatenating url" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@wp_content_dir = "/custom/"
|
||||||
:path => "test/asdf.php",
|
@expected = "http://sub.example.com/path/to/wordpress/custom/plugins/test/asdf.php"
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins",
|
|
||||||
:wp_content_dir => "/custom/"
|
|
||||||
)
|
|
||||||
instance.get_full_url.to_s.should == "http://sub.example.com/path/to/wordpress/custom/plugins/test/asdf.php"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#get_url_without_filename" do
|
describe "#get_url_without_filename" do
|
||||||
|
after :each do
|
||||||
|
arguments = {
|
||||||
|
:base_url => @base_url || "http://sub.example.com/path/to/wordpress/",
|
||||||
|
:path => @path || "test/asdf.php",
|
||||||
|
:vulns_file => "XXX.xml",
|
||||||
|
:name => "test",
|
||||||
|
:vulns_xpath => "XX",
|
||||||
|
:type => "plugins",
|
||||||
|
:wp_content_dir => @wp_content_dir
|
||||||
|
}
|
||||||
|
|
||||||
|
instance = WpItem.new(arguments)
|
||||||
|
instance.get_url_without_filename.to_s.should === @expected
|
||||||
|
end
|
||||||
|
|
||||||
it "should return the correct url" do
|
it "should return the correct url" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@expected = "http://sub.example.com/path/to/wordpress/wp-content/plugins/test/"
|
||||||
:path => "test/asdf.php",
|
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins"
|
|
||||||
)
|
|
||||||
instance.get_url_without_filename.to_s.should == "http://sub.example.com/path/to/wordpress/wp-content/plugins/test/"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the correct url (custom wp_content_dir)" do
|
it "should return the correct url (custom wp_content_dir)" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@wp_content_dir = "custom"
|
||||||
:path => "test/asdf.php",
|
@expected = "http://sub.example.com/path/to/wordpress/custom/plugins/test/"
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins",
|
|
||||||
:wp_content_dir => "custom"
|
|
||||||
)
|
|
||||||
instance.get_url_without_filename.to_s.should == "http://sub.example.com/path/to/wordpress/custom/plugins/test/"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should trim / and add missing / before concatenating url" do
|
it "should trim / and add missing / before concatenating url" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@wp_content_dir = "/custom/"
|
||||||
:path => "test/asdf.php",
|
@expected = "http://sub.example.com/path/to/wordpress/custom/plugins/test/"
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins",
|
|
||||||
:wp_content_dir => "/custom/"
|
|
||||||
)
|
|
||||||
instance.get_url_without_filename.to_s.should == "http://sub.example.com/path/to/wordpress/custom/plugins/test/"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not remove the last foldername" do
|
it "should not remove the last foldername" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@path = "test/"
|
||||||
:path => "test/",
|
@expected = "http://sub.example.com/path/to/wordpress/wp-content/plugins/test/"
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins"
|
|
||||||
)
|
|
||||||
instance.get_url_without_filename.to_s.should == "http://sub.example.com/path/to/wordpress/wp-content/plugins/test/"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the correct url (https)" do
|
it "should return the correct url (https)" do
|
||||||
instance = WpItem.new(:base_url => "https://sub.example.com/path/to/wordpress/",
|
@base_url = "https://sub.example.com/path/to/wordpress/"
|
||||||
:path => "test/asdf.php",
|
@expected = "https://sub.example.com/path/to/wordpress/wp-content/plugins/test/"
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins"
|
|
||||||
)
|
|
||||||
instance.get_url_without_filename.to_s.should == "https://sub.example.com/path/to/wordpress/wp-content/plugins/test/"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should add the last slash if it's not present" do
|
it "should add the last slash if it's not present" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@path = "test-one"
|
||||||
:path => "test-one",
|
@expected = "http://sub.example.com/path/to/wordpress/wp-content/plugins/test-one/"
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins"
|
|
||||||
)
|
|
||||||
instance.get_url_without_filename.to_s.should == "http://sub.example.com/path/to/wordpress/wp-content/plugins/test-one/"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -145,12 +116,13 @@ describe WpPlugin do
|
|||||||
let(:fixtures_dir) { SPEC_FIXTURES_WPSCAN_WP_PLUGIN_DIR + '/version' }
|
let(:fixtures_dir) { SPEC_FIXTURES_WPSCAN_WP_PLUGIN_DIR + '/version' }
|
||||||
|
|
||||||
before :each do
|
before :each do
|
||||||
@instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@instance = WpItem.new(
|
||||||
:path => "test/asdf.php",
|
:base_url => "http://sub.example.com/path/to/wordpress/",
|
||||||
:vulns_file => "XXX.xml",
|
:path => "test/asdf.php",
|
||||||
:name => "test",
|
:vulns_file => "XXX.xml",
|
||||||
:vulns_xpath => "XX",
|
:name => "test",
|
||||||
:type => "plugins"
|
:vulns_xpath => "XX",
|
||||||
|
:type => "plugins"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -165,39 +137,39 @@ describe WpPlugin do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should return nil if the version is invalid (IE : trunk etc)" do
|
it "should return nil if the version is invalid (IE : trunk etc)" do
|
||||||
stub_request(:get, @instance.readme_url.to_s).to_return(:status => 200,
|
stub_request_to_fixture(:url => @instance.readme_url.to_s, :fixture => fixtures_dir + '/trunk-version.txt')
|
||||||
:body => File.new(fixtures_dir + '/trunk-version.txt'))
|
|
||||||
@instance.version.should be_nil
|
@instance.version.should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the version 0.4" do
|
it "should return the version 0.4" do
|
||||||
stub_request(:get, @instance.readme_url.to_s).to_return(:status => 200,
|
stub_request_to_fixture(:url => @instance.readme_url.to_s, :fixture => fixtures_dir + '/simple-login-lockdown-0.4.txt')
|
||||||
:body => File.new(fixtures_dir + '/simple-login-lockdown-0.4.txt'))
|
|
||||||
|
|
||||||
@instance.version.should === "0.4"
|
@instance.version.should === "0.4"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#directory_listing?" do
|
describe "#directory_listing?" do
|
||||||
before :each do
|
before :each do
|
||||||
@instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@instance = WpItem.new(
|
||||||
:path => "test/asdf.php",
|
:base_url => "http://sub.example.com/path/to/wordpress/",
|
||||||
:vulns_file => "XXX.xml",
|
:path => "test/asdf.php",
|
||||||
:name => "test",
|
:vulns_file => "XXX.xml",
|
||||||
:vulns_xpath => "XX",
|
:name => "test",
|
||||||
:type => "plugins"
|
:vulns_xpath => "XX",
|
||||||
|
:type => "plugins"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return true" do
|
it "should return true" do
|
||||||
stub_request(:get, @instance.get_url_without_filename.to_s).to_return(:status => 200,
|
stub_request(:get, @instance.get_url_without_filename.to_s)
|
||||||
:body => "<html><head><title>Index of asdf</title></head></html>")
|
.to_return(:status => 200, :body => "<html><head><title>Index of asdf</title></head></html>")
|
||||||
|
|
||||||
@instance.directory_listing?.should == true
|
@instance.directory_listing?.should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return false" do
|
it "should return false" do
|
||||||
stub_request(:get, @instance.get_url_without_filename.to_s).to_return(:status => 200,
|
stub_request(:get, @instance.get_url_without_filename.to_s)
|
||||||
:body => "<html><head><title>My Wordpress Site</title></head></html>")
|
.to_return(:status => 200, :body => "<html><head><title>My Wordpress Site</title></head></html>")
|
||||||
|
|
||||||
@instance.directory_listing?.should == false
|
@instance.directory_listing?.should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -208,72 +180,57 @@ describe WpPlugin do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#extract_name_from_url" do
|
describe "#extract_name_from_url" do
|
||||||
|
after :each do
|
||||||
|
arguments = {
|
||||||
|
:base_url => "http://sub.example.com/path/to/wordpress/",
|
||||||
|
:path => @path || "test/asdf.php",
|
||||||
|
:vulns_file => "XXX.xml",
|
||||||
|
:name => "test",
|
||||||
|
:vulns_xpath => "XX",
|
||||||
|
:type => @type || "plugins",
|
||||||
|
:wp_content_dir => @wp_content_dir
|
||||||
|
}
|
||||||
|
|
||||||
|
instance = WpItem.new(arguments)
|
||||||
|
instance.extract_name_from_url.should === @expected
|
||||||
|
end
|
||||||
|
|
||||||
it "should extract the correct name" do
|
it "should extract the correct name" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@expected = "test"
|
||||||
:path => "test/asdf.php",
|
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins"
|
|
||||||
)
|
|
||||||
instance.extract_name_from_url.should == "test"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should extract the correct name (custom wp_content_dir)" do
|
it "should extract the correct name (custom wp_content_dir)" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@wp_content_dir = "custom"
|
||||||
:path => "test/asdf.php",
|
@expected = "test"
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins",
|
|
||||||
:wp_content_dir => "custom"
|
|
||||||
)
|
|
||||||
instance.extract_name_from_url.should == "test"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should extract the correct name" do
|
it "should extract the correct name" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@path = "test2/asdf.php"
|
||||||
:path => "test2/asdf.php",
|
@wp_content_dir = "/custom/"
|
||||||
:vulns_file => "XXX.xml",
|
@expected = "test2"
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins",
|
|
||||||
:wp_content_dir => "/custom/"
|
|
||||||
)
|
|
||||||
instance.extract_name_from_url.should == "test2"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should extract the correct plugin name" do
|
it "should extract the correct plugin name" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@path = "testplugin/"
|
||||||
:path => "testplugin/",
|
@expected = "testplugin"
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins"
|
|
||||||
)
|
|
||||||
instance.extract_name_from_url.should == "testplugin"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should extract the correct theme name" do
|
it "should extract the correct theme name" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@path = "testtheme/"
|
||||||
:path => "testtheme/",
|
@type = "themes"
|
||||||
:vulns_file => "XXX.xml",
|
@expected = "testtheme"
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "themes"
|
|
||||||
)
|
|
||||||
instance.extract_name_from_url.should == "testtheme"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#to_s" do
|
describe "#to_s" do
|
||||||
before :each do
|
before :each do
|
||||||
@instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@instance = WpItem.new(
|
||||||
:path => "test/asdf.php",
|
:base_url => "http://sub.example.com/path/to/wordpress/",
|
||||||
:vulns_file => "XXX.xml",
|
:path => "test/asdf.php",
|
||||||
:name => "test",
|
:vulns_file => "XXX.xml",
|
||||||
:vulns_xpath => "XX",
|
:name => "test",
|
||||||
:type => "plugins"
|
:vulns_xpath => "XX",
|
||||||
|
:type => "plugins"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -290,194 +247,159 @@ describe WpPlugin do
|
|||||||
|
|
||||||
describe "#==" do
|
describe "#==" do
|
||||||
before :each do
|
before :each do
|
||||||
@instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@instance = WpItem.new(
|
||||||
:path => "test/asdf.php",
|
:base_url => "http://sub.example.com/path/to/wordpress/",
|
||||||
:vulns_file => "XXX.xml",
|
:path => "test/asdf.php",
|
||||||
:name => "test",
|
:vulns_file => "XXX.xml",
|
||||||
:vulns_xpath => "XX",
|
:name => "test",
|
||||||
:type => "plugins"
|
:vulns_xpath => "XX",
|
||||||
|
:type => "plugins"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return false" do
|
it "should return false" do
|
||||||
instance2 = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
instance2 = WpItem.new(
|
||||||
:path => "newname/asdf.php",
|
:base_url => "http://sub.example.com/path/to/wordpress/",
|
||||||
:type => "plugins",
|
:path => "newname/asdf.php",
|
||||||
:vulns_file => "XXX.xml",
|
:type => "plugins",
|
||||||
:vulns_xpath => "XX"
|
:vulns_file => "XXX.xml",
|
||||||
|
:vulns_xpath => "XX"
|
||||||
)
|
)
|
||||||
(@instance==instance2).should == false
|
(@instance==instance2).should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return true" do
|
it "should return true" do
|
||||||
instance2 = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
instance2 = WpItem.new(
|
||||||
:path => "test/asdf.php",
|
:base_url => "http://sub.example.com/path/to/wordpress/",
|
||||||
:type => "plugins",
|
:path => "test/asdf.php",
|
||||||
:vulns_file => "XXX.xml",
|
:type => "plugins",
|
||||||
:vulns_xpath => "XX"
|
:vulns_file => "XXX.xml",
|
||||||
|
:vulns_xpath => "XX"
|
||||||
)
|
)
|
||||||
(@instance==instance2).should == true
|
(@instance==instance2).should == true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#get_sub_folder" do
|
describe "#get_sub_folder" do
|
||||||
it "should return themes" do
|
after :each do
|
||||||
item = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
arguments = {
|
||||||
:path => "test/asdf.php",
|
:base_url => "http://sub.example.com/path/to/wordpress/",
|
||||||
:vulns_file => "XXX.xml",
|
:path => "test/asdf.php",
|
||||||
:wp_content_dir => "wp-content",
|
:vulns_file => "XXX.xml",
|
||||||
:wp_plugins_dir => "wp-content/plugins",
|
:wp_content_dir => "wp-content",
|
||||||
:name => "test",
|
:wp_plugins_dir => "wp-content/plugins",
|
||||||
:vulns_xpath => "XX",
|
:name => "test",
|
||||||
:type => "themes"
|
:vulns_xpath => "XX",
|
||||||
)
|
:type => @type || "themes"
|
||||||
item.get_sub_folder.should == "themes"
|
}
|
||||||
|
|
||||||
|
instance = WpItem.new(arguments)
|
||||||
|
|
||||||
|
if @raise_error
|
||||||
|
expect { instance.get_sub_folder }.to @raise_error
|
||||||
|
else
|
||||||
|
instance.get_sub_folder.should === @expected
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return themes" do
|
it "should return themes" do
|
||||||
item = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@expected = "themes"
|
||||||
:path => "test/asdf.php",
|
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:wp_content_dir => "wp-content",
|
|
||||||
:wp_plugins_dir => "wp-content/plugins",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "themes"
|
|
||||||
)
|
|
||||||
item.get_sub_folder.should == "themes"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return nil" do
|
it "should return nil" do
|
||||||
item = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@type = "timthumbs"
|
||||||
:path => "test/asdf.php",
|
@expected = nil
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:wp_content_dir => "wp-content",
|
|
||||||
:wp_plugins_dir => "wp-content/plugins",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "timthumbs"
|
|
||||||
)
|
|
||||||
item.get_sub_folder.should == nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should raise an exception" do
|
it "should raise an exception" do
|
||||||
item = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@type = "type"
|
||||||
:path => "test/asdf.php",
|
@raise_error = raise_error(RuntimeError, "unknown type type")
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:wp_content_dir => "wp-content",
|
|
||||||
:wp_plugins_dir => "wp-content/plugins",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "type"
|
|
||||||
)
|
|
||||||
expect { item.get_sub_folder }.to raise_error(RuntimeError, "unknown type type")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#readme_url" do
|
describe "#readme_url" do
|
||||||
|
after :each do
|
||||||
|
arguments = {
|
||||||
|
:base_url => "http://sub.example.com/path/to/wordpress/",
|
||||||
|
:path => "test/asdf.php",
|
||||||
|
:vulns_file => "XXX.xml",
|
||||||
|
:name => "test",
|
||||||
|
:vulns_xpath => "XX",
|
||||||
|
:type => @type || "plugins",
|
||||||
|
:wp_content_dir => @wp_content_dir
|
||||||
|
}
|
||||||
|
|
||||||
|
instance = WpItem.new(arguments)
|
||||||
|
instance.readme_url.to_s.should === @expected
|
||||||
|
end
|
||||||
|
|
||||||
it "should return the corrent plugin readme url" do
|
it "should return the corrent plugin readme url" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@expected = "http://sub.example.com/path/to/wordpress/wp-content/plugins/test/readme.txt"
|
||||||
:path => "test/asdf.php",
|
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins"
|
|
||||||
)
|
|
||||||
instance.readme_url.to_s.should == "http://sub.example.com/path/to/wordpress/wp-content/plugins/test/readme.txt"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the corrent plugin readme url (custom wp_content)" do
|
it "should return the corrent plugin readme url (custom wp_content)" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@wp_content_dir = "custom"
|
||||||
:path => "test/asdf.php",
|
@expected = "http://sub.example.com/path/to/wordpress/custom/plugins/test/readme.txt"
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins",
|
|
||||||
:wp_content_dir => "custom"
|
|
||||||
)
|
|
||||||
instance.readme_url.to_s.should == "http://sub.example.com/path/to/wordpress/custom/plugins/test/readme.txt"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the corrent theme readme url" do
|
it "should return the corrent theme readme url" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@type = "themes"
|
||||||
:path => "test/asdf.php",
|
@expected = "http://sub.example.com/path/to/wordpress/wp-content/themes/test/readme.txt"
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "themes"
|
|
||||||
)
|
|
||||||
instance.readme_url.to_s.should == "http://sub.example.com/path/to/wordpress/wp-content/themes/test/readme.txt"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the corrent theme readme url (custom wp_content)" do
|
it "should return the corrent theme readme url (custom wp_content)" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@type = "themes"
|
||||||
:path => "test/asdf.php",
|
@wp_content_dir = "custom"
|
||||||
:vulns_file => "XXX.xml",
|
@expected = "http://sub.example.com/path/to/wordpress/custom/themes/test/readme.txt"
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "themes",
|
|
||||||
:wp_content_dir => "custom"
|
|
||||||
)
|
|
||||||
instance.readme_url.to_s.should == "http://sub.example.com/path/to/wordpress/custom/themes/test/readme.txt"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#changelog_url" do
|
describe "#changelog_url" do
|
||||||
|
after :each do
|
||||||
|
arguments = {
|
||||||
|
:base_url => "http://sub.example.com/path/to/wordpress/",
|
||||||
|
:path => "test/asdf.php",
|
||||||
|
:vulns_file => "XXX.xml",
|
||||||
|
:name => "test",
|
||||||
|
:vulns_xpath => "XX",
|
||||||
|
:type => @type || "plugins",
|
||||||
|
:wp_content_dir => @wp_content_dir
|
||||||
|
}
|
||||||
|
|
||||||
|
instance = WpItem.new(arguments)
|
||||||
|
instance.changelog_url.to_s.should === @expected
|
||||||
|
end
|
||||||
|
|
||||||
it "should return the corrent plugin changelog url" do
|
it "should return the corrent plugin changelog url" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@expected = "http://sub.example.com/path/to/wordpress/wp-content/plugins/test/changelog.txt"
|
||||||
:path => "test/asdf.php",
|
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins"
|
|
||||||
)
|
|
||||||
instance.changelog_url.to_s.should == "http://sub.example.com/path/to/wordpress/wp-content/plugins/test/changelog.txt"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the corrent plugin changelog url (custom wp_content)" do
|
it "should return the corrent plugin changelog url (custom wp_content)" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@wp_content_dir = "custom"
|
||||||
:path => "test/asdf.php",
|
@expected = "http://sub.example.com/path/to/wordpress/custom/plugins/test/changelog.txt"
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "plugins",
|
|
||||||
:wp_content_dir => "custom"
|
|
||||||
)
|
|
||||||
instance.changelog_url.to_s.should == "http://sub.example.com/path/to/wordpress/custom/plugins/test/changelog.txt"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the corrent theme changelog url" do
|
it "should return the corrent theme changelog url" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@type = "themes"
|
||||||
:path => "test/asdf.php",
|
@expected = "http://sub.example.com/path/to/wordpress/wp-content/themes/test/changelog.txt"
|
||||||
:vulns_file => "XXX.xml",
|
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "themes"
|
|
||||||
)
|
|
||||||
instance.changelog_url.to_s.should == "http://sub.example.com/path/to/wordpress/wp-content/themes/test/changelog.txt"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the corrent theme changelog url (custom wp_content)" do
|
it "should return the corrent theme changelog url (custom wp_content)" do
|
||||||
instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@type = "themes"
|
||||||
:path => "test/asdf.php",
|
@wp_content_dir = "custom"
|
||||||
:vulns_file => "XXX.xml",
|
@expected = "http://sub.example.com/path/to/wordpress/custom/themes/test/changelog.txt"
|
||||||
:name => "test",
|
|
||||||
:vulns_xpath => "XX",
|
|
||||||
:type => "themes",
|
|
||||||
:wp_content_dir => "custom"
|
|
||||||
)
|
|
||||||
instance.changelog_url.to_s.should == "http://sub.example.com/path/to/wordpress/custom/themes/test/changelog.txt"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#has_readme?" do
|
describe "#has_readme?" do
|
||||||
before :each do
|
before :each do
|
||||||
@instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@instance = WpItem.new(
|
||||||
:path => "test/asdf.php",
|
:base_url => "http://sub.example.com/path/to/wordpress/",
|
||||||
:vulns_file => "XXX.xml",
|
:path => "test/asdf.php",
|
||||||
:name => "test",
|
:vulns_file => "XXX.xml",
|
||||||
:vulns_xpath => "XX",
|
:name => "test",
|
||||||
:type => "plugins"
|
:vulns_xpath => "XX",
|
||||||
|
:type => "plugins"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -494,12 +416,13 @@ describe WpPlugin do
|
|||||||
|
|
||||||
describe "#has_changelog?" do
|
describe "#has_changelog?" do
|
||||||
before :each do
|
before :each do
|
||||||
@instance = WpItem.new(:base_url => "http://sub.example.com/path/to/wordpress/",
|
@instance = WpItem.new(
|
||||||
:path => "test/asdf.php",
|
:base_url => "http://sub.example.com/path/to/wordpress/",
|
||||||
:vulns_file => "XXX.xml",
|
:path => "test/asdf.php",
|
||||||
:name => "test",
|
:vulns_file => "XXX.xml",
|
||||||
:vulns_xpath => "XX",
|
:name => "test",
|
||||||
:type => "plugins"
|
:vulns_xpath => "XX",
|
||||||
|
:type => "plugins"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -513,4 +436,4 @@ describe WpPlugin do
|
|||||||
@instance.has_changelog?.should == false
|
@instance.has_changelog?.should == false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user