Skip to content

Commit

Permalink
feedback fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rajkumar-u committed Apr 28, 2022
1 parent 20b9121 commit 36b6679
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 92 deletions.
28 changes: 12 additions & 16 deletions lib/bugcrowd_templates/template_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,31 @@ def find_template_file
# check upto item directory, and return if template exist
# e.g: `templates/submissions/description/server_security_misconfiguration/clickjacking/form_input/template.md`
def item_file_path
item_path = BugcrowdTemplates.current_directory.join(
type, field, category, subcategory, item, file_name
)
file_name_with_extension = [file_name, 'md'].join('.')

file_path_url(item_path)
BugcrowdTemplates.current_directory.join(
type, field, category, subcategory, item, file_name_with_extension
)
end

# check upto subcategory directory, and return if template exist
# e.g: `templates/submissions/description/server_security_misconfiguration/clickjacking/template.md`
def subcategory_file_path
subcategory_path = BugcrowdTemplates.current_directory.join(
type, field, category, subcategory, file_name
)
file_name_with_extension = [file_name, 'md'].join('.')

file_path_url(subcategory_path)
BugcrowdTemplates.current_directory.join(
type, field, category, subcategory, file_name_with_extension
)
end

# check upto category directory, and return if template exist
# e.g: `templates/submissions/description/server_security_misconfiguration/template.md`
def category_file_path
category_path = BugcrowdTemplates.current_directory.join(
type, field, category, file_name
)

file_path_url(category_path)
end
file_name_with_extension = [file_name, 'md'].join('.')

def file_path_url(file_path)
"#{file_path}.md"
BugcrowdTemplates.current_directory.join(
type, field, category, file_name_with_extension
)
end

def valid?(input_str)
Expand Down
105 changes: 33 additions & 72 deletions spec/bugcrowd_templates/template_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
)
end

let!(:directory) { BugcrowdTemplates.current_directory }
let!(:file_name_with_extension) { [file_name, 'md'].join('.') }

describe '#new' do
context 'initialize with submission type' do
let!(:type) { 'submission' }
Expand Down Expand Up @@ -64,18 +67,18 @@
).template_file
end

let(:directory) { BugcrowdTemplates.current_directory }
let!(:result) { directory.join(type, field, category, subcategory, item, file_name_with_extension) }

context 'when it has all the params' do
let!(:type) { 'methodology' }
let!(:field) { 'notes' }
let!(:category) { 'website_testing' }
let!(:subcategory) { 'information' }
let!(:subcategory) { '' }
let!(:item) { '' }
let!(:file_name) { '' }
let!(:file_name) { 'information' }

it 'returns the template value' do
is_expected.to eq("#{directory}/methodology/notes/website_testing/information.md")
is_expected.to eq(result)
end
end

Expand All @@ -88,7 +91,7 @@
let!(:file_name) { '' }

it 'returns the template value' do
is_expected.to eq("#{directory}/methodology/notes/website_testing.md")
is_expected.to eq(result)
end
end

Expand Down Expand Up @@ -118,18 +121,17 @@
).find_template_file
end

let(:dir) { BugcrowdTemplates.current_directory }

context 'when item folder is not having template for submissions' do
let!(:type) { 'submissions' }
let!(:field) { 'description' }
let!(:category) { 'server_security_misconfiguration' }
let!(:subcategory) { 'clickjacking' }
let!(:item) { 'form_input' }
let!(:file_name) { 'template' }
let!(:result) { directory.join(type, field, category, subcategory, file_name_with_extension) }

it 'returns the template from the subcategory folder as template' do
is_expected.to eq("#{dir}/submissions/description/server_security_misconfiguration/clickjacking/template.md")
is_expected.to eq(result)
end
end

Expand All @@ -140,22 +142,24 @@
let!(:subcategory) { '' }
let!(:item) { '' }
let!(:file_name) { 'template' }
let!(:result) { directory.join(type, field, category, file_name_with_extension) }

it 'returns the category folder as template' do
is_expected.to eq("#{dir}/submissions/description/using_components_with_known_vulnerabilities/template.md")
is_expected.to eq(result)
end
end

context 'when item folder is not having template for methodology' do
let!(:type) { 'methodology' }
let!(:field) { 'notes' }
let!(:category) { 'website_testing' }
let!(:subcategory) { 'information' }
let!(:subcategory) { '' }
let!(:item) { '' }
let!(:file_name) { '' }
let!(:file_name) { 'information' }
let!(:result) { directory.join(type, field, category, file_name_with_extension) }

it 'returns the methodology template' do
is_expected.to eq("#{dir}/methodology/notes/website_testing/information.md")
is_expected.to eq(result)
end
end
end
Expand All @@ -172,18 +176,17 @@
).item_file_path
end

let(:dir) { BugcrowdTemplates.current_directory }

context 'when searching item folder for submissions' do
let!(:type) { 'submissions' }
let!(:field) { 'description' }
let!(:category) { 'server_security' }
let!(:subcategory) { 'clickjacking' }
let!(:item) { 'form' }
let!(:file_name) { 'template' }
let!(:result) { directory.join(type, field, category, subcategory, item, file_name_with_extension) }

