Commit 661f0ec8 authored by telyn's avatar telyn
Browse files

Improve/fix test_ssl_hooks and change Symbiosis.root to Symbiosis.etc

parent 15ad8d67
......@@ -72,7 +72,7 @@ opts = GetoptLong.new(
['--no-rollover', '-R', GetoptLong::NO_ARGUMENT],
['--select', '-s', GetoptLong::REQUIRED_ARGUMENT],
['--prefix', '-p', GetoptLong::REQUIRED_ARGUMENT],
['--root-dir', '-r', GetoptLong::REQUIRED_ARGUMENT]
['--etc-dir', '-r', GetoptLong::REQUIRED_ARGUMENT]
)
manual = help = false
......@@ -82,7 +82,7 @@ prefix = '/srv'
do_list = do_generate = do_rollover = nil
rollover_to = nil
threshold = 21
root = '/'
etc_dir = '/etc'
opts.each do |opt,arg|
case opt
......@@ -107,8 +107,8 @@ opts.each do |opt,arg|
manual = true
when '--prefix'
prefix = arg
when '--root-dir'
root = arg
when '--etc-dir'
etc_dir = arg
when '--list'
do_list = true
when '--verbose'
......@@ -118,7 +118,6 @@ opts.each do |opt,arg|
end
end
prefix == '/srv' && prefix = File.join(root, '/srv')
#
# Output help as required.
......@@ -137,6 +136,7 @@ end
v = $VERBOSE
$VERBOSE = false
require 'symbiosis'
require 'symbiosis/domains'
require 'symbiosis/domain/ssl'
require 'symbiosis/ssl'
......@@ -148,6 +148,8 @@ require 'symbiosis/ssl/selfsigned'
#
$VERBOSE = v
Symbiosis.etc = etc_dir
domains = []
ARGV.each do |arg|
......
......@@ -2,27 +2,30 @@
# This module contains all the classes that are needed for Bytemark Symbiosis.
#
module Symbiosis
def root
@@root || '/'
@@etc = '/etc'
@@prefix='/srv'
def self.etc
@@etc
end
def root=(new_root)
@@root = new_root
def self.etc=(new_etc)
@@etc = new_etc
end
def prefix
@@prefix || '/srv'
def self.prefix
@@prefix
end
def prefix=(new_prefix)
def self.prefix=(new_prefix)
@@prefix = new_prefix
end
def path_to(path)
File.join(root, path)
def self.path_in_etc(path)
File.join(etc, path)
end
def path_in_prefix_to(path)
File.join(root, prefix, path)
def self.path_in_prefix(path)
File.join(prefix, path)
end
end
......@@ -7,7 +7,7 @@ module Symbiosis
def self.call_hooks(domains_with_updates)
return if domains_with_updates.empty?
hooks_path = Symbiosis.path_to('/etc/symbiosis/ssl-hooks.d/*')
hooks_path = Symbiosis.path_in_etc('/symbiosis/ssl-hooks.d/*')
Dir.glob(hooks_path).each do |script|
next unless File.executable?(script)
......
......@@ -27,10 +27,13 @@ class SSLTest < Test::Unit::TestCase
#
Process.egid = 1000 if Process.gid == 0
Process.euid = 1000 if Process.uid == 0
@root = Dir.mktmpdir('root')
@etc = Dir.mktmpdir('etc')
@prefix = Dir.mktmpdir("srv")
Symbiosis.etc = File.realpath @etc
Symbiosis.prefix = File.realpath @prefix
@etc.freeze
@prefix.freeze
@domain = Symbiosis::Domain.new(nil, @prefix)
@domain.create
......@@ -61,6 +64,8 @@ class SSLTest < Test::Unit::TestCase
FileUtils.rm_rf(@prefix) if File.directory?(@prefix)
end
FileUtils.rm_rf(@etc) if File.directory?(@etc)
Process.euid = 0 if Process.uid == 0
Process.egid = 0 if Process.gid == 0
end
......@@ -954,12 +959,8 @@ class SSLTest < Test::Unit::TestCase
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)
args_path = Symbiosis.path_in_etc('hook.args')
out_path = Symbiosis.path_in_etc('hook.output')
hook = <<HOOK
#!/bin/bash
......@@ -968,12 +969,16 @@ echo "$1" > #{args_path}
cat > #{out_path}
HOOK
system("#{@script} --root-dir=#{@root} --prefix=#{@prefix}")
FileUtils.mkdir_p Symbiosis.path_in_etc('symbiosis/ssl-hooks.d')
IO.write Symbiosis.path_in_etc('symbiosis/ssl-hooks.d/hook'), hook, mode: 'w', perm: 0755
system("#{@script} --etc-dir=#{@etc} --prefix=#{@prefix}")
args = IO.read args_path
out = IO.read args_path
out = IO.read out_path
assert_equal 'live-update'
assert_equal ssl_domain.name, out
assert_equal "live-update\n", args
assert_equal "#{ssl_domain.name}\n", out
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