-
Notifications
You must be signed in to change notification settings - Fork 97
/
spec_helper_acceptance.rb
147 lines (134 loc) · 5.09 KB
/
spec_helper_acceptance.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
require 'beaker-rspec/spec_helper'
require 'beaker-rspec/helpers/serverspec'
UNSUPPORTED_PLATFORMS = []
unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
# This will install the latest available package on el and deb based
# systems fail on windows and osx, and install via gem on other *nixes
foss_opts = {:default_action => 'gem_install', :version => '3.7.1'}
if default.is_pe?; then
install_pe;
else
install_puppet(foss_opts);
end
hosts.each do |host|
if host['platform'] !~ /windows/i
on host, 'puppet master'
on host, "mkdir -p #{host['distmoduledir']}"
elsif host["platform"] =~ /solaris/
on host, "echo 'export PATH=/opt/puppet/bin:/var/ruby/1.8/gem_home/bin:${PATH}' >> ~/.bashrc"
elsif host.is_pe?
on host, "echo 'export PATH=#{host['puppetbindir']}:${PATH}' >> ~/.bashrc"
end
on host, "mkdir -p #{host['distmoduledir']}"
end
end
def create_keys_for_test(host)
# Generate private key and CA for keystore
if host['platform'] =~ /windows/i
cmd = 'env PATH="$( [ -d "/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/sys/ruby/bin" ]'
cmd += ' && echo "/cygdrive/c/Program Files (x86)" || echo "/cygdrive/c/Program Files" )/Puppet Labs/Puppet/sys/ruby/bin:${PATH}" ruby -e'
temp_dir = 'C:\\tmp\\'
on host, 'mkdir /cygdrive/c/tmp'
else
path = '${PATH}'
path = "/opt/csw/bin:#{path}" # Need ruby's path on solaris 10 (foss)
path = "/opt/puppet/bin:#{path}" # But try PE's ruby first
cmd = "PATH=#{path} ruby -e"
temp_dir = '/tmp/'
end
# Need to check for ruby path on puppet install, use vendor ruby and add it to the path durring execution
tmp_privky = "#{temp_dir}privkey.pem"
tmp_ca = "#{temp_dir}ca.pem"
tmp_ca2 = "#{temp_dir}ca2.pem"
tmp_chain = "#{temp_dir}chain.pem"
opensslscript =<<EOS
require 'openssl'
key = OpenSSL::PKey::RSA.new 1024
ca = OpenSSL::X509::Certificate.new
ca.serial = 1
ca.public_key = key.public_key
subj = '/CN=Test CA/ST=Denial/L=Springfield/O=Dis/CN=www.example.com'
ca.subject = OpenSSL::X509::Name.parse subj
ca.issuer = ca.subject
ca.not_before = Time.now
ca.not_after = ca.not_before + 360
ca.sign(key, OpenSSL::Digest::SHA256.new)
key2 = OpenSSL::PKey::RSA.new 1024
ca2 = OpenSSL::X509::Certificate.new
ca2.serial = 2
ca2.public_key = key2.public_key
subj2 = '/CN=Test CA/ST=Denial/L=Springfield/O=Dis/CN=www.example.com'
ca2.subject = OpenSSL::X509::Name.parse subj2
ca2.issuer = ca2.subject
ca2.not_before = Time.now
ca2.not_after = ca2.not_before + 360
ca2.sign(key2, OpenSSL::Digest::SHA256.new)
chain = OpenSSL::X509::Certificate.new
chain.serial = 1
chain.public_key = key.public_key
chain_subj = '/CN=Chain CA/ST=Denial/L=Springfield/O=Dis/CN=www.example.net'
chain.subject = OpenSSL::X509::Name.parse chain_subj
chain.issuer = chain.subject
chain.not_before = Time.now
chain.not_after = chain.not_before + 360
chain.sign(key, OpenSSL::Digest::SHA256.new)
File.open('#{tmp_privky}', 'w') { |f| f.write key.to_pem }
File.open('#{tmp_ca}', 'w') { |f| f.write ca.to_pem }
File.open('#{tmp_ca2}', 'w') { |f| f.write ca2.to_pem }
File.open('#{tmp_chain}', 'w') { |f| f.write chain.to_pem }
EOS
on host, "#{cmd} \"#{opensslscript}\""
end
RSpec.configure do |c|
# Project root
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
# Readable test descriptions
c.formatter = :documentation
# Configure all nodes in nodeset
c.before :suite do
# Install module and dependencies
hosts.each do |host|
create_keys_for_test(host)
copy_module_to(host, :source => proj_root, :module_name => 'java_ks')
#install java if windows
if host['platform'] =~ /windows/i
exec_puppet = <<EOS
exec{'Download':
command => 'powershell.exe -command "Invoke-WebRequest https://forge.puppetlabs.com"',
path => ['c:\\windows\\sysnative\\WindowsPowershell\\v1.0','c:\\windows\\system32\\WindowsPowershell\\v1.0'],
}
EOS
on host, apply_manifest(exec_puppet)
on host, puppet('module install cyberious-windows_java')
else
on host, puppet('module install puppetlabs-java')
on host, puppet('module', 'install', 'puppetlabs-java'), {:acceptable_exit_codes => [0, 1]}
end
end
end
end
RSpec.shared_context 'common variables' do
before {
java_major, java_minor = (ENV['JAVA_VERSION'] || '7u67').split('u')
@ensure_ks = 'latest'
@temp_dir = '/tmp/'
@resource_path = "undef"
@target = '/etc/truststore.ts'
case fact('osfamily')
when "Solaris"
@keytool_path = '/usr/java/bin/'
@resource_path = "['/usr/java/bin/','/opt/puppet/bin/']"
@target = '/etc/truststore.ts'
when "AIX"
@keytool_path = '/usr/java6/bin/'
@resource_path = "['/usr/java6/bin/','/usr/bin/']"
@target = '/etc/truststore.ts'
when 'windows'
@ensure_ks = 'present'
@keytool_path = "C:/Java/jdk1.#{java_major}.0_#{java_minor}/bin/"
@target = 'c:/truststore.ts'
@temp_dir = 'C:/tmp/'
@resource_path = "['C:/Java/jdk1.#{java_major}.0_#{java_minor}/bin/']"
end
}
end