vrt 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ require 'rails/generators/base'
3
3
  module Vrt
4
4
  module Generators
5
5
  class InstallGenerator < Rails::Generators::Base
6
- source_root(File.expand_path(File.dirname(__FILE__)))
6
+ source_root(File.expand_path(File.dirname(__dir__)))
7
7
  def create_initializer_file
8
8
  copy_file '../vrt.rb', 'config/initializers/vrt.rb'
9
9
  end
data/lib/vrt.rb CHANGED
@@ -6,6 +6,7 @@ require 'vrt/map'
6
6
  require 'vrt/node'
7
7
  require 'vrt/mapping'
8
8
  require 'vrt/cross_version_mapping'
9
+ require 'vrt/errors'
9
10
 
10
11
  require 'date'
11
12
  require 'json'
@@ -48,6 +49,7 @@ module VRT
48
49
  def last_updated(version = nil)
49
50
  version ||= current_version
50
51
  return @last_update[version] if @last_update[version]
52
+
51
53
  metadata = JSON.parse(json_pathname(version).read)['metadata']
52
54
  @last_update[version] = Date.parse(metadata['release_date'])
53
55
  end
@@ -5,7 +5,7 @@ module VRT
5
5
  def cross_version_category_mapping
6
6
  category_map = {}
7
7
  deprecated_node_json.each do |key, value|
8
- latest_version = value.keys.sort_by { |n| Gem::Version.new(n) }.last
8
+ latest_version = value.keys.max_by { |n| Gem::Version.new(n) }
9
9
  id_list = value[latest_version].split('.')
10
10
  cat_id = id_list[0]
11
11
  sub_id = id_list[0..1].join('.')
@@ -26,7 +26,7 @@ module VRT
26
26
  end
27
27
 
28
28
  def latest_version_for_deprecated_node(vrt_id)
29
- deprecated_node_json[vrt_id].keys.sort_by { |n| Gem::Version.new(n) }.last
29
+ deprecated_node_json[vrt_id].keys.max_by { |n| Gem::Version.new(n) }
30
30
  end
31
31
 
32
32
  def find_deprecated_node(vrt_id, new_version = nil, max_depth = 'variant')
@@ -43,6 +43,7 @@ module VRT
43
43
  else
44
44
  parent = vrt_id.split('.')[0..-2].join('.')
45
45
  return nil if parent.empty?
46
+
46
47
  find_valid_parent_node(parent, new_version, max_depth)
47
48
  end
48
49
  end
@@ -0,0 +1,5 @@
1
+ module VRT
2
+ module Errors
3
+ class MappingNotFound < StandardError; end
4
+ end
5
+ end
@@ -41,15 +41,20 @@ module VRT
41
41
  private
42
42
 
43
43
  def valid_identifier?(vrt_id)
44
- # At least one string of lowercase or _, plus up to 2 more with stops
45
- @_valid_identifiers[vrt_id] ||= vrt_id =~ /other|\A[a-z_\d]+(\.[a-z_\d]+){0,2}\z/
44
+ # The upstream json schema in the VRT has changed so we need to support both:
45
+ # Current: At least one string of lowercase letters or _, plus up to 2 more with stops (no digits)
46
+ # and Old: At least one string of lowercase letters, numbers, or _,
47
+ # plus up to 2 more with stops and no leading numbers
48
+ @_valid_identifiers[vrt_id] ||= vrt_id =~ /other|\A[a-z][a-z_\d]*(\.[a-z][a-z_\d]*){0,2}\z/
46
49
  end
47
50
 
48
51
  def construct_lineage(string, max_depth)
49
52
  return unless valid_identifier?(string)
53
+
50
54
  lineage = ''
51
55
  walk_node_tree(string, max_depth: max_depth) do |ids, node, level|
52
56
  return unless node
57
+
53
58
  lineage += node.name
54
59
  lineage += ' > ' unless level == ids.length
55
60
  end
@@ -79,9 +84,7 @@ module VRT
79
84
 
80
85
  def build_node(memo, vrt, parent = nil)
81
86
  node = Node.new(vrt.merge('version' => @version, 'parent' => parent))
82
- if node.children?
83
- node.children = vrt['children'].reduce({}) { |m, v| build_node(m, v, node) }
84
- end
87
+ node.children = vrt['children'].reduce({}) { |m, v| build_node(m, v, node) } if node.children?
85
88
  memo[node.id] = node
86
89
  memo
87
90
  end
@@ -39,8 +39,9 @@ module VRT
39
39
  def load_mappings
40
40
  @mappings = {}
41
41
  VRT.versions.each do |version|
