Skip to content

Commit 6630997

Browse files
committed
Add vhost config file tests
1 parent ca1ca75 commit 6630997

File tree

4 files changed

+82
-3
lines changed

4 files changed

+82
-3
lines changed

configs/vhost-app.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# (use - to default to ocf account name)
1212
# aliases - comma-separated aliases list, must be FQDNs
1313
# [flags] - (optional) comma-separated list of flags
14-
# only [nossl] is supported currently
14+
# No flags are supported currently
1515
#
1616

1717
# added 2019-01-24 fydai in-person

configs/vhost-mail.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ggroup dev-vhost.ocf.berkeley.edu
77
ggroup dev-dev-vhost.ocf.berkeley.edu
88

99
# added 2020-04-28 jaw rt#8975
10-
seaguls seaguls.berkeley.edu
10+
seaguls seaguls.berkeley.edu
1111

1212
# added 2020-04-28 jaw rt#9040
1313
thetatau thetatau.berkeley.edu
@@ -263,7 +263,7 @@ neurotech neurotech.berkeley.edu
263263
# added 2018-09-20 dkessler (staff hours)
264264
epoch epoch.berkeley.edu
265265
# changed 2019-10-13 php (in person)
266-
epoch pdab.berkeley.edu
266+
epoch pdab.berkeley.edu
267267

268268
# added 2018-09-12 mdcha (staff hours)
269269
mmhi mmhi.berkeley.edu

tests/conftest.py

+8
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@
55
def etc(fs):
66
"""Use pyfakefs in every test case"""
77
fs.add_real_directory('configs', target_path='/etc/ocf', read_only=True)
8+
9+
# This is here for vhost configs, but should be removed once they are read
10+
# from this repo via ocflib instead of read from NFS or the staff web
11+
# userdir. The statement above this will handle loading from the local
12+
# files instead of /etc/ocf once that's the case.
13+
fs.add_real_directory(
14+
'configs', target_path='/home/s/st/staff/vhost', read_only=True,
15+
)

tests/vhost_test.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from ocflib.vhost.application import get_app_vhosts
2+
from ocflib.vhost.mail import get_mail_vhosts
3+
from ocflib.vhost.mail import vhosts_for_user
4+
from ocflib.vhost.web import get_vhosts
5+
from ocflib.vhost.web import has_vhost
6+
7+
8+
def test_app_vhosts():
9+
app_vhosts = get_app_vhosts()
10+
11+
# Make sure we're actually getting some app vhosts back
12+
assert(any(app_vhosts))
13+
14+
# Check that dev-app.o.b.e exists as an app vhost (this is used for testing
15+
# by OCF staff, so it's likely to stick around). It should also be owned by
16+
# the ggroup user.
17+
assert('dev-app.ocf.berkeley.edu' in app_vhosts)
18+
assert(app_vhosts['dev-app.ocf.berkeley.edu']['username'] == 'ggroup')
19+
20+
# Ensure that there's no nossl flags present, we only support SSL vhosts
21+
# as of rt#5347
22+
nossl_flags = [
23+
vhost['flags']
24+
for vhost in app_vhosts.values() if 'nossl' in vhost['flags']
25+
]
26+
assert(not any(nossl_flags))
27+
28+
29+
def test_mail_vhosts():
30+
mail_vhosts = get_mail_vhosts()
31+
32+
# Make sure we're actually getting some app vhosts back
33+
assert(any(mail_vhosts))
34+
35+
# Check that the ggroup user has some mail vhosts (these are used for
36+
# testing by OCF staff so they're likely to stick around)
37+
assert(any(vhosts_for_user('ggroup')))
38+
39+
# Check that dev-vhost.o.b.e exists as an mail vhost (this is used for
40+
# testing by OCF staff, so it's likely to stick around)
41+
assert(
42+
'dev-vhost.ocf.berkeley.edu' in {vhost.domain for vhost in mail_vhosts}
43+
)
44+
45+
46+
def test_web_vhosts():
47+
web_vhosts = get_vhosts()
48+
49+
# Make sure we're actually getting some vhosts back
50+
assert(any(web_vhosts))
51+
52+
# Ensure the 'staff' and 'ggroup' users have some vhosts. These are likely
53+
# to always stick around as they are owned by the OCF and there are
54+
# multiple of them present for each user
55+
assert(has_vhost('staff'))
56+
assert(has_vhost('ggroup'))
57+
58+
# Check that dev-vhost.o.b.e exists as a web vhost (this is used for
59+
# testing by OCF staff, so it's likely to stick around). It should also
60+
# have a dev-host-alias.o.b.e alias present
61+
assert('dev-vhost.ocf.berkeley.edu' in web_vhosts)
62+
aliases = web_vhosts['dev-vhost.ocf.berkeley.edu']['aliases']
63+
assert('dev-vhost-alias.ocf.berkeley.edu' in aliases)
64+
65+
flags = [vhost['flags'] for vhost in web_vhosts.values() if vhost['flags']]
66+
# Ensure that there's no nossl flags present, we only support SSL vhosts
67+
# as of rt#5347.
68+
assert(not any([flag_list for flag_list in flags if 'nossl' in flag_list]))
69+
# hsts flags are still allowed (but may become the default sometime and be
70+
# removed)
71+
assert(any([flag_list for flag_list in flags if 'hsts' in flag_list]))

0 commit comments

Comments
 (0)