Skip to content

Commit

Permalink
Updating the powershell and the specs to use certificate thumbprint r…
Browse files Browse the repository at this point in the history
…ather than certificate name
  • Loading branch information
stack72 committed Apr 14, 2014
1 parent 077e959 commit 2d1e659
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions manifests/manage_binding.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define iis::manage_binding($site_name, $protocol, $port, $host_header = '', $ip_address = '*', $certificate_name = '', $ensure = 'present') {
define iis::manage_binding($site_name, $protocol, $port, $host_header = '', $ip_address = '*', $certificate_thumbprint = '', $ensure = 'present') {
include 'iis::param::powershell'

if ! ($protocol in [ 'http', 'https', 'net.tcp', 'net.pipe', 'netmsmq', 'msmq.formatname' ]) {
Expand All @@ -23,15 +23,15 @@
}

if ($protocol == 'https') {
validate_re($certificate_name, ['^(.)+$'], 'certificate_name required for https bindings')
validate_re($certificate_thumbprint, ['^(.)+$'], 'certificate_thumbprint required for https bindings')
if ($ip_address == '*' or $ip_address == '0.0.0.0') {
fail('https bindings require a valid ip_address')
}

exec { "Attach-Certificate-${title}":
path => "${iis::param::powershell::path};${::path}",
command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; New-Item \\\"IIS:\\SslBindings\\${ip_address}!${port}\\\" -Value (Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.FriendlyName.Equals(\\\"${certificate_name}\\\")} | Select-Object -First 1)\"",
onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.FriendlyName.Equals(\\\"${certificate_name}\\\")} | Select-Object -First 1) -and ((Test-Path \\\"IIS:\\SslBindings\\${ip_address}!${port}\\\") -eq \$false)) { exit 0 } else { exit 1 }\"",
command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; New-Item \\\"IIS:\\SslBindings\\${ip_address}!${port}\\\" -Value (Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.Thumbprint.Equals(\\\"${certificate_thumbprint}\\\")} | Select-Object -First 1)\"",
onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.Thumbprint.Equals(\\\"${certificate_thumbprint}\\\")} | Select-Object -First 1) -and ((Test-Path \\\"IIS:\\SslBindings\\${ip_address}!${port}\\\") -eq \$false)) { exit 0 } else { exit 1 }\"",
require => Exec["CreateBinding-${title}"],
logoutput => true,
}
Expand Down
12 changes: 6 additions & 6 deletions spec/defines/manage_binding_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@
:ip_address => '127.0.0.1',
} }

it { expect { should contain_exec('Attach-Certificate-myWebSite-port-443')}.to raise_error(Puppet::Error, /certificate_name required for https bindings/) }
it { expect { should contain_exec('Attach-Certificate-myWebSite-port-443')}.to raise_error(Puppet::Error, /certificate_thumbprint required for https bindings/) }
end

describe 'when protocol is https and ip address *' do
let(:title) { 'myWebSite-port-443' }
let(:params) { {
:site_name => 'myWebSite',
:certificate_name => 'myCertificate',
:certificate_thumbprint => 'myCertificate',
:protocol => 'https',
:port => '443',
:ip_address => '*',
Expand All @@ -102,7 +102,7 @@
let(:title) { 'myWebSite-port-443' }
let(:params) { {
:site_name => 'myWebSite',
:certificate_name => 'myCertificate',
:certificate_thumbprint => 'myCertificate',
:protocol => 'https',
:port => '443',
:ip_address => '0.0.0.0',
Expand All @@ -115,15 +115,15 @@
let(:title) { 'myWebSite-port-443' }
let(:params) { {
:site_name => 'myWebSite',
:certificate_name => 'myCertificate',
:certificate_thumbprint => 'myCertificate',
:protocol => 'https',
:port => '443',
:ip_address => '127.0.0.1',
} }

it { should contain_exec('Attach-Certificate-myWebSite-port-443').with({
'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-Item \\\"IIS:\\SslBindings\\127.0.0.1!443\\\" -Value (Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.FriendlyName.Equals(\\\"myCertificate\\\")} | Select-Object -First 1)\"",
'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.FriendlyName.Equals(\\\"myCertificate\\\")} | Select-Object -First 1) -and ((Test-Path \\\"IIS:\\SslBindings\\127.0.0.1!443\\\") -eq \$false)) { exit 0 } else { exit 1 }\"",
'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-Item \\\"IIS:\\SslBindings\\127.0.0.1!443\\\" -Value (Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.Thumbprint.Equals(\\\"myCertificate\\\")} | Select-Object -First 1)\"",
'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.Thumbprint.Equals(\\\"myCertificate\\\")} | Select-Object -First 1) -and ((Test-Path \\\"IIS:\\SslBindings\\127.0.0.1!443\\\") -eq \$false)) { exit 0 } else { exit 1 }\"",
})}
end

Expand Down

0 comments on commit 2d1e659

Please sign in to comment.