42
- filename = VRT::DIR.join(version, 'mappings', "#{@scheme}.json")
42
+ filename = mapping_file_path(version)
43
43
  next unless File.file?(filename)
44
+
44
45
  mapping = JSON.parse(File.read(filename))
45
46
  mapping['content'] = key_by_id(mapping['content'])
46
47
  @mappings[version] = mapping
@@ -48,6 +49,15 @@ module VRT
48
49
  # so this will end up as the earliest version with a mapping file
49
50
  @min_version = version
50
51
  end
52
+ raise VRT::Errors::MappingNotFound if @mappings.empty?
53
+ end
54
+
55
+ def mapping_file_path(version)
56
+ filename = VRT::DIR.join(version, 'mappings', "#{@scheme}.json")
57
+ return filename if File.file?(filename)
58
+
59
+ # Supports mappings that are nested under their scheme name e.g. `mappings/cvss/cvss.json`
60
+ VRT::DIR.join(version, 'mappings', @scheme, "#{@scheme}.json")
51
61
  end
52
62
 
53
63
  # Converts arrays to hashes keyed by the id attribute (as a symbol) for easier lookup. So
@@ -71,6 +81,7 @@ module VRT
71
81
  id_list.each do |id|
72
82
  entry = mapping[id]
73
83
  break unless entry # mapping file doesn't go this deep, return previous value
84
+
74
85
  best_guess = merge_arrays(best_guess, entry[key]) if entry[key]
75
86
  # use the children mapping for the next iteration
76
87
  mapping = entry['children'] || {}
@@ -1,3 +1,3 @@
1
1
  module Vrt
2
- VERSION = '0.7.1'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vrt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Barnett Klane
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-11-27 00:00:00.000000000 Z
13
+ date: 2019-03-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -27,7 +27,7 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  version: '1.14'
29
29
  - !ruby/object:Gem::Dependency
30
- name: rake
30
+ name: pry
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - ">="
@@ -41,7 +41,7 @@ dependencies:
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  - !ruby/object:Gem::Dependency
44
- name: rspec
44
+ name: rake
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
@@ -55,33 +55,33 @@ dependencies:
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  - !ruby/object:Gem::Dependency
58
- name: rubocop
58
+ name: rspec
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - '='
61
+ - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 0.48.1
63
+ version: '0'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - '='
68
+ - - ">="
69
69
  - !ruby/object:Gem::Version
70
- version: 0.48.1
70
+ version: '0'
71
71
  - !ruby/object:Gem::Dependency
72
- name: pry
72
+ name: rubocop
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ">="
75
+ - - '='
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: 0.56.0
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - ">="
82
+ - - '='
83
83
  - !ruby/object:Gem::Version
84
- version: '0'
84
+ version: 0.56.0
85
85
  description:
86
86
  email:
87
87
  - barnett@bugcrowd.com
@@ -136,10 +136,20 @@ files:
136
136
  - lib/data/1.6/mappings/remediation_advice.schema.json
137
137
  - lib/data/1.6/vrt.schema.json
138
138
  - lib/data/1.6/vulnerability-rating-taxonomy.json
139
+ - lib/data/1.7/deprecated-node-mapping.json
140
+ - lib/data/1.7/mappings/cvss_v3/cvss_v3.json
141
+ - lib/data/1.7/mappings/cvss_v3/cvss_v3.schema.json
142
+ - lib/data/1.7/mappings/cwe/cwe.json
143
+ - lib/data/1.7/mappings/cwe/cwe.schema.json
144
+ - lib/data/1.7/mappings/remediation_advice/remediation_advice.json
145
+ - lib/data/1.7/mappings/remediation_advice/remediation_advice.schema.json
146
+ - lib/data/1.7/vrt.schema.json
147
+ - lib/data/1.7/vulnerability-rating-taxonomy.json
139
148
  - lib/generators/vrt.rb
140
149
  - lib/generators/vrt/install_generator.rb
141
150
  - lib/vrt.rb
142
151
  - lib/vrt/cross_version_mapping.rb
152
+ - lib/vrt/errors.rb
143
153
  - lib/vrt/map.rb
144
154
  - lib/vrt/mapping.rb
145
155
  - lib/vrt/node.rb
@@ -164,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
174
  version: '0'
165
175
  requirements: []
166
176
  rubyforge_project:
167
- rubygems_version: 2.6.12
177
+ rubygems_version: 2.7.6
168
178
  signing_key:
169
179
  specification_version: 4
170
180
  summary: Ruby wrapper for Bugcrowd's Vulnerability Rating Taxonomy