Commit 15ad8d67 authored by telyn's avatar telyn
Browse files

Add test_ssl_hooks

parent 6bd6f2be
...@@ -71,7 +71,8 @@ opts = GetoptLong.new( ...@@ -71,7 +71,8 @@ opts = GetoptLong.new(
['--no-generate', '-G', GetoptLong::NO_ARGUMENT], ['--no-generate', '-G', GetoptLong::NO_ARGUMENT],
['--no-rollover', '-R', GetoptLong::NO_ARGUMENT], ['--no-rollover', '-R', GetoptLong::NO_ARGUMENT],
['--select', '-s', GetoptLong::REQUIRED_ARGUMENT], ['--select', '-s', GetoptLong::REQUIRED_ARGUMENT],
['--prefix', '-p', GetoptLong::REQUIRED_ARGUMENT] ['--prefix', '-p', GetoptLong::REQUIRED_ARGUMENT],
['--root-dir', '-r', GetoptLong::REQUIRED_ARGUMENT]
) )
manual = help = false manual = help = false
...@@ -81,6 +82,7 @@ prefix = '/srv' ...@@ -81,6 +82,7 @@ prefix = '/srv'
do_list = do_generate = do_rollover = nil do_list = do_generate = do_rollover = nil
rollover_to = nil rollover_to = nil
threshold = 21 threshold = 21
root = '/'
opts.each do |opt,arg| opts.each do |opt,arg|
case opt case opt
...@@ -105,6 +107,8 @@ opts.each do |opt,arg| ...@@ -105,6 +107,8 @@ opts.each do |opt,arg|
manual = true manual = true
when '--prefix' when '--prefix'
prefix = arg prefix = arg
when '--root-dir'
root = arg
when '--list' when '--list'
do_list = true do_list = true
when '--verbose' when '--verbose'
...@@ -114,6 +118,8 @@ opts.each do |opt,arg| ...@@ -114,6 +118,8 @@ opts.each do |opt,arg|
end end
end end
prefix == '/srv' && prefix = File.join(root, '/srv')
# #
# Output help as required. # Output help as required.
# #
......
...@@ -2,5 +2,27 @@ ...@@ -2,5 +2,27 @@
# This module contains all the classes that are needed for Bytemark Symbiosis. # This module contains all the classes that are needed for Bytemark Symbiosis.
# #
module Symbiosis module Symbiosis
def root
@@root || '/'
end
def root=(new_root)
@@root = new_root
end
def prefix
@@prefix || '/srv'
end
def prefix=(new_prefix)
@@prefix = new_prefix
end
def path_to(path)
File.join(root, path)
end
def path_in_prefix_to(path)
File.join(root, prefix, path)
end
end end
require 'symbiosis'
module Symbiosis module Symbiosis
class SSL class SSL
PROVIDERS ||= [] PROVIDERS ||= []
...@@ -5,7 +7,9 @@ module Symbiosis ...@@ -5,7 +7,9 @@ module Symbiosis
def self.call_hooks(domains_with_updates) def self.call_hooks(domains_with_updates)
return if domains_with_updates.empty? return if domains_with_updates.empty?
Dir.glob('/etc/symbiosis/ssl-hooks.d/*').each do |script| hooks_path = Symbiosis.path_to('/etc/symbiosis/ssl-hooks.d/*')
Dir.glob(hooks_path).each do |script|
next unless File.executable?(script) next unless File.executable?(script)
IO.popen([script, 'live-update'], 'r+') do |io| IO.popen([script, 'live-update'], 'r+') do |io|
io.puts domains_with_updates.join("\n") io.puts domains_with_updates.join("\n")
......
...@@ -2,6 +2,7 @@ $:.unshift "../lib/" if File.directory?("../lib") ...@@ -2,6 +2,7 @@ $:.unshift "../lib/" if File.directory?("../lib")
require 'test/unit' require 'test/unit'
require 'tmpdir' require 'tmpdir'
require 'symbiosis'
require 'symbiosis/domain/ssl' require 'symbiosis/domain/ssl'
require 'symbiosis/ssl/selfsigned' require 'symbiosis/ssl/selfsigned'
require 'mocha/test_unit' require 'mocha/test_unit'
...@@ -26,12 +27,21 @@ class SSLTest < Test::Unit::TestCase ...@@ -26,12 +27,21 @@ class SSLTest < Test::Unit::TestCase
# #
Process.egid = 1000 if Process.gid == 0 Process.egid = 1000 if Process.gid == 0
Process.euid = 1000 if Process.uid == 0 Process.euid = 1000 if Process.uid == 0
@root = Dir.mktmpdir('root')
@prefix = Dir.mktmpdir("srv") @prefix = Dir.mktmpdir("srv")
@prefix.freeze @prefix.freeze
@domain = Symbiosis::Domain.new(nil, @prefix) @domain = Symbiosis::Domain.new(nil, @prefix)
@domain.create @domain.create
@verbose = (($VERBOSE or $DEBUG) ? " --verbose " : "")
testd = File.dirname(__FILE__)
@script = File.expand_path(File.join(testd,"..","bin","symbiosis-ssl"))
@script = '/usr/sbin/symbiosis-ssl' unless File.exist?(@script)
@script += @verbose
end end
def teardown def teardown
...@@ -928,4 +938,42 @@ class SSLTest < Test::Unit::TestCase ...@@ -928,4 +938,42 @@ class SSLTest < Test::Unit::TestCase
end end
def test_ssl_hooks
#
# This requires the Self-signed provider to be in place
#
ssl_domain = @domain
ssl_domain.ssl_provider = 'selfsigned'
ssl_dir = File.join(ssl_domain.config_dir, 'ssl')
sets_dir = File.join(ssl_dir, 'sets')
Symbiosis::Utils.mkdir_p(sets_dir)
regular_domain = Symbiosis::Domain.new(nil, @prefix)
regular_domain.create
args_path = Symbiosis.path_to('hook.args')
out_path = Symbiosis.path_to('hook.output')
File.delete(args_path, 'w') if File.exist?(args_path)
File.delete(out_path, 'w') if File.exist?(out_path)
hook = <<HOOK
#!/bin/bash
echo "$1" > #{args_path}
cat > #{out_path}
HOOK
system("#{@script} --root-dir=#{@root} --prefix=#{@prefix}")
args = IO.read args_path
out = IO.read args_path
assert_equal 'live-update'
assert_equal ssl_domain.name, out
end
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment