Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate advisories through schemas #421

Merged
merged 1 commit into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -33,5 +33,12 @@
end
end
end

it "should have valid schema" do
schema = YAML.load_file(File.join(File.dirname(__FILE__), 'schemas/gem.yml'))
validator = Kwalify::Validator.new(schema)
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,7 +3,7 @@

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

advisory = YAML.load_file(path)

describe path do
Expand All @@ -17,6 +17,13 @@
expect(subject.downcase).to eq(engine.downcase)
end
end

it "should have valid schema" do
schema = YAML.load_file(File.join(File.dirname(__FILE__), 'schemas/ruby.yml'))
validator = Kwalify::Validator.new(schema)
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'