Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Ian Eiloart
Sympl
Commits
15ad8d67
Commit
15ad8d67
authored
Aug 14, 2017
by
telyn
Browse files
Add test_ssl_hooks
parent
6bd6f2be
Changes
4
Hide whitespace changes
Inline
Side-by-side
common/bin/symbiosis-ssl
View file @
15ad8d67
...
...
@@ -71,7 +71,8 @@ opts = GetoptLong.new(
[
'--no-generate'
,
'-G'
,
GetoptLong
::
NO_ARGUMENT
],
[
'--no-rollover'
,
'-R'
,
GetoptLong
::
NO_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
...
...
@@ -81,6 +82,7 @@ prefix = '/srv'
do_list
=
do_generate
=
do_rollover
=
nil
rollover_to
=
nil
threshold
=
21
root
=
'/'
opts
.
each
do
|
opt
,
arg
|
case
opt
...
...
@@ -105,6 +107,8 @@ opts.each do |opt,arg|
manual
=
true
when
'--prefix'
prefix
=
arg
when
'--root-dir'
root
=
arg
when
'--list'
do_list
=
true
when
'--verbose'
...
...
@@ -114,6 +118,8 @@ opts.each do |opt,arg|
end
end
prefix
==
'/srv'
&&
prefix
=
File
.
join
(
root
,
'/srv'
)
#
# Output help as required.
#
...
...
common/lib/symbiosis.rb
View file @
15ad8d67
...
...
@@ -2,5 +2,27 @@
# This module contains all the classes that are needed for Bytemark 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
common/lib/symbiosis/ssl.rb
View file @
15ad8d67
require
'symbiosis'
module
Symbiosis
class
SSL
PROVIDERS
||=
[]
...
...
@@ -5,7 +7,9 @@ module Symbiosis
def
self
.
call_hooks
(
domains_with_updates
)
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
)
IO
.
popen
([
script
,
'live-update'
],
'r+'
)
do
|
io
|
io
.
puts
domains_with_updates
.
join
(
"
\n
"
)
...
...
common/test.d/tc_ssl.rb
View file @
15ad8d67
...
...
@@ -2,6 +2,7 @@ $:.unshift "../lib/" if File.directory?("../lib")
require
'test/unit'
require
'tmpdir'
require
'symbiosis'
require
'symbiosis/domain/ssl'
require
'symbiosis/ssl/selfsigned'
require
'mocha/test_unit'
...
...
@@ -26,12 +27,21 @@ class SSLTest < Test::Unit::TestCase
#
Process
.
egid
=
1000
if
Process
.
gid
==
0
Process
.
euid
=
1000
if
Process
.
uid
==
0
@root
=
Dir
.
mktmpdir
(
'root'
)
@prefix
=
Dir
.
mktmpdir
(
"srv"
)
@prefix
.
freeze
@domain
=
Symbiosis
::
Domain
.
new
(
nil
,
@prefix
)
@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
def
teardown
...
...
@@ -928,4 +938,42 @@ class SSLTest < Test::Unit::TestCase
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment