class HappyMapperTools::StigAttributes::DescriptionDetailsType

Public Class Methods

apply(value) click to toggle source
# File lib/happy_mapper_tools/stig_attributes.rb, line 159
def apply(value)
  value = value.gsub('&', 'and')
  value = value.gsub('"<"', 'less than (converted less than)')
  DescriptionDetails.parse("<Details>#{value}</Details>")
rescue Nokogiri::XML::SyntaxError => e
  if report_disallowed_tags(value) # if there was a bad tag
    exit(1)
  else
    report_error(value, e)
  end
end
apply?(value, _convert_to_type) click to toggle source
# File lib/happy_mapper_tools/stig_attributes.rb, line 171
def apply?(value, _convert_to_type)
  value.is_a?(String)
end
type() click to toggle source
# File lib/happy_mapper_tools/stig_attributes.rb, line 155
def type
  DescriptionDetails
end

Private Class Methods

report_disallowed_tags(value) click to toggle source
# File lib/happy_mapper_tools/stig_attributes.rb, line 184
def report_disallowed_tags(value)
  allowed_tags = %w{VulnDiscussion FalsePositives FalseNegatives Documentable
                    Mitigations SeverityOverrideGuidance PotentialImpacts
                    PotentialImpacts ThirdPartyTools MitigationControl
                    Responsibility IAControl IAControls SecurityOverrideGuidance}

  tags_found = value.scan(%r{(?<=<)([^\/]*?)((?= \/>)|(?=>))}).to_a

  tags_found = tags_found.uniq.flatten.reject!(&:empty?)
  offending_tags = tags_found - allowed_tags

  unless offending_tags.count.zero?
    puts "\n\nThe non-standard tag(s): #{offending_tags.to_s.colorize(:red)}" \
         ' were found in: ' + "\n\n#{value}"
    puts "\n\nPlease:\n "
    option_one = '(1) ' + '(best)'.colorize(:green) + ' Use the ' +
                 '`-r --replace-tags array` '.colorize(:light_yellow) +
                 '(case sensitive) option to replace the offending tags ' \
                 'during processing of the XCCDF ' \
                 'file to use the ' +
                 "`$#{offending_tags[0]}` ".colorize(:light_green) +
                 'syntax in your InSpec profile.'
    option_two = '(2) Update your XCCDF file to *not use* non-standard XCCDF ' \
                'elements within ' +
                 '`&lt;`,`&gt;`, `<` '.colorize(:red) +
                 'or '.colorize(:default) +
                 '`>` '.colorize(:red) +
                 'as "placeholders", and use something that doesn\'t confuse ' \
                 'the XML parser, such as : ' +
                 "`$#{offending_tags[0]}`".colorize(:light_green)
    puts option_one
    puts "\n"
    puts option_two
    return true
  end
  false
end
report_error(value, error) click to toggle source
# File lib/happy_mapper_tools/stig_attributes.rb, line 177
def report_error(value, error)
  puts error.to_s.colorize(:red)
  column = error.column - '<Details>'.length - 2
  puts "Error around #{value[column-10..column+10].colorize(:light_yellow)}"
  exit(1)
end