Skip to content

Commit

Permalink
Add specs to ensure there are no "double reported" advisories.
Browse files Browse the repository at this point in the history
* All advisory files must contain a unique CVE ID and GHSA ID *per*
  directory.
  • Loading branch information
postmodern committed Apr 21, 2023
1 parent d7288e6 commit c6157ef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/advisories_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
load File.join(File.dirname(__FILE__), 'spec_helper.rb')
require 'gem_advisory_example'
require 'ruby_advisory_example'
require 'advisory_dir_example'

describe "gems" do
Dir.glob(File.join(File.dirname(__FILE__), '../gems/*/*')) do |path|
include_examples 'Gem Advisory', path
end

Dir.glob(File.join(File.dirname(__FILE__), '../gems/*')) do |dir|
include_examples 'Advisory Directory', dir
end
end

describe "rubies" do
Dir.glob(File.join(File.dirname(__FILE__), '../rubies/*/*')) do |path|
include_examples 'Rubies Advisory', path
end

Dir.glob(File.join(File.dirname(__FILE__), '../rubies/*')) do |dir|
include_examples 'Advisory Directory', dir
end
end
27 changes: 27 additions & 0 deletions spec/advisory_dir_example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'rspec'
require 'date'

shared_examples_for "Advisory Directory" do |dir|
describe dir do
let(:advisory_paths) { Dir.glob(File.join(dir,'*.yml')) }
let(:advisories) do
advisory_paths.map do |path|
YAML.safe_load_file(path, permitted_classes: [Date])
end
end

it "must not contain duplicate CVE IDs" do
cve_ids = advisories.map { |advisory| advisory['cve'] }
cve_ids.compact!

expect(cve_ids).to eq(cve_ids.uniq)
end

it "must not contain duplicate GHSA IDs" do
ghsa_ids = advisories.map { |advisory| advisory['ghsa'] }.compact
ghsa_ids.compact!

expect(ghsa_ids).to eq(ghsa_ids.uniq)
end
end
end

0 comments on commit c6157ef

Please sign in to comment.