Skip to content

Commit bad8481

Browse files
janeunerRobert Clark
and
Robert Clark
authored
Add Fallback Logic for Unrecognized Idents #222 (#227)
- added fallback logic for unrecognized idents, using legacy behaviors - added unit testing for the new Ident constructor * Cleanup Ident test to use hash instead of array Signed-off-by: Jarod Neuner <jarod@neuner.us> Signed-off-by: Robert Clark <rbclark@mitre.org> Co-authored-by: Robert Clark <rbclark@mitre.org>
1 parent d4ee848 commit bad8481

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/happy_mapper_tools/benchmark.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,17 @@ class Ident
6767
content :ident, String
6868
def initialize(ident_str)
6969
@ident = ident_str
70-
if ident_str =~ /^(CCI-[0-9]{6})$/
70+
if ident_str =~ /^(CCI-[0-9]{6})$/
71+
# Match CCI IDs; e.g. CCI-123456
7172
@system = 'http://cyber.mil/cci'
72-
else
73+
elsif ident_str =~ /^(S?V-[0-9]{5})$/
74+
# Match SV- IDs; e.g. SV-12345
75+
# Match V- IDs; e.g. V-12345
7376
@system = 'http://cyber.mil/legacy'
74-
end
77+
else
78+
# for all other ident_str, use the old identifier
79+
@system = 'https://public.cyber.mil/stigs/cci/'
80+
end
7581
end
7682
end
7783

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'minitest/spec'
2+
require 'minitest/autorun'
3+
4+
describe "HappyMapperTools::Benchmark::Ident correctly determines the system for each identifier" do
5+
# test values (tv); tv[0] == identifier, tv[1] == system
6+
tvList = {
7+
'CCI-000213' => 'http://cyber.mil/cci',
8+
'V-72859' => 'http://cyber.mil/legacy',
9+
'SV-87511' => 'http://cyber.mil/legacy',
10+
'CCI-00213' => 'https://public.cyber.mil/stigs/cci/',
11+
'CCI-0000213' => 'https://public.cyber.mil/stigs/cci/',
12+
}
13+
14+
tvList.each do |identifier, system|
15+
it identifier do
16+
# Ident.new automatically determines ident.system
17+
ident = HappyMapperTools::Benchmark::Ident.new identifier
18+
assert_equal(system, ident.system)
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)