@@ -27,6 +27,7 @@ function setup() {
2727
2828 source /tmp/hestia-test-env.sh
2929 source $HESTIA /func/main.sh
30+ source $HESTIA /conf/hestia.conf
3031}
3132
3233# ----------------------------------------------------------#
@@ -156,28 +157,114 @@ function setup() {
156157 interface=$( v-list-sys-interfaces plain | head -n 1)
157158 run ip link show dev $interface
158159 assert_success
160+
161+ local a2_rpaf=" /etc/$WEB_SYSTEM /mods-enabled/rpaf.conf"
162+ local a2_remoteip=" /etc/$WEB_SYSTEM /mods-enabled/remoteip.conf"
163+
164+ # Save initial state
159165 echo " interface=${interface} " >> /tmp/hestia-test-env.sh
166+ [ -f " $a2_rpaf " ] && file_hash1=$( cat $a2_rpaf | md5sum | cut -d" " -f1) && echo " a2_rpaf_hash='${file_hash1} '" >> /tmp/hestia-test-env.sh
167+ [ -f " $a2_remoteip " ] && file_hash2=$( cat $a2_remoteip | md5sum | cut -d" " -f1) && echo " a2_remoteip_hash='${file_hash2} '" >> /tmp/hestia-test-env.sh
160168
161- run v-add-sys-ip 198.18.0.123 255.255.255.255 $interface $user
169+
170+ local ip=" 198.18.0.12"
171+ run v-add-sys-ip $ip 255.255.255.255 $interface $user
162172 assert_success
163173 refute_output
174+
175+ assert_file_exist /etc/$WEB_SYSTEM /conf.d/$ip .conf
176+ assert_file_exist $HESTIA /data/ips/$ip
177+ assert_file_contains $HESTIA /data/ips/$ip " OWNER='$user '"
178+ assert_file_contains $HESTIA /data/ips/$ip " INTERFACE='$interface '"
179+
180+ if [ -n " $PROXY_SYSTEM " ]; then
181+ assert_file_exist /etc/$PROXY_SYSTEM /conf.d/$ip .conf
182+ [ -f " $a2_rpaf " ] && assert_file_contains " $a2_rpaf " " RPAFproxy_ips.*$ip \b"
183+ [ -f " $a2_remoteip " ] && assert_file_contains " $a2_remoteip " " RemoteIPInternalProxy $ip \$ "
184+ fi
185+
164186}
165187
166- @test " Ip: Add duplicate (duplicat )" {
167- run v-add-sys-ip 198.18.0.123 255.255.255.255 $interface $user
188+ @test " Ip: Add ip (duplicate )" {
189+ run v-add-sys-ip 198.18.0.12 255.255.255.255 $interface $user
168190 assert_failure $E_EXISTS
169191}
170192
171- @test " Ip: Delete ip" {
172- run v-delete-sys-ip 198.18.0.123
193+ @test " Ip: Add extra ip" {
194+ local ip=" 198.18.0.121"
195+ run v-add-sys-ip $ip 255.255.255.255 $interface $user
196+ assert_success
197+ refute_output
198+
199+ assert_file_exist /etc/$WEB_SYSTEM /conf.d/$ip .conf
200+ assert_file_exist $HESTIA /data/ips/$ip
201+ assert_file_contains $HESTIA /data/ips/$ip " OWNER='$user '"
202+ assert_file_contains $HESTIA /data/ips/$ip " INTERFACE='$interface '"
203+
204+ if [ -n " $PROXY_SYSTEM " ]; then
205+ assert_file_exist /etc/$PROXY_SYSTEM /conf.d/$ip .conf
206+ local a2_rpaf=" /etc/$WEB_SYSTEM /mods-enabled/rpaf.conf"
207+ [ -f " $a2_rpaf " ] && assert_file_contains " $a2_rpaf " " RPAFproxy_ips.*$ip \b"
208+
209+ local a2_remoteip=" /etc/$WEB_SYSTEM /mods-enabled/remoteip.conf"
210+ [ -f " $a2_remoteip " ] && assert_file_contains " $a2_remoteip " " RemoteIPInternalProxy $ip \$ "
211+ fi
212+ }
213+
214+ @test " Ip: Delete ips" {
215+ local ip=" 198.18.0.12"
216+ run v-delete-sys-ip $ip
173217 assert_success
174218 refute_output
219+
220+ assert_file_not_exist /etc/$WEB_SYSTEM /conf.d/$ip .conf
221+ assert_file_not_exist $HESTIA /data/ips/$ip
222+
223+
224+ ip=" 198.18.0.121"
225+ run v-delete-sys-ip $ip
226+ assert_success
227+ refute_output
228+
229+ assert_file_not_exist /etc/$WEB_SYSTEM /conf.d/$ip .conf
230+ assert_file_not_exist $HESTIA /data/ips/$ip
231+
232+ if [ -n " $PROXY_SYSTEM " ]; then
233+ assert_file_not_exist /etc/$PROXY_SYSTEM /conf.d/$ip .conf
234+ fi
235+
236+ # remoteip and rpaf config hashes must match the initial one
237+ if [ ! -z " $a2_rpaf_hash " ]; then
238+ local a2_rpaf=" /etc/$WEB_SYSTEM /mods-enabled/rpaf.conf"
239+ file_hash=$( cat $a2_rpaf | md5sum | cut -d" " -f1)
240+ assert_equal " $file_hash " " $a2_rpaf_hash "
241+ fi
242+ if [ ! -z " $a2_remoteip_hash " ]; then
243+ local a2_remoteip=" /etc/$WEB_SYSTEM /mods-enabled/remoteip.conf"
244+ file_hash=$( cat $a2_remoteip | md5sum | cut -d" " -f1)
245+ assert_equal " $file_hash " " $a2_remoteip_hash "
246+ fi
175247}
176248
177249@test " Ip: Add IP for rest of the test" {
178- run v-add-sys-ip 198.18.0.125 255.255.255.255 $interface $user
250+ local ip=" 198.18.0.125"
251+ run v-add-sys-ip $ip 255.255.255.255 $interface $user
179252 assert_success
180253 refute_output
254+
255+ assert_file_exist /etc/$WEB_SYSTEM /conf.d/$ip .conf
256+ assert_file_exist $HESTIA /data/ips/$ip
257+ assert_file_contains $HESTIA /data/ips/$ip " OWNER='$user '"
258+ assert_file_contains $HESTIA /data/ips/$ip " INTERFACE='$interface '"
259+
260+ if [ -n " $PROXY_SYSTEM " ]; then
261+ assert_file_exist /etc/$PROXY_SYSTEM /conf.d/$ip .conf
262+ local a2_rpaf=" /etc/$WEB_SYSTEM /mods-enabled/rpaf.conf"
263+ [ -f " $a2_rpaf " ] && assert_file_contains " $a2_rpaf " " RPAFproxy_ips.*$ip \b"
264+
265+ local a2_remoteip=" /etc/$WEB_SYSTEM /mods-enabled/remoteip.conf"
266+ [ -f " $a2_remoteip " ] && assert_file_contains " $a2_remoteip " " RemoteIPInternalProxy $ip \$ "
267+ fi
181268}
182269
183270
0 commit comments