Commit f8faecc0 authored by telyn's avatar telyn
Browse files

Fix up ssl tests

parent ef1ea9ce
......@@ -157,7 +157,6 @@ require 'symbiosis'
require 'symbiosis/domains'
require 'symbiosis/domain/ssl'
require 'symbiosis/ssl'
require 'symbiosis/ssl/hooks'
require 'symbiosis/ssl/letsencrypt'
require 'symbiosis/ssl/selfsigned'
......
......@@ -11,8 +11,8 @@ module Symbiosis
class Hooks < Symbiosis::DomainHooks
HOOKS_DIR = File.join('symbiosis', 'ssl-hooks.d').freeze
def self.run!
Symbiosis::SSL::Hooks.new.run!
def self.run!(event, domains)
Symbiosis::SSL::Hooks.new.run! event, domains
end
def initialize(hooks_dir = Symbiosis.path_in_etc(HOOKS_DIR))
......
......@@ -3,18 +3,20 @@ require 'fileutils'
# helpers for the rest of the tests in this dir
module TestHelpers
def self.make_test_hook(hooks_dir)
args_path = Symbiosis.path_in_etc('hook.args')
output_path = Symbiosis.path_in_etc('hook.output')
def make_test_hook(hooks_dir)
hook = strip_heredoc <<HOOK
#!/bin/bash
echo "$1" > #{args_path}
cat > #{out_path}
cat > #{output_path}
HOOK
FileUtils.mkdir_p hooks_dir
IO.write Symbiosis.path_in_etc(hooks_dir, 'hook'),
IO.write File.join(hooks_dir, 'hook'),
hook, mode: 'w', perm: 0o755
HookOutput.new args_path, output_path
......@@ -27,8 +29,13 @@ HOOK
@output_path = output_path
end
def hook_ran?
File.exist?(@args_path) && File.exist?(@output_path)
end
def args
return @args if @args
return nil unless hook_ran?
@args = IO.read @args_path
......@@ -38,6 +45,7 @@ HOOK
def output
return @output if @output
return nil unless hook_ran?
@output = IO.read @output_path
......@@ -46,8 +54,10 @@ HOOK
end
end
def strip_heredoc
indent = scan(/^[ \t]*(?=\S)/).min.try(:size) || 0
String.gsub(/^[ \t]{#{indent}}/, '')
def self.strip_heredoc(heredoc)
space = heredoc.scan(/^[ \t]*(?=\S)/).min
indent = space ? space.size : 0
heredoc.gsub(/^[ \t]{#{indent}}/, '')
end
end
......@@ -2,6 +2,7 @@ $:.unshift "../lib/" if File.directory?("../lib")
require 'test/unit'
require 'tmpdir'
require './helpers'
require 'symbiosis'
require 'symbiosis/domain/ssl'
require 'symbiosis/ssl/selfsigned'
......@@ -959,13 +960,10 @@ class SSLTest < Test::Unit::TestCase
regular_domain = Symbiosis::Domain.new(nil, @prefix)
regular_domain.create
TestHelpers.make_test_hook Symbiosis.path_in_etc('symbiosis', 'ssl-hooks.d')
result = TestHelpers.make_test_hook Symbiosis.path_in_etc('symbiosis', 'ssl-hooks.d')
system("#{@script} --etc-dir=#{@etc} --prefix=#{@prefix}")
args = IO.read args_path
out = IO.read out_path
assert_equal "live-update\n", args
assert_equal "#{ssl_domain.name}\n", out
assert_equal "live-update\n", result.args
assert_equal "#{ssl_domain.name}\n", result.output
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