2012-04-12 08:06:27 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Tests for Serval DNA configuration operations.
|
|
|
|
#
|
|
|
|
# Copyright 2012 Paul Gardner-Stephen
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
source "${0%/*}/../testframework.sh"
|
|
|
|
source "${0%/*}/../testdefs.sh"
|
|
|
|
|
|
|
|
setup() {
|
2012-05-20 04:18:02 +00:00
|
|
|
setup_servald
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 02:28:07 +00:00
|
|
|
assert_stderr_log() {
|
|
|
|
local -a warn_patterns=()
|
|
|
|
local -a error_patterns=()
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
--warn-pattern=*) warn_patterns+=("${1#*=}"); shift;;
|
|
|
|
--error-pattern=*) error_patterns+=("${1#*=}"); shift;;
|
|
|
|
*) error "unsupported option: $1"; return;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
assertStderrGrep \
|
|
|
|
--matches=${#error_patterns[*]} \
|
|
|
|
--message="stderr of ($executed) contains exactly ${#error_patterns[*]} error message(s)" \
|
|
|
|
'^ERROR:'
|
|
|
|
local pattern
|
|
|
|
for pattern in "${warn_patterns[@]}"; do
|
|
|
|
assertStderrGrep \
|
|
|
|
--message="stderr of ($executed) contains a warning message matching \"$pattern\"" \
|
|
|
|
"^WARN:.*$pattern"
|
|
|
|
done
|
|
|
|
for pattern in "${error_patterns[@]}"; do
|
|
|
|
assertStderrGrep \
|
|
|
|
--message="stderr of ($executed) contains an error message matching \"$pattern\"" \
|
|
|
|
"^ERROR:.*$pattern"
|
|
|
|
done
|
2012-12-04 07:52:26 +00:00
|
|
|
}
|
|
|
|
|
2012-04-12 08:06:27 +00:00
|
|
|
doc_GetCreateInstanceDir="Get creates instance directory"
|
|
|
|
setup_GetCreateInstanceDir() {
|
2012-06-04 08:58:05 +00:00
|
|
|
setup
|
2012-08-27 06:26:55 +00:00
|
|
|
assert ! [ -d "$SERVALINSTANCE_PATH" ]
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
test_GetCreateInstanceDir() {
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config get
|
2012-06-04 08:58:05 +00:00
|
|
|
assert [ -d "$SERVALINSTANCE_PATH" ]
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_SetCreateInstanceDir="Set creates instance directory"
|
|
|
|
setup_SetCreateInstanceDir() {
|
2012-06-04 08:58:05 +00:00
|
|
|
setup
|
2012-08-27 06:26:55 +00:00
|
|
|
assert ! [ -d "$SERVALINSTANCE_PATH" ]
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
test_SetCreateInstanceDir() {
|
2012-12-04 07:50:53 +00:00
|
|
|
executeOk_servald config set debug.verbose 0
|
2012-06-04 08:58:05 +00:00
|
|
|
assert [ -d "$SERVALINSTANCE_PATH" ]
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_GetNull="Get an unset config item"
|
|
|
|
test_GetNull() {
|
2012-12-04 07:50:53 +00:00
|
|
|
executeOk_servald config get debug.verbose
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 0
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_SetGet="Set and get a single config item"
|
|
|
|
test_SetGet() {
|
2012-12-04 07:50:53 +00:00
|
|
|
executeOk_servald config set debug.verbose yes
|
|
|
|
executeOk_servald config get debug.verbose
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
2012-12-04 07:50:53 +00:00
|
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^debug\.verbose=yes$'
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_GetAll="Get all config items"
|
|
|
|
test_GetAll() {
|
2012-12-06 02:01:19 +00:00
|
|
|
executeOk_servald config \
|
|
|
|
set debug.verbose true \
|
|
|
|
set log.show_pid true \
|
|
|
|
set server.chdir /tmp/nothing \
|
|
|
|
set rhizome.enable no
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config get
|
2012-12-04 07:50:53 +00:00
|
|
|
assertStdoutLineCount '==' 4
|
|
|
|
assertStdoutGrep --stdout --matches=1 '^debug\.verbose=true$'
|
|
|
|
assertStdoutGrep --stdout --matches=1 '^log\.show_pid=true$'
|
|
|
|
assertStdoutGrep --stdout --matches=1 '^server\.chdir=/tmp/nothing$'
|
|
|
|
assertStdoutGrep --stdout --matches=1 '^rhizome\.enable=no$'
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 02:01:19 +00:00
|
|
|
doc_SetDelMixed="Set and del config items in single command"
|
|
|
|
test_SetDelMixed() {
|
|
|
|
executeOk_servald config \
|
|
|
|
set debug.verbose true \
|
|
|
|
set log.show_pid true \
|
|
|
|
set server.chdir /tmp/nothing \
|
|
|
|
set rhizome.enable no
|
|
|
|
executeOk_servald config \
|
|
|
|
set debug.verbose false \
|
|
|
|
del log.show_pid \
|
|
|
|
set log.show_time 1 \
|
|
|
|
del server.chdir \
|
|
|
|
del rhizome.enable
|
|
|
|
executeOk_servald config get
|
|
|
|
assertStdoutLineCount '==' 2
|
|
|
|
assertStdoutGrep --stdout --matches=1 '^debug\.verbose=false$'
|
|
|
|
assertStdoutGrep --stdout --matches=1 '^log\.show_time=1$'
|
|
|
|
}
|
|
|
|
|
2012-04-12 08:06:27 +00:00
|
|
|
doc_SetTwice="Set a single config item twice"
|
|
|
|
test_SetTwice() {
|
2012-12-04 07:50:53 +00:00
|
|
|
executeOk_servald config set debug.verbose yes
|
|
|
|
executeOk_servald config get debug.verbose
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
2012-12-04 07:50:53 +00:00
|
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^debug\.verbose=yes$'
|
|
|
|
executeOk_servald config set debug.verbose false
|
|
|
|
executeOk_servald config get debug.verbose
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
2012-12-04 07:50:53 +00:00
|
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^debug\.verbose=false$'
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_DelNull="Delete an unset config item"
|
|
|
|
test_DelNull() {
|
2012-12-04 07:50:53 +00:00
|
|
|
executeOk_servald config del debug.verbose
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 0
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_Del="Delete single config item"
|
|
|
|
test_Del() {
|
2012-12-06 02:01:19 +00:00
|
|
|
executeOk_servald config set debug.verbose yes set log.show_pid true
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config get
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 2
|
2012-12-04 07:50:53 +00:00
|
|
|
executeOk_servald config del debug.verbose
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config get
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
2012-12-04 07:50:53 +00:00
|
|
|
executeOk_servald config del log.show_pid
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 0
|
|
|
|
}
|
|
|
|
|
2012-12-04 06:22:49 +00:00
|
|
|
doc_CaseSensitive="Config item names are case sensitive"
|
|
|
|
test_CaseSensitive() {
|
2012-12-04 07:50:53 +00:00
|
|
|
execute $servald config set Debug.verbose yes
|
|
|
|
assertExitStatus --stderr '!=' 0
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
|
2012-12-04 07:50:53 +00:00
|
|
|
doc_OptionNames="Config item names must be well formed"
|
|
|
|
test_OptionNames() {
|
|
|
|
execute $servald config set debug. yes
|
2012-12-04 06:22:49 +00:00
|
|
|
assertExitStatus --stderr '!=' 0
|
2012-12-04 07:50:53 +00:00
|
|
|
execute $servald config set .verbose yes
|
2012-12-04 06:22:49 +00:00
|
|
|
assertExitStatus --stderr '!=' 0
|
2012-12-06 02:01:19 +00:00
|
|
|
execute $servald config del debug..verbose
|
2012-12-04 06:22:49 +00:00
|
|
|
assertExitStatus --stderr '!=' 0
|
2012-05-14 09:02:10 +00:00
|
|
|
}
|
|
|
|
|
2012-05-15 00:19:40 +00:00
|
|
|
doc_DebugFlags="Debug config options affect verbosity"
|
2012-05-14 09:02:10 +00:00
|
|
|
test_DebugFlags() {
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald echo one two three
|
2012-05-14 09:02:10 +00:00
|
|
|
assertStderrGrep --matches=0 '\<echo:argv\['
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set debug.verbose true
|
|
|
|
executeOk_servald echo one two three
|
2012-05-14 09:02:10 +00:00
|
|
|
assertStderrGrep --matches=3 '\<echo:argv\['
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set debug.verbose false
|
|
|
|
executeOk_servald echo one two three
|
2012-05-14 09:02:10 +00:00
|
|
|
assertStderrGrep --matches=0 '\<echo:argv\['
|
|
|
|
}
|
|
|
|
|
2012-12-05 02:28:07 +00:00
|
|
|
doc_InterfacesLegacyIncludeAll="Legacy 'interfaces' config option include all"
|
|
|
|
test_InterfacesLegacyIncludeAll() {
|
2012-12-04 07:52:26 +00:00
|
|
|
executeOk_servald config set interfaces '+'
|
2012-12-05 02:28:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_InterfacesLegacyExcludeAll="Legacy 'interfaces' config option exclude all"
|
|
|
|
test_InterfacesLegacyExcludeAll() {
|
2012-12-04 07:52:26 +00:00
|
|
|
executeOk_servald config set interfaces '-'
|
2012-12-05 02:28:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_InterfacesLegacyMixed="Legacy 'interfaces' config option mixed list"
|
|
|
|
test_InterfacesLegacyMixed() {
|
|
|
|
executeOk_servald config set interfaces '+eth,-wifi,+'
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_InterfacesLegacyMixedDetail="Legacy 'interfaces' config option mixed list with details"
|
|
|
|
test_InterfacesLegacyMixedDetail() {
|
2012-12-04 07:52:26 +00:00
|
|
|
executeOk_servald config set interfaces '+eth=ethernet:4111:9M, +wifi=wifi:4112:900K, -'
|
2012-12-05 02:28:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_InterfacesLegacyInvalidType="Legacy 'interfaces' config option invalid type"
|
|
|
|
test_InterfacesLegacyInvalidType() {
|
|
|
|
execute --stderr --core-backtrace --exit-status=2 --executable=$servald \
|
|
|
|
config set interfaces '+eth=foo:4111:9M'
|
|
|
|
assert_stderr_log \
|
|
|
|
--warn-pattern='"interfaces".*invalid' \
|
|
|
|
--error-pattern='config file.*not loaded.*invalid'
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_InterfacesLegacyInvalidPort="Legacy 'interfaces' config option invalid port"
|
|
|
|
test_InterfacesLegacyInvalidPort() {
|
|
|
|
execute --stderr --core-backtrace --exit-status=2 --executable=$servald \
|
|
|
|
config set interfaces '+eth=ethernet:-1000:9M'
|
|
|
|
assert_stderr_log \
|
|
|
|
--warn-pattern='"interfaces".*invalid' \
|
|
|
|
--error-pattern='config file.*not loaded.*invalid'
|
|
|
|
}
|
|
|
|
|
2012-12-20 05:50:12 +00:00
|
|
|
doc_InterfacesLegacyInvalidSpeed="Legacy 'interfaces' config option invalid speed is ignored"
|
2012-12-05 02:28:07 +00:00
|
|
|
test_InterfacesLegacyInvalidSpeed() {
|
2012-12-20 05:50:12 +00:00
|
|
|
# speed option is no longer validated or used
|
|
|
|
execute --stderr --core-backtrace --exit-status=0 --executable=$servald \
|
|
|
|
config set interfaces '+eth=ethernet:4111:9Moose'
|
|
|
|
#assert_stderr_log \
|
|
|
|
# --warn-pattern='"interfaces".*invalid' \
|
|
|
|
# --error-pattern='config file.*not loaded.*invalid'
|
2012-12-05 02:28:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_InterfacesLegacyIncompatible="Legacy 'interfaces' config option incompatible with modern form"
|
|
|
|
test_InterfacesLegacyIncompatible() {
|
|
|
|
executeOk_servald config set interfaces '+'
|
|
|
|
execute --stderr --core-backtrace --executable=$servald \
|
|
|
|
config set interfaces.10.match 'eth'
|
|
|
|
tfw_cat $SERVALINSTANCE_PATH/serval.conf
|
|
|
|
assertExitStatus '==' 2
|
|
|
|
assert_stderr_log \
|
|
|
|
--warn-pattern='"interfaces.*incompatible' \
|
|
|
|
--error-pattern='config file.*not loaded.*incompatible'
|
|
|
|
tfw_cat --stderr
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_InterfacesModernMatch="Modern 'interfaces.N.match' config option"
|
|
|
|
test_InterfacesModernMatch() {
|
|
|
|
executeOk_servald config set interfaces.0.match 'eth*, wifi*'
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_InterfacesModernDummy="Modern 'interfaces.N.dummy' config option"
|
|
|
|
test_InterfacesModernDummy() {
|
|
|
|
executeOk_servald config set interfaces.0.dummy dummyname
|
|
|
|
}
|
|
|
|
teardown_InterfacesModernDummy() {
|
|
|
|
tfw_cat $SERVALINSTANCE_PATH/serval.conf
|
|
|
|
teardown
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_InterfacesModernIncompatible="Config options 'interfaces.match' and 'interfaces.dummy' are incompatible"
|
|
|
|
test_InterfacesModernIncompatible() {
|
|
|
|
executeOk_servald config set interfaces.0.match eth
|
|
|
|
execute --stderr --core-backtrace --executable=$servald \
|
|
|
|
config set interfaces.0.dummy dummy
|
|
|
|
assertExitStatus '==' 2
|
|
|
|
assert_stderr_log \
|
|
|
|
--warn-pattern='"interfaces\.0\..*incompatible' \
|
|
|
|
--error-pattern='config file.*not loaded.*incompatible'
|
2012-12-04 07:52:26 +00:00
|
|
|
}
|
|
|
|
|
2012-04-12 08:06:27 +00:00
|
|
|
runTests "$@"
|