update unit tests

Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
This commit is contained in:
Christoph Hartmann 2017-05-29 18:16:09 -04:00
parent a6ef98c896
commit 687f1a5827
11 changed files with 117 additions and 8 deletions

View file

@ -124,7 +124,7 @@ module Inspec
# if version is set, ensure it is in SPDX format
if !params[:license].nil? && !Spdx.valid_license?(params[:license])
errors.push("License '#{params[:license]}' needs to be in SPDX format. See https://spdx.org/licenses/.")
warnings.push("License '#{params[:license]}' needs to be in SPDX format. See https://spdx.org/licenses/.")
end
[errors, warnings]

View file

@ -340,4 +340,5 @@ LGPL-2.1+
LGPL-3.0+
LGPL-2.0+
StandardML-NJ
WXwindows
WXwindows
All Rights Reserved

View file

@ -55,10 +55,10 @@ describe 'inspec exec with json formatter' do
"maintainer" => "Chef Software, Inc.",
"copyright" => "Chef Software, Inc.",
"copyright_email" => "support@chef.io",
"license" => "Apache 2 license",
"license" => "Apache-2.0",
"summary" => "Demonstrates the use of InSpec Compliance Profile",
"version" => "1.0.0",
"sha256" => "dc106310cc44b877b6ebf4fae786fb6d0b88bc2660e36b360e8ef28cae8fbfc5",
"sha256" => "821f866e407a91cfadb44af5d4570b92ac7f7a272025da7aa9a92aa635cc4440",
"supports" => [{"os-family" => "unix"}],
"attributes" => []
})

View file

@ -4,6 +4,7 @@ maintainer: bob
title: title
copyright: left
summary: nothing
license: Apache-2.0
supports:
- linux
- darwin

View file

@ -6,5 +6,6 @@ copyright_email: support@chef.io
license: Proprietary, All rights reserved
summary: Testing stub
version: 1.0.0
license: Apache-2.0
supports:
- os-family: linux

View file

@ -3,6 +3,6 @@ title: InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com
license: All Rights Reserved
license: Apache-2.0
summary: An InSpec Compliance Profile
version: 0.1.0.999

View file

@ -5,3 +5,4 @@ title 'title'
copyright 'left'
summary 'nothing'
supports 'linux'
license 'Apache-2.0'

View file

@ -0,0 +1,8 @@
name: license-invalid
title: InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com
license: Invalid License Name
summary: An InSpec Compliance Profile
version: 0.1.0

View file

@ -0,0 +1,8 @@
name: license-proprietary
title: InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com
license: All Rights Reserved
summary: An InSpec Compliance Profile
version: 0.1.0

View file

@ -0,0 +1,8 @@
name: license-spdx
title: InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com
license: Apache-2.0
summary: An InSpec Compliance Profile
version: 0.1.0

View file

