summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Gemfile.lock6
-rw-r--r--license-management.gemspec1
-rw-r--r--spec/fixtures/v2.0_schema.json16
-rw-r--r--spec/integration/python/pipenv_spec.rb51
-rw-r--r--spec/spec_helper.rb2
-rw-r--r--spec/support/matchers.rb13
6 files changed, 87 insertions, 2 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index abe9075..60f69d1 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -8,7 +8,11 @@ PATH
GEM
remote: https://rubygems.org/
specs:
+ addressable (2.7.0)
+ public_suffix (>= 2.0.2, < 5.0)
diff-lcs (1.3)
+ json-schema (2.8.1)
+ addressable (>= 2.4)
license_finder (5.11.1)
bundler
rubyzip (>= 1, < 3)
@@ -18,6 +22,7 @@ GEM
xml-simple
net-hippie (0.3.0)
parslet (1.8.2)
+ public_suffix (4.0.3)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
@@ -42,6 +47,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ json-schema (~> 2.8)
license-management!
rspec (~> 3.9)
diff --git a/license-management.gemspec b/license-management.gemspec
index 492fd2d..60ab5e1 100644
--- a/license-management.gemspec
+++ b/license-management.gemspec
@@ -29,5 +29,6 @@ Gem::Specification.new do |spec|
spec.add_dependency 'license_finder', '~> 5.11'
spec.add_dependency 'net-hippie', '~> 0.3'
+ spec.add_development_dependency 'json-schema', '~> 2.8'
spec.add_development_dependency 'rspec', '~> 3.9'
end
diff --git a/spec/fixtures/v2.0_schema.json b/spec/fixtures/v2.0_schema.json
new file mode 100644
index 0000000..bd304ce
--- /dev/null
+++ b/spec/fixtures/v2.0_schema.json
@@ -0,0 +1,16 @@
+{
+ "$id": "https://gitlab.com/gitlab-org/security-products/license-management/blob/master/spec/fixtures/v2.0_schema.json",
+ "type": "object",
+ "required": [
+ "version",
+ "licenses",
+ "dependencies"
+ ],
+ "properties": {
+ "version": { "type": "string" },
+ "licenses": { "type": "array" },
+ "dependencies": { "type": "array" }
+ },
+ "additionalProperties": false
+}
+
diff --git a/spec/integration/python/pipenv_spec.rb b/spec/integration/python/pipenv_spec.rb
index 15e48dc..6039b25 100644
--- a/spec/integration/python/pipenv_spec.rb
+++ b/spec/integration/python/pipenv_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
RSpec.describe "pipenv" do
- context "when a project depends on a Pipfile.lock" do
+ context "when a project depends on a version 6 Pipfile.lock" do
let(:pipfile_lock_content) do
JSON.pretty_generate({
"_meta": {
@@ -23,8 +23,55 @@ RSpec.describe "pipenv" do
report = runner.scan
expect(report).not_to be_empty
- expect(report[:version]).to start_with('2')
+ expect(report[:version]).not_to be_empty
+ expect(report[:licenses]).not_to be_empty
expect(report[:dependencies].map { |x| x[:name] }).to include("six")
end
end
+
+ context "when a project depends on a version 3.2.1 Pipfile.lock" do
+ let(:pipfile_lock_content) do
+ JSON.pretty_generate({
+ "default": {
+ "crayons": { "version": "==0.1.2", "hash": "" },
+ "requirements-parser": { "version": "==0.1.0", "hash": "" },
+ "pexpect": { "version": "==4.2.1", "hash": "" },
+ "delegator.py": { "version": "==0.0.8", "hash": "" },
+ "backports.shutil_get_terminal_size": { "version": "==1.0.0", "hash": "" },
+ "ptyprocess": { "version": "==0.5.1", "hash": "" },
+ "parse": { "version": "==1.6.6", "hash": "" },
+ "toml": { "version": "==0.9.2", "hash": "" },
+ "colorama": { "version": "==0.3.7", "hash": "" },
+ "requests": { "version": "==2.13.0", "hash": "" },
+ "click": { "version": "==6.7", "hash": "" }
+ },
+ "develop": {
+ "packaging": { "version": "==16.8", "hash": "" },
+ "pytest": { "version": "==3.0.6", "hash": "" },
+ "setuptools": { "version": "==34.0.2", "hash": "" },
+ "pyparsing": { "version": "==2.1.10", "hash": "" },
+ "py": { "version": "==1.4.32", "hash": "" },
+ "six": { "version": "==1.10.0", "hash": "" },
+ "appdirs": { "version": "==1.4.0", "hash": "" }
+ },
+ "_meta": {
+ "sources": [ { "url": "https://pypi.python.org/simple", "verify_ssl": true } ],
+ "requires": {},
+ "Pipfile-sha256": "24f12b631b7c40b8c5eff934a1aef263ed04f5eaffb4acf4706442f3d23cba36"
+ }
+ })
+ end
+
+ it 'produces a valid report' do
+ runner.add_file('Pipfile.lock', pipfile_lock_content)
+
+ report = runner.scan
+
+ expect(report).to match_schema(version: '2.0')
+ expect(report).not_to be_empty
+ expect(report[:version]).not_to be_empty
+ expect(report[:licenses]).not_to be_empty
+ expect(report[:dependencies].count).to eql(18)
+ end
+ end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 115822b..1889335 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,7 +1,9 @@
require 'license/management'
require 'json'
require 'securerandom'
+require 'json-schema'
require 'support/integration_test_helper'
+require 'support/matchers'
RSpec.configure do |config|
config.include IntegrationTestHelper, type: :integration
diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb
new file mode 100644
index 0000000..bb54d19
--- /dev/null
+++ b/spec/support/matchers.rb
@@ -0,0 +1,13 @@
+RSpec::Matchers.define :match_schema do |version: nil, **options|
+ match do |actual|
+ path = License::Management.root.join("spec/fixtures/v#{version}_schema.json")
+ schema = JSON.parse(IO.read(path))
+ @errors = JSON::Validator.fully_validate(schema, actual, options)
+ @errors.empty?
+ end
+
+ failure_message do |response|
+ "didn't match the schema for version #{version}" \
+ " The validation errors were:\n#{@errors.join("\n")}"
+ end
+end