it 'returns the template' do
is_expected.to eq("#{dir}/submissions/description/server_security/clickjacking/form/template.md")
is_expected.to eq(result)
end
end

Expand All @@ -192,11 +195,12 @@
let!(:field) { 'notes' }
let!(:category) { 'website_testing' }
let!(:subcategory) { 'information' }
let!(:item) { 'infor' }
let!(:file_name) { '' }
let!(:item) { 'api_testing' }
let!(:file_name) { 'testing' }
let!(:result) { directory.join(type, field, category, subcategory, item, file_name_with_extension) }

it 'returns the template' do
is_expected.to eq("#{dir}/methodology/notes/website_testing/information/infor.md")
is_expected.to eq(result)
end
end
end
Expand All @@ -213,31 +217,31 @@
).subcategory_file_path
end

let(:dir) { BugcrowdTemplates.current_directory }

context 'when searching subcategory folder for submissions' do
let!(:type) { 'submissions' }
let!(:field) { 'description' }
let!(:category) { 'server_security' }
let!(:subcategory) { 'clickjacking' }
let!(:item) { '' }
let!(:file_name) { 'template' }
let!(:result) { directory.join(type, field, category, subcategory, item, file_name_with_extension) }

it 'returns the template' do
is_expected.to eq("#{dir}/submissions/description/server_security/clickjacking/template.md")
is_expected.to eq(result)
end
end

context 'when searching subcategory folder for methodology' do
let!(:type) { 'methodology' }
let!(:field) { 'notes' }
let!(:category) { 'website_testing' }
let!(:subcategory) { 'information' }
let!(:subcategory) { '' }
let!(:item) { '' }
let!(:file_name) { '' }
let!(:file_name) { 'information' }
let!(:result) { directory.join(type, field, category, subcategory, file_name_with_extension) }

it 'returns the template' do
is_expected.to eq("#{dir}/methodology/notes/website_testing/information.md")
is_expected.to eq(result)
end
end
end
Expand All @@ -254,18 +258,17 @@
).category_file_path
end

let(:dir) { BugcrowdTemplates.current_directory }

context 'when searching category folder for submissions' do
let!(:type) { 'submissions' }
let!(:field) { 'description' }
let!(:category) { 'server_security' }
let!(:subcategory) { '' }
let!(:item) { '' }
let!(:file_name) { 'template' }
let!(:result) { directory.join(type, field, category, subcategory, file_name_with_extension) }

it 'returns the template' do
is_expected.to eq("#{dir}/submissions/description/server_security/template.md")
is_expected.to eq(result)
end
end

Expand All @@ -275,53 +278,11 @@
let!(:category) { 'website_testing' }
let!(:subcategory) { '' }
let!(:item) { '' }
let!(:file_name) { '' }

it 'returns the template' do
is_expected.to eq("#{dir}/methodology/notes/website_testing.md")
end
end
end

describe '#file_path_url' do
subject do
described_class.new(
type: type,
field: field,
category: category,
subcategory: subcategory,
item: item,
file_name: file_name
).file_path_url(file_path)
end

let(:dir) { BugcrowdTemplates.current_directory }

context 'when file path for submission' do
let!(:type) { 'submissions' }
let!(:field) { 'description' }
let!(:category) { 'server_security' }
let!(:subcategory) { 'subcategory' }
let!(:item) { 'item' }
let!(:file_name) { 'template' }
let(:file_path) { '/category/subcategory/item/template' }

it 'returns the template' do
is_expected.to eq('/category/subcategory/item/template.md')
end
end

context 'when file path for methodology' do
let!(:type) { 'methodology' }
let!(:field) { 'notes' }
let!(:category) { 'website_testing' }
let!(:subcategory) { 'information' }
let!(:item) { '' }
let!(:file_name) { '' }
let(:file_path) { '/methodology/notes/website_testing/information' }
let!(:file_name) { 'information' }
let!(:result) { directory.join(type, field, category, subcategory, file_name_with_extension) }

it 'returns the template' do
is_expected.to eq('/methodology/notes/website_testing/information.md')
is_expected.to eq(result)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/bugcrowd_templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
let!(:type) { 'methodology' }
let!(:field) { 'notes' }
let!(:category) { 'website_testing' }
let!(:subcategory) { 'information' }
let!(:subcategory) { '' }
let!(:item) { '' }
let!(:file_name) { '' }
let!(:file_name) { 'information' }

it 'returns the bugcrowd template value as string' do
is_expected.to include('# Information gathering')
Expand Down Expand Up @@ -233,9 +233,9 @@
let!(:type) { 'methodology' }
let!(:field) { 'notes' }
let!(:category) { 'website_testing' }
let!(:subcategory) { 'information' }
let!(:subcategory) { '' }
let!(:item) { '' }
let!(:file_name) { '' }
let!(:file_name) { 'information' }

it 'returns the methodology template value as string' do
is_expected.to include('# Information gathering')
Expand Down

0 comments on commit 36b6679

Please sign in to comment.