@ -70,7 +70,7 @@ describe Inspec::Profile do
end
it 'works on a complete profile' do
MockLoader.load_profile('complete-profile').sha256.must_equal '41ce15e61b7e02aad5dade183f68c547e062f1390762d266c5c8cf96d49134c7'
MockLoader.load_profile('complete-profile').sha256.must_equal 'f9dbfad594ff9eff2209c8a791a1a88a0330f3d3800395e56acf981e4cc5e236'
end
end
@ -112,6 +112,7 @@ describe Inspec::Profile do
logger.expect :warn, nil, ["Missing profile summary in inspec.yml"]
logger.expect :warn, nil, ["Missing profile maintainer in inspec.yml"]
logger.expect :warn, nil, ["Missing profile copyright in inspec.yml"]
logger.expect :warn, nil, ["Missing profile license in inspec.yml"]
logger.expect :warn, nil, ['No controls or tests were defined.']
result = MockLoader.load_profile(profile_id, {logger: logger}).check
@ -124,7 +125,7 @@ describe Inspec::Profile do
result[:summary][:profile].must_match(/tests from .*empty-metadata/)
result[:summary][:controls].must_equal 0
result[:errors].length.must_equal 1
result[:warnings].length.must_equal 5
result[:warnings].length.must_equal 6
end
end
@ -139,6 +140,7 @@ describe Inspec::Profile do
logger.expect :warn, nil, ["Missing profile summary in metadata.rb"]
logger.expect :warn, nil, ["Missing profile maintainer in metadata.rb"]
logger.expect :warn, nil, ["Missing profile copyright in metadata.rb"]
logger.expect :warn, nil, ["Missing profile license in metadata.rb"]
logger.expect :warn, nil, ['No controls or tests were defined.']
result = MockLoader.load_profile(profile_id, {logger: logger}).check
@ -151,7 +153,7 @@ describe Inspec::Profile do
result[:summary][:profile].must_match(/tests from .*legacy-empty-metadata/)
result[:summary][:controls].must_equal 0
result[:errors].length.must_equal 1
result[:warnings].length.must_equal 6
result[:warnings].length.must_equal 7
end
end
@ -333,5 +335,84 @@ describe Inspec::Profile do
result[:warnings].length.must_equal 1
end
end
describe 'shows warning if license is invalid' do
let(:profile_id) { 'license-invalid' }
let(:profile_path) { MockLoader.profile_zip(profile_id) }
let(:profile) { MockLoader.load_profile(profile_path, {logger: logger}) }
it 'prints ok messages and counts the controls' do
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
logger.expect :warn, nil, ["License 'Invalid License Name' needs to be in SPDX format. See https://spdx.org/licenses/."]
logger.expect :warn, nil, ['No controls or tests were defined.']
logger.expect :info, nil, ["Metadata OK."]
result = MockLoader.load_profile(profile_id, {logger: logger}).check
# verify logger output
logger.verify
# verify hash result
result[:summary][:valid].must_equal true
result[:summary][:location].must_equal "#{home}/mock/profiles/#{profile_id}"
result[:summary][:profile].must_equal 'license-invalid'
result[:summary][:controls].must_equal 0
result[:errors].length.must_equal 0
result[:warnings].length.must_equal 2
end
describe 'shows no warning if license is spdx' do
let(:profile_id) { 'license-spdx' }
let(:profile_path) { MockLoader.profile_zip(profile_id) }
let(:profile) { MockLoader.load_profile(profile_path, {logger: logger}) }
it 'prints ok messages and counts the controls' do
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
logger.expect :warn, nil, ['No controls or tests were defined.']
logger.expect :info, nil, ["Metadata OK."]
result = MockLoader.load_profile(profile_id, {logger: logger}).check
# verify logger output
logger.verify
# verify hash result
result[:summary][:valid].must_equal true
result[:summary][:location].must_equal "#{home}/mock/profiles/#{profile_id}"
result[:summary][:profile].must_equal 'license-spdx'
result[:summary][:controls].must_equal 0
result[:errors].length.must_equal 0
result[:warnings].length.must_equal 1
end
end
describe 'accepts proprietary license' do
let(:profile_id) { 'license-proprietary' }
let(:profile_path) { MockLoader.profile_zip(profile_id) }
let(:profile) { MockLoader.load_profile(profile_path, {logger: logger}) }
it 'prints ok messages and counts the controls' do
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
logger.expect :warn, nil, ['No controls or tests were defined.']
logger.expect :info, nil, ["Metadata OK."]
result = MockLoader.load_profile(profile_id, {logger: logger}).check
# verify logger output
logger.verify
# verify hash result
result[:summary][:valid].must_equal true
result[:summary][:location].must_equal "#{home}/mock/profiles/#{profile_id}"
result[:summary][:profile].must_equal 'license-proprietary'
result[:summary][:controls].must_equal 0
result[:errors].length.must_equal 0
result[:warnings].length.must_equal 1
end
end
end
end
end