Skip to content

Commit 1cd8665

Browse files
authored
[BC-7978] Add support for subcategory filtering (#16)
* [BC-7978] Add support for subcategory filtering in VRT.all_matching_categories * Clean up sub v cat id * bump version
1 parent 1e37c12 commit 1cd8665

5 files changed

Lines changed: 37 additions & 5 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
vrt (0.4.2)
4+
vrt (0.4.4)
55

66
GEM
77
remote: https://rubygems.org/

lib/vrt.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ def current_categories
5757

5858
# Get all deprecated ids that would match in the given categories from the current version
5959
def all_matching_categories(categories)
60-
cross_version_category_mapping.select { |key, _value| categories.include?(key) }.values.flatten
60+
cross_version_category_mapping
61+
.select { |key, _value| categories.include?(key) }
62+
.values
63+
.flatten
64+
.uniq
6165
end
6266

6367
# Finds the best match valid node. First looks at valid nodes in the given new version or finds

lib/vrt/cross_version_mapping.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
module VRT
22
module CrossVersionMapping
33
# Maps new_category_id: deprecated_node_id
4+
# and new_subcategory_id: deprecated_node_id
45
def cross_version_category_mapping
56
category_map = {}
67
deprecated_node_json.each do |key, value|
78
latest_version = value.keys.sort_by { |n| Gem::Version.new(n) }.last
8-
id = value[latest_version].split('.')[0]
9-
category_map[id] ? category_map[id] << key : category_map[id] = [key]
9+
id_list = value[latest_version].split('.')
10+
cat_id = id_list[0]
11+
sub_id = id_list[0..1].join('.')
12+
category_map[cat_id] ? category_map[cat_id] << key : category_map[cat_id] = [key]
13+
category_map[sub_id] ? category_map[sub_id] << key : category_map[sub_id] = [key]
1014
end
1115
category_map
1216
end

lib/vrt/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Vrt
2-
VERSION = '0.4.3'.freeze
2+
VERSION = '0.4.4'.freeze
33
end

spec/vrt_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,30 @@
183183
expect(full_search_list).to contain_exactly(*deprecated)
184184
end
185185
end
186+
187+
context 'with subcategories included' do
188+
let(:categories) do
189+
%w[
190+
external_behavior
191+
other
192+
unvalidated_redirects_and_forwards.open_redirect
193+
]
194+
end
195+
let(:deprecated) do
196+
%w[
197+
poor_physical_security
198+
social_engineering
199+
unvalidated_redirects_and_forwards.lack_of_security_speed_bump_page
200+
unvalidated_redirects_and_forwards.open_redirect.get_based_all_users
201+
unvalidated_redirects_and_forwards.open_redirect.get_based_unauthenticated
202+
unvalidated_redirects_and_forwards.open_redirect.get_based_authenticated
203+
]
204+
end
205+
206+
it 'should return a list containing the deprecated categories' do
207+
expect(full_search_list).to contain_exactly(*deprecated)
208+
end
209+
end
186210
end
187211

188212
describe '#current_version?' do

0 commit comments

Comments
 (0)