Skip to content

Commit

Permalink
Added fallback logic for unrecognized idents. Added unit testing for …
Browse files Browse the repository at this point in the history
…the new Ident constructor.

Signed-off-by: Jarod Neuner <[email protected]>
  • Loading branch information
janeuner committed Apr 16, 2021
2 parents d4ee848 + d1234e4 commit 082802f
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 |tv|
it tv[0] do
# Ident.new automatically determines ident.system
ident = HappyMapperTools::Benchmark::Ident.new tv[0]
assert_equal(tv[1], ident.system)
end
end
end

0 comments on commit 082802f

Please sign in to comment.