Class: Castanet::Testing::JasigServerTasks
- Inherits:
-
Object
- Object
- Castanet::Testing::JasigServerTasks
- Extended by:
- AssetPaths
- Includes:
- CommonTasks, Namespacing, Rake::DSL, Shellwords
- Defined in:
- lib/castanet/testing/jasig_server_tasks.rb
Constant Summary collapse
- DEFAULT_SCRATCH_DIR =
'/tmp/castanet-testing/jasig'
- DEFAULT_JASIG_URL =
'http://downloads.jasig.org/cas/cas-server-3.5.2-release.tar.gz'
- DEFAULT_JETTY_URL =
'http://archive.eclipse.org/jetty/8.1.7.v20120910/dist/jetty-distribution-8.1.7.v20120910.tar.gz'
- DEFAULT_JASIG_CHECKSUM =
'e93e05acad4975c5caa1c20dff7c57ff8e846253bbf68ea8a5fc0199ce608cba'
- DEFAULT_JETTY_CHECKSUM =
'a65d20367839bf3df7d32a05992678487ba8daeebb41d9833975aee46ffe86c2'
- DEFAULT_MOUNT_POINT =
'/cas'
- DEFAULT_HOST =
'localhost'
- DEFAULT_SSL_KEY =
ssl_key_path
- DEFAULT_SSL_CERT =
ssl_cert_path
- DEFAULT_TIMEOUT =
120
- JETTY_SSL_CONFIG_TEMPLATE =
asset_path('jasig/jetty.xml.erb')
- JETTY_CONFIG_PATCHFILE =
asset_path('jasig/jetty.xml.patch')
- RUNNER =
asset_path('jasig/run.sh')
Constants included from ConnectionTesting
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ JasigServerTasks
constructor
This is a ridiculous amount of setup for a CAS server.
Methods included from AssetPaths
asset_path, ssl_cert_path, ssl_key_path
Methods included from Namespacing
Methods included from CommonTasks
Methods included from ConnectionTesting
Constructor Details
#initialize(options = {}) ⇒ JasigServerTasks
This is a ridiculous amount of setup for a CAS server.
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/castanet/testing/jasig_server_tasks.rb', line 57 def initialize( = {}) root = [:root] || 'castanet:testing:jasig' scratch_dir = [:scratch_dir] || DEFAULT_SCRATCH_DIR jasig_url = [:jasig_url] || DEFAULT_JASIG_URL jasig_checksum = [:jasig_checksum] || DEFAULT_JASIG_CHECKSUM jetty_url = [:jetty_url] || DEFAULT_JETTY_URL jetty_checksum = [:jetty_checksum] || DEFAULT_JETTY_CHECKSUM mount_point = [:mount_point] || DEFAULT_MOUNT_POINT host = [:host] || DEFAULT_HOST ssl_cert = [:ssl_cert] || DEFAULT_SSL_CERT ssl_key = [:ssl_key] || DEFAULT_SSL_KEY timeout = [:timeout] || DEFAULT_TIMEOUT instance_dir = "#{scratch_dir}/jasig.#{$$}" port = ENV['PORT'] jasig_fn = URI.parse(jasig_url).path.split('/').last jasig_package_dest = "#{scratch_dir}/#{jasig_fn}" jasig_extract_dest = "#{scratch_dir}/#{jasig_fn}-extract" jasig_war_filename = mount_point.split('/').last + '.war' # Older versions of the Jasig CAS server used the cas-server-webapp*.war # pattern. There's usually only one WAR in a Jasig CAS server # distribution, though, so we just look for all of them and pick the first one. jasig_package_name = FileList["#{jasig_extract_dest}/modules/*.war"] jetty_fn = URI.parse(jetty_url).path.split('/').last jetty_package_dest = "#{scratch_dir}/#{jetty_fn}" jetty_war_filename = mount_point.split('/').last + '.war' jetty_keystore = "#{instance_dir}/jetty.ks" jetty_storepass = "secret" jetty_ssl_config = "#{jetty_package_dest}/etc/jetty-cas-ssl.xml" namespaces(root.split(':')) do file jasig_package_dest do mkdir_p scratch_dir sh "curl -s #{e jasig_url} > #{e jasig_package_dest}" verify_checksum(jasig_package_dest, jasig_checksum) end file jetty_package_dest do mkdir_p scratch_dir sh "curl -s #{e jetty_url} > #{e jetty_package_dest}" verify_checksum(jetty_package_dest, jetty_checksum) end file jasig_extract_dest do mkdir_p jasig_extract_dest sh "tar xf #{e jasig_package_dest} -C #{e jasig_extract_dest} --strip-components 1" end file instance_dir do mkdir_p instance_dir sh "tar xf #{e jetty_package_dest} -C #{e instance_dir} --strip-components 1" end task :ensure_port do raise "PORT is not set" unless port end desc 'Download the CAS server' task :download => [jasig_package_dest, jasig_extract_dest, jetty_package_dest] task :prep => [:download, :ensure_port, instance_dir] do mkdir_p instance_dir cp jasig_package_name.compact.first, "#{instance_dir}/webapps/#{jasig_war_filename}" sh %Q{openssl pkcs12 -inkey #{e ssl_key} -in #{e ssl_cert} -export \ -out #{e "#{instance_dir}/jetty.pkcs12"} \ -password #{e "pass:#{jetty_storepass}"}} sh %Q{keytool -destkeystore #{e jetty_keystore} -importkeystore \ -srckeystore #{e "#{instance_dir}/jetty.pkcs12"} \ -srcstoretype PKCS12 -srcstorepass #{e jetty_storepass} \ -storepass #{e jetty_storepass} -noprompt} ssl_config = ERB.new(File.read(JETTY_SSL_CONFIG_TEMPLATE)).result(binding) ssl_file = "#{instance_dir}/etc/jetty-cas-ssl.xml" File.open(ssl_file, 'w') { |f| f.write(ssl_config) } ini = File.read("#{instance_dir}/start.ini") unless ini.include?(ssl_file) File.open("#{instance_dir}/start.ini", 'a+') do |f| f.write(ssl_file) end end # Delete the default connector. patchfile = File.('../jetty.xml.patch', __FILE__) cd "#{instance_dir}/etc" do sh "patch -p1 < #{e JETTY_CONFIG_PATCHFILE}" end end desc 'Start a Jasig CAS Server instance (requires PORT to be set)' task :start => :prep do exec "cd #{e instance_dir} && exec java -jar start.jar" end desc "Wait for all Jasig CAS Server instances in #{scratch_dir} to become ready" task(:waitall) { wait_all(scratch_dir, timeout) } desc "Clean up all Jasig CAS Server instances under #{scratch_dir}" task(:cleanall) { clean_all(scratch_dir, 'jasig') } desc "Delete #{scratch_dir}" task :delete_scratch_dir do rm_rf scratch_dir end end end |