Skip to content

Commit

Permalink
add check to make sure the license is present (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrero authored and jgawor committed Aug 23, 2016
1 parent 9ae7977 commit 6afddf3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/liberty_buildpack/util/license_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ def self.check_license(license_uri, license_id)

# The below regex ignores white space and grabs anything between the first occurrence of "D/N:" and "<".
LibertyBuildpack::Util::Cache::ApplicationCache.new.get(license_uri) do |file|
license = file.read.force_encoding('ISO-8859-1').scan(/D\/N:\s*(.*?)\s*\</m).last.first
scanned_license = file.read.force_encoding('ISO-8859-1').scan(/D\/N:\s*(.*?)\s*\</m)
if scanned_license.empty?
raise 'No D/N code found in the license file'
else
license = scanned_license.first.last
end

return license_id == license
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/license2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body>Nothing Here<br></body></html>
30 changes: 30 additions & 0 deletions spec/liberty_buildpack/container/liberty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2004,5 +2004,35 @@ def run(root, configuration = default_configuration)

end

describe 'Expect license error if not in license html' do

def run(root, env = {})
set_liberty_fixture('spec/fixtures/wlp-stub.tar.gz')

Liberty.new(
app_dir: root,
lib_directory: '',
configuration: default_configuration,
environment: env,
license_ids: { 'IBM_LIBERTY_LICENSE' => '1234-ABCD' }
).compile
end

before do
# return license file by default
application_cache.stub(:get).and_yield(File.open('spec/fixtures/license2.html'))
end

it 'should raise error' do
Dir.mktmpdir do |root|
FileUtils.cp_r('spec/fixtures/container_liberty/.', root)
env = { 'JBP_CONFIG_LIBERTY' => '[features: blah, app_archive: {feature: [jsp-2.2]}]' }
expect { run(root, env) }.to raise_error(/No\ D\/N\ code\ found\ in\ the\ license\ file/)

end
end

end

end
end

0 comments on commit 6afddf3

Please sign in to comment.