Skip to content

Commit

Permalink
Validate advisories through schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Oct 22, 2019
1 parent ec04dbd commit 57a1de7
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ source 'https://rubygems.org'

gem 'faraday'
gem 'rake'
gem 'kwalify'
gem 'rspec'

group :development do
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ GEM
diff-lcs (1.3)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
kwalify (0.7.2)
method_source (0.9.0)
mini_portile2 (2.4.0)
multipart-post (2.1.1)
Expand Down Expand Up @@ -33,6 +34,7 @@ PLATFORMS

DEPENDENCIES
faraday
kwalify
nokogiri
pry
rake
Expand Down
7 changes: 7 additions & 0 deletions spec/gem_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
include_examples 'Advisory', path

advisory = YAML.load_file(path)
schema = YAML.load_file(File.join(File.dirname(__FILE__), 'schemas/gem.yml'))
validator = Kwalify::Validator.new(schema)

describe path do
let(:gem) { File.basename(File.dirname(path)) }
Expand Down Expand Up @@ -33,5 +35,10 @@
end
end
end

it "should have valid schema" do
errors = validator.validate(advisory)
expect(errors).to be_empty
end
end
end
9 changes: 8 additions & 1 deletion spec/ruby_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

shared_examples_for "Rubies Advisory" do |path|
include_examples 'Advisory', path

advisory = YAML.load_file(path)
schema = YAML.load_file(File.join(File.dirname(__FILE__), 'schemas/ruby.yml'))
validator = Kwalify::Validator.new(schema)

describe path do
let(:engine) { File.basename(File.dirname(path)) }
Expand All @@ -17,6 +19,11 @@
expect(subject.downcase).to eq(engine.downcase)
end
end

it "should have valid schema" do
errors = validator.validate(advisory)
expect(errors).to be_empty
end
end
end

64 changes: 64 additions & 0 deletions spec/schemas/gem.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
type: map
mapping:
"gem":
type: str
required: yes
"library":
type: str
"framework":
type: str
"platform":
type: str
"cve":
type: str
pattern: /\d+-\d+/
"osvdb":
type: int
"ghsa":
type: str
"url":
type: str
required: true
pattern: /https?:\/\//
"title":
type: str
required: true
"date":
type: date
required: true
"description":
type: str
required: true
"cvss_v2":
type: float
"cvss_v3":
type: float
"unaffected_versions":
type: seq
sequence:
- type: str
"patched_versions":
type: seq
sequence:
- type: str
"vendor_patch":
type: seq
sequence:
- type: str
pattern: /https?:\/\//
"related":
type: map
mapping:
"cve":
type: seq
sequence:
- type: str
"osvdb":
type: seq
sequence:
- type: int
"url":
type: seq
sequence:
- type: str
pattern: /https?:\/\//
36 changes: 36 additions & 0 deletions spec/schemas/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
type: map
mapping:
"engine":
type: str
required: yes
enum: [jruby, rbx, ruby]
"cve":
type: str
pattern: /\d+-\d+/
"osvdb":
type: int
"url":
type: str
required: true
pattern: /https?:\/\//
"title":
type: str
required: true
"date":
type: date
required: true
"description":
type: str
required: true
"cvss_v2":
type: float
"cvss_v3":
type: float
"unaffected_versions":
type: seq
sequence:
- type: str
"patched_versions":
type: seq
sequence:
- type: str
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require 'kwalify'
require 'rspec'

0 comments on commit 57a1de7

Please sign in to comment.