Skip to content

Commit

Permalink
[Changed] to recognize permitted licenses with AND in the name [#1739…
Browse files Browse the repository at this point in the history
…97648]

Signed-off-by: Jeff Jun <jjun@pivotal.io>
  • Loading branch information
ohlookadollar authored and Pivotal-Jeff-Jun committed Aug 5, 2020
1 parent 4fb5ba4 commit eab1425
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
13 changes: 9 additions & 4 deletions lib/license_finder/decisions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ def approved?(name, version = nil)
end

def permitted?(lic)
return lic.sub_licenses.any? { |sub_lic| @permitted.include?(sub_lic) } if lic.is_a?(OrLicense)
return lic.sub_licenses.all? { |sub_lic| @permitted.include?(sub_lic) } if lic.is_a?(AndLicense)

@permitted.include?(lic)
if @permitted.include?(lic)
true
elsif lic.is_a?(OrLicense)
lic.sub_licenses.any? { |sub_lic| @permitted.include?(sub_lic) }
elsif lic.is_a?(AndLicense)
lic.sub_licenses.all? { |sub_lic| @permitted.include?(sub_lic) }
else
false
end
end

def restricted?(lic)
Expand Down
15 changes: 11 additions & 4 deletions lib/license_finder/license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ def all

def find_by_name(name)
name ||= 'unknown'
return OrLicense.new(name) if name.include?(OrLicense.operator)
return AndLicense.new(name) if name.include?(AndLicense.operator)

all.detect { |l| l.matches_name? l.stripped_name(name) } || Definitions.build_unrecognized(name)
license = all.detect { |l| l.matches_name? l.stripped_name(name) }

if license
license
elsif name.include?(OrLicense.operator)
OrLicense.new(name)
elsif name.include?(AndLicense.operator)
AndLicense.new(name)
else
Definitions.build_unrecognized(name)
end
end

def find_by_text(text)
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/license_finder/decision_applier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ module LicenseFinder
expect(dep).not_to be_approved
expect(dep).not_to be_permitted
end
it 'does not mix up with non-compound license with AND' do
dep = Package.new('dep', nil, spec_licenses: ['Common Development and Distribution License 1.0'])
decisions = Decisions.new
.add_package('manual', nil)
.license('manual', 'Common Development and Distribution License 1.0')
.permit('Common Development and Distribution License 1.0')
described_class.new(decisions: decisions, packages: [dep])
expect(dep).to be_approved
expect(dep).to be_permitted
end
end
describe 'OR compound licenses' do
it 'checks at least one OR condition: success case' do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/license_finder/license/definitions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
end

describe '#matches_text?' do
fit "should return true if the text begins with 'Mozilla Public License Version 1.1'" do
it "should return true if the text begins with 'Mozilla Public License Version 1.1'" do
expect(subject).to be_matches_text 'Mozilla Public License Version 1.1'
end

Expand Down

0 comments on commit eab1425

Please sign in to comment.