-
Notifications
You must be signed in to change notification settings - Fork 0
/
rc_script
executable file
·285 lines (243 loc) · 8.53 KB
/
rc_script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#!/usr/libexec/atf-sh
: ${TMPDIR=/tmp}
. $(atf_get_srcdir)/../../../scripts/utils.subr
atf_test_case stroke cleanup
stroke_head()
{
atf_set descr "Test stroke rc script"
atf_set require.user root
}
stroke_body()
{
sst_init
cp $(atf_get_srcdir)/files/moon/etc/rc.d/strongswan ${TMPDIR}/strongswan
jexec moon mv ${TMPDIR}/strongswan /usr/local/etc/rc.d
jexec moon chmod 0555 /usr/local/etc/rc.d/strongswan
jexec moon sysrc strongswan_enable=YES
jexec moon sysrc strongswan_interface=stroke
# start (started)
jexec moon service strongswan start > /dev/null 2>&1 || true
atf_check -s not-exit:0 \
-e match:"strongswan already running?" \
jexec moon service strongswan start
jexec moon service strongswan stop > /dev/null 2>&1 || true
# start (stopped)
atf_check \
-o match:"Starting strongswan." \
-e match:"Starting strongSwan" \
jexec moon service strongswan start
jexec moon service strongswan stop > /dev/null 2>&1 || true
# stop (started)
jexec moon service strongswan start > /dev/null 2>&1 || true
atf_check \
-o match:"Stopping strongswan." \
-o match:"Waiting for PIDS" \
jexec moon service strongswan stop
jexec moon service strongswan stop > /dev/null 2>&1 || true
# stop (stopped)
atf_check -s not-exit:0 \
-e match:"strongswan not running?" \
jexec moon service strongswan stop
jexec moon service strongswan stop > /dev/null 2>&1 || true
# restart (started)
jexec moon service strongswan start > /dev/null 2>&1 || true
atf_check \
-o match:"Stopping strongswan." \
-o match:"Waiting for PIDS" \
-o match:"Starting strongswan." \
-e match:"Starting strongSwan" \
jexec moon service strongswan restart
jexec moon service strongswan stop > /dev/null 2>&1 || true
# restart (stopped)
atf_check \
-o match:"Starting strongswan." \
-e match:"Starting strongSwan" \
jexec moon service strongswan restart
jexec moon service strongswan stop > /dev/null 2>&1 || true
# status (started)
jexec moon service strongswan start > /dev/null 2>&1 || true
atf_check \
-o match:"Security Associations" \
jexec moon service strongswan status
jexec moon service strongswan stop > /dev/null 2>&1 || true
# status (stopped)
atf_check -s not-exit:0 \
jexec moon service strongswan status
jexec moon service strongswan stop > /dev/null 2>&1 || true
# statusall (started)
jexec moon service strongswan start > /dev/null 2>&1 || true
atf_check \
-o match:"Status of IKE charon daemon" \
-o match:"Connections" \
-o match:"Security Associations" \
jexec moon service strongswan statusall
jexec moon service strongswan stop > /dev/null 2>&1 || true
# statusall (stopped)
atf_check -s not-exit:0 \
jexec moon service strongswan statusall
jexec moon service strongswan stop > /dev/null 2>&1 || true
# reload (started)
jexec moon service strongswan start > /dev/null 2>&1 || true
atf_check \
-e match:"Reloading strongSwan IPsec configuration..." \
jexec moon service strongswan reload
jexec moon service strongswan stop > /dev/null 2>&1 || true
# reload (stopped)
atf_check -s not-exit:0 \
-e match:"starter is not running" \
jexec moon service strongswan reload
jexec moon service strongswan stop > /dev/null 2>&1 || true
# respawn charon process
jexec moon service strongswan start > /dev/null 2>&1 || true
jexec moon sleep 1
charon_pid=$(jexec moon cat /var/run/charon.pid)
jexec moon kill -9 $charon_pid
jexec moon sleep 5
atf_check \
-o match:"/usr/local/libexec/ipsec/charon" \
jexec moon ps auxww
jexec moon service strongswan stop > /dev/null 2>&1 || true
}
stroke_cleanup()
{
sst_cleanup
}
atf_test_case vici cleanup
vici_head()
{
atf_set descr "Test VICI rc script"
atf_set require.user root
}
vici_body()
{
sst_init
cp $(atf_get_srcdir)/files/moon/etc/rc.d/strongswan ${TMPDIR}/strongswan
jexec moon mv ${TMPDIR}/strongswan /usr/local/etc/rc.d
jexec moon service strongswan stop > /dev/null 2>&1
jexec moon service strongswan stop > /dev/null 2>&1
jexec moon service strongswan stop > /dev/null 2>&1
jexec moon service strongswan stop > /dev/null 2>&1
jexec moon service strongswan stop > /dev/null 2>&1
jexec moon service strongswan stop > /dev/null 2>&1
jexec moon chmod 0555 /usr/local/etc/rc.d/strongswan
cp $(atf_get_srcdir)/files/moon/etc/swanctl/conf.d/dummy.conf \
${TMPDIR}/dummy.conf
jexec moon mv ${TMPDIR}/dummy.conf /usr/local/etc/swanctl/conf.d
jexec moon sysrc strongswan_enable=YES
jexec moon sysrc strongswan_interface=VICI
# start (started)
jexec moon service strongswan start > /dev/null 2>&1 || true
atf_check -s not-exit:0 \
-e match:"strongswan already running?" \
jexec moon service strongswan start
jexec moon service strongswan stop > /dev/null 2>&1 || true
# start (stopped)
atf_check \
-o match:"Starting strongswan." \
-o match:"successfully loaded [[:digit:]]+ connections" \
-o match:"authorities found" \
-o match:"pools found" \
jexec moon service strongswan start
jexec moon service strongswan stop > /dev/null 2>&1 || true
# stop (started)
jexec moon service strongswan start > /dev/null 2>&1 || true
atf_check \
-o match:"Stopping strongswan." \
-o match:"Waiting for PIDS" \
jexec moon service strongswan stop
jexec moon service strongswan stop > /dev/null 2>&1 || true
# stop (stopped)
atf_check -s not-exit:0 \
-e match:"strongswan not running?" \
jexec moon service strongswan stop
jexec moon service strongswan stop > /dev/null 2>&1 || true
# restart (started)
jexec moon service strongswan start > /dev/null 2>&1 || true
atf_check \
-o match:"Stopping strongswan." \
-o match:"Waiting for PIDS" \
-o match:"Starting strongswan." \
-o match:"successfully loaded [[:digit:]]+ connections" \
-o match:"authorities found" \
-o match:"pools found" \
jexec moon service strongswan restart
jexec moon service strongswan stop > /dev/null 2>&1 || true
# restart (stopped)
atf_check \
-e match:"strongswan not running?" \
-o match:"Starting strongswan." \
-o match:"successfully loaded [[:digit:]]+ connections" \
-o match:"authorities found" \
-o match:"pools found" \
jexec moon service strongswan restart
jexec moon service strongswan stop > /dev/null 2>&1 || true
# status (started)
jexec moon service strongswan start > /dev/null 2>&1 || true
atf_check \
-o match:"uptime" \
-o match:"worker threads" \
-o match:"loaded plugins" \
jexec moon service strongswan status
jexec moon service strongswan stop > /dev/null 2>&1 || true
# status (stopped)
atf_check -s not-exit:0 \
-e match:"strongswan not running?" \
jexec moon service strongswan status
jexec moon service strongswan stop > /dev/null 2>&1 || true
# statusall (started)
jexec moon service strongswan start > /dev/null 2>&1 || true
atf_check \
-o match:"uptime" \
-o match:"worker threads" \
-o match:"loaded plugins" \
jexec moon service strongswan statusall
jexec moon service strongswan stop > /dev/null 2>&1 || true
# statusall (stopped)
atf_check -s not-exit:0 \
-e match:"strongswan not running?" \
jexec moon service strongswan statusall
jexec moon service strongswan stop > /dev/null 2>&1 || true
# reload (started)
jexec moon service strongswan start > /dev/null 2>&1 || true
atf_check \
-o match:"successfully loaded [[:digit:]]+ connections" \
-o match:"authorities found" \
-o match:"pools found" \
jexec moon service strongswan reload
jexec moon service strongswan stop > /dev/null 2>&1 || true
# reload (stopped)
atf_check -s not-exit:0 \
-e match:"strongswan not running?" \
jexec moon service strongswan reload
jexec moon service strongswan stop > /dev/null 2>&1 || true
# respawn charon process
#
# NB: This implies that the daemon gets supervised and
# *restarted*. While this was true for the old stroke, it is
# not true for vici as it is at the moment.
# A user switching from stoke to vici would expect this
# behavior, as well as users switching from strongswan on
# Linux-based systems; charon-systemd supervises the process
# and respawns accordingly.
# While, this should be up for debate, I guess it is one of the
# reasons why some users are still reluctant to switch to vici
# (nobody wants to loose their VPN connections).
jexec moon service strongswan start > /dev/null 2>&1 || true
jexec moon sleep 1
charon_pid=$(jexec moon cat /var/run/charon.pid)
jexec moon kill -9 $charon_pid
jexec moon sleep 2 # daemon(8) restarts after 1 second
atf_check \
-o match:"/usr/local/libexec/ipsec/charon" \
jexec moon ps auxww
jexec moon service strongswan stop > /dev/null 2>&1 || true
}
vici_cleanup()
{
sst_cleanup
}
atf_init_test_cases()
{
atf_add_test_case stroke
atf_add_test_case vici
}