Skip to content

Commit

Permalink
Merge branch '578-contrast-override-application-name'
Browse files Browse the repository at this point in the history
  • Loading branch information
nebhale committed Apr 18, 2018
2 parents 978e329 + cb3539f commit ab809a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/java_buildpack/framework/contrast_security_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ def compile

# (see JavaBuildpack::Component::BaseComponent#release)
def release
@droplet.java_opts.add_system_property('contrast.override.appname', application_name) unless appname_exist?

@droplet.java_opts
.add_system_property('contrast.dir', '$TMPDIR')
.add_system_property('contrast.override.appname', application_name)
.add_preformatted_options("-javaagent:#{qualify_path(@droplet.sandbox + jar_name, @droplet.root)}=" \
"#{qualify_path(contrast_config, @droplet.root)}")
end
Expand Down Expand Up @@ -109,6 +110,10 @@ def application_name
@application.details['application_name'] || 'ROOT'
end

def appname_exist?
@droplet.java_opts.any? { |java_opt| java_opt =~ /contrast.override.appname/ }
end

def contrast_config
@droplet.sandbox + 'contrast.config'
end
Expand Down
9 changes: 9 additions & 0 deletions spec/java_buildpack/framework/contrast_security_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@
expect(sandbox + 'contrast.config').to exist
end

it 'does not override app name if there is an existing appname' do
java_opts.add_system_property('contrast.override.appname', 'NAME_ALREADY_OVERRIDDEN')

component.release

expect(java_opts).to include('-Dcontrast.override.appname=NAME_ALREADY_OVERRIDDEN')
expect(java_opts).not_to include('-Dcontrast.override.appname=test-application-name')
end

end

end

0 comments on commit ab809a5

Please sign in to comment.