Additional specs for #1374
This commit is contained in:
@@ -6,12 +6,14 @@ rescue StandardError => e
|
|||||||
raise "JSON parsing error in #{file} #{e}"
|
raise "JSON parsing error in #{file} #{e}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [ Symbol ]
|
# Sanitize and classify a slug
|
||||||
# @note As a class can not start with a digit or underscore, a D_ is
|
# @note As a class can not start with a digit or underscore, a D_ is
|
||||||
# put as a prefix in such case. Ugly but well :x
|
# put as a prefix in such case. Ugly but well :x
|
||||||
# Not only used to classify slugs though, but Dynamic Finder names as well
|
# Not only used to classify slugs though, but Dynamic Finder names as well
|
||||||
|
#
|
||||||
|
# @return [ Symbol ]
|
||||||
def classify_slug(slug)
|
def classify_slug(slug)
|
||||||
classified = slug.to_s.tr('-', '_').camelize.to_s
|
classified = slug.to_s.gsub(/[^a-z\d\-]/i, '-').gsub(/\-{1,}/, '_').camelize.to_s
|
||||||
classified = "D_#{classified}" if classified[0] =~ /\d/
|
classified = "D_#{classified}" if classified[0] =~ /\d/
|
||||||
|
|
||||||
classified.to_sym
|
classified.to_sym
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ describe WPScan::DB::DynamicFinders::Plugin do
|
|||||||
describe '.create_versions_finders' do
|
describe '.create_versions_finders' do
|
||||||
# handled and tested in spec/lib/finders/dynamic_finders/plugin_version_spec
|
# handled and tested in spec/lib/finders/dynamic_finders/plugin_version_spec
|
||||||
|
|
||||||
describe 'Try to create the finders twice' do
|
context 'When trying to create the finders twice' do
|
||||||
# let's just test one slug, no need to test them all
|
# let's just test one slug, no need to test them all
|
||||||
let(:slug) { '12-step-meeting-list' }
|
let(:slug) { '12-step-meeting-list' }
|
||||||
|
|
||||||
@@ -57,6 +57,14 @@ describe WPScan::DB::DynamicFinders::Plugin do
|
|||||||
expect { WPScan::DB::DynamicFinders::Plugin.create_versions_finders(slug) }.to_not raise_error
|
expect { WPScan::DB::DynamicFinders::Plugin.create_versions_finders(slug) }.to_not raise_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the slug contains non alpha-numeric chars' do
|
||||||
|
let(:slug) { 'test.something' }
|
||||||
|
|
||||||
|
it 'sanitize it and does not raise an error' do
|
||||||
|
expect { WPScan::DB::DynamicFinders::Plugin.create_versions_finders(slug) }.to_not raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.version_finder_super_class' do
|
describe '.version_finder_super_class' do
|
||||||
|
|||||||
18
spec/lib/helper_spec.rb
Normal file
18
spec/lib/helper_spec.rb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
describe '#classify_slug' do
|
||||||
|
{
|
||||||
|
'slug' => :Slug,
|
||||||
|
'slug-usual' => :SlugUsual,
|
||||||
|
'12-slug' => :D_12Slug,
|
||||||
|
'slug.s' => :SlugS,
|
||||||
|
'slug yolo $' => :SlugYolo,
|
||||||
|
'slug $ ab.cd/12' => :SlugAbCd12
|
||||||
|
}.each do |slug, expected_symbol|
|
||||||
|
context "when #{slug}" do
|
||||||
|
it "returns #{expected_symbol}" do
|
||||||
|
expect(classify_slug(slug)).to eql expected_symbol
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user