Skip to content

Commit

Permalink
Use shellquote to properly escape the username/password for jenkins-s…
Browse files Browse the repository at this point in the history
…lave defaults

References voxpupuli#374
Fixes voxpupuli#371
  • Loading branch information
R. Tyler Croy committed Oct 11, 2015
1 parent d3b32f6 commit 0897b2f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 4 additions & 1 deletion manifests/slave.pp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
$slave_name = undef,
$description = undef,
$masterurl = undef,
$autodiscoveryaddress = undef,
$autodiscoveryaddress = undef,
$ui_user = undef,
$ui_pass = undef,
$version = $jenkins::params::swarm_version,
Expand All @@ -99,6 +99,9 @@

$client_jar = "swarm-client-${version}-jar-with-dependencies.jar"
$client_url = "http://maven.jenkins-ci.org/content/repositories/releases/org/jenkins-ci/plugins/swarm-client/${version}/"
$quoted_ui_user = shellquote($ui_user)
$quoted_ui_pass = shellquote($ui_pass)


if $install_java and ($::osfamily != 'Darwin') {
# Currently the puppetlabs/java module doesn't support installing Java on
Expand Down
19 changes: 19 additions & 0 deletions spec/classes/jenkins_slave_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@
with_content(/--toolLocation Python-2.7=\/usr\/bin\/python2.7/).
with_content(/--toolLocation Java-1.8=\/usr\/bin\/java/) }
end

describe 'with a UI user/password' do
let(:user) { '"frank"' }
let(:password) { "abignale's" }
let(:params) do
{
:ui_user => user,
:ui_pass => password,
}
end

it 'should escape the user' do
should contain_file(slave_runtime_file).with_content(/^JENKINS_USERNAME='#{user}'$/)
end

it 'should escape the password' do
should contain_file(slave_runtime_file).with_content(/^JENKINS_PASSWORD="#{password}"$/)
end
end
end

shared_examples 'using slave_name' do
Expand Down
6 changes: 3 additions & 3 deletions templates/jenkins-slave-defaults.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ FSROOT="<%= @slave_home -%>"

DESCRIPTION="<%= @description -%>"

# credentials should be single quoted
JENKINS_USERNAME="'<%= @ui_user.gsub!(/^\'|\'?$/, '') -%>'"
JENKINS_PASSWORD="'<%= @ui_pass.gsub!(/^\'|\'?$/, '') -%>'"
# credentials should be sinjle quoted
JENKINS_USERNAME=<%= @quoted_ui_user %>
JENKINS_PASSWORD=<%= @quoted_ui_pass %>

OTHER_ARGS="<%= '-disableSslVerification' if @disable_ssl_verification -%>"

Expand Down

0 comments on commit 0897b2f

Please sign in to comment.