From de0ca810b9c9e5781e47d0dd85435e97e4c1ec2a Mon Sep 17 00:00:00 2001 From: Adam David Date: Tue, 29 May 2018 20:42:19 -0700 Subject: [PATCH 1/3] Let VRT::Map#find_node accept nil values --- lib/vrt/map.rb | 1 + spec/vrt/map_spec.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/lib/vrt/map.rb b/lib/vrt/map.rb index 0d338e6..4771ce4 100644 --- a/lib/vrt/map.rb +++ b/lib/vrt/map.rb @@ -18,6 +18,7 @@ def initialize(version = nil) end def find_node(string, max_depth: 'variant') + return nil unless valid_identifier?(string) @_found_nodes[string + max_depth] ||= walk_node_tree(string, max_depth: max_depth) end diff --git a/spec/vrt/map_spec.rb b/spec/vrt/map_spec.rb index e1f80ae..1f55858 100644 --- a/spec/vrt/map_spec.rb +++ b/spec/vrt/map_spec.rb @@ -51,6 +51,50 @@ end end + describe '#find_node' do + subject { sample_map.find_node(vrt_id) } + + context 'when vrt_id is nil' do + let(:vrt_id) { nil } + + it { is_expected.to be_nil } + end + + context 'when vrt_id is not a valid identifier' do + let(:vrt_id) { "I'm not valid" } + + it { is_expected.to be_nil } + end + + context 'when vrt_id is not a string' do + let(:vrt_id) { 55 } + + it { is_expected.to be_nil } + end + + context 'when vrt_id is a valid identifier' do + context 'vrt_id does not exist in version' do + let(:vrt_id) { 'cool_new_concept' } + + it { is_expected.to be_nil } + end + + context 'vrt_id exists in version' do + context 'vrt_id is category level' do + let(:vrt_id) { 'server_security_misconfiguration' } + + it { is_expected.to be_a(VRT::Node) } + end + + context 'vrt_id is a variant' do + let(:vrt_id) { 'server_security_misconfiguration.using_default_credentials.production_server' } + + it { is_expected.to be_a(VRT::Node) } + end + end + end + end + describe '#get_lineage' do context 'with a complex hierarchy' do let(:id) { 'server_security_misconfiguration.using_default_credentials.production_server' } From cbad3bca8264e8756aaae860840f0dae9aceb1b9 Mon Sep 17 00:00:00 2001 From: Adam David Date: Tue, 29 May 2018 21:52:14 -0700 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index daed38a..f05a507 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Changed - Fixed bug for mappings with multiple keys and a default (resolves: [#26](https://github.com/bugcrowd/vrt-ruby/issues/26)) +- `VRT::Map#find_node` returns `nil` when passed an invalid vrt_id ### Removed - Removed `Gemfile.lock` from source control From e0c9cb4a8b1285ce6de3d2ba8db664e67b9581d8 Mon Sep 17 00:00:00 2001 From: Adam David Date: Wed, 30 May 2018 16:23:59 -0700 Subject: [PATCH 3/3] Include issue in changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f05a507..7ddedcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Changed - Fixed bug for mappings with multiple keys and a default (resolves: [#26](https://github.com/bugcrowd/vrt-ruby/issues/26)) -- `VRT::Map#find_node` returns `nil` when passed an invalid vrt_id +- `VRT::Map#find_node` returns `nil` when passed an invalid vrt_id (resolves: [#32](https://github.com/bugcrowd/vrt-ruby/issues/32)) ### Removed - Removed `Gemfile.lock` from source control