Skip to content

Commit

Permalink
Add Fallback Logic for Unrecognized Idents #222 (#227)
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
Signed-off-by: Robert Clark <[email protected]>
Co-authored-by: Robert Clark <[email protected]>
  • Loading branch information
janeuner and Robert Clark authored Apr 23, 2021
1 parent d4ee848 commit bad8481
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/happy_mapper_tools/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,17 @@ class Ident
content :ident, String
def initialize(ident_str)
@ident = ident_str
if ident_str =~ /^(CCI-[0-9]{6})$/
if ident_str =~ /^(CCI-[0-9]{6})$/
# Match CCI IDs; e.g. CCI-123456
@system = 'http://cyber.mil/cci'
else
elsif ident_str =~ /^(S?V-[0-9]{5})$/
# Match SV- IDs; e.g. SV-12345
# Match V- IDs; e.g. V-12345
@system = 'http://cyber.mil/legacy'
end
else
# for all other ident_str, use the old identifier
@system = 'https://public.cyber.mil/stigs/cci/'
end
end
end

Expand Down
21 changes: 21 additions & 0 deletions test/unit/inspec_tools/happymapper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'minitest/spec'
require 'minitest/autorun'

describe "HappyMapperTools::Benchmark::Ident correctly determines the system for each identifier" do
# test values (tv); tv[0] == identifier, tv[1] == system
tvList = {
'CCI-000213' => 'http://cyber.mil/cci',
'V-72859' => 'http://cyber.mil/legacy',
'SV-87511' => 'http://cyber.mil/legacy',
'CCI-00213' => 'https://public.cyber.mil/stigs/cci/',
'CCI-0000213' => 'https://public.cyber.mil/stigs/cci/',
}

tvList.each do |identifier, system|
it identifier do
# Ident.new automatically determines ident.system
ident = HappyMapperTools::Benchmark::Ident.new identifier
assert_equal(system, ident.system)
end
end
end

0 comments on commit bad8481

Please sign in to comment.