From: Jorge Pereira Date: Wed, 2 Oct 2019 01:36:24 +0000 (-0300) Subject: Add tests for radmin/control-socket X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e552e6e43feec878aaca425b965d52493f2608b;p=thirdparty%2Ffreeradius-server.git Add tests for radmin/control-socket --- diff --git a/Makefile b/Makefile index e44157f4e38..be3df5caeda 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,7 @@ $(BUILD_DIR)/tests/radiusd-c: raddb/test.conf ${BUILD_DIR}/bin/radiusd $(GENERAT @echo "ok" @touch $@ -test: ${BUILD_DIR}/bin/radiusd ${BUILD_DIR}/bin/radclient test.bin test.trie test.unit test.xlat test.map test.keywords test.auth test.modules $(BUILD_DIR)/tests/radiusd-c test.eap | build.raddb +test: ${BUILD_DIR}/bin/radiusd ${BUILD_DIR}/bin/radclient test.bin test.trie test.unit test.xlat test.map test.keywords test.auth test.modules test.radmin $(BUILD_DIR)/tests/radiusd-c test.eap | build.raddb @$(MAKE) -C src/tests tests clean: clean.test diff --git a/src/tests/all.mk b/src/tests/all.mk index 0a3861c4c37..054672e1b38 100644 --- a/src/tests/all.mk +++ b/src/tests/all.mk @@ -5,7 +5,7 @@ # Or, if we're trying to clean things up. # ifneq "$(findstring test,$(MAKECMDGOALS))$(findstring clean,$(MAKECMDGOALS))" "" -SUBMAKEFILES := rbmonkey.mk eapol_test/all.mk dict/all.mk trie/all.mk unit/all.mk map/all.mk xlat/all.mk keywords/all.mk util/all.mk auth/all.mk modules/all.mk bin/all.mk daemon/all.mk +SUBMAKEFILES := radmin/all.mk rbmonkey.mk eapol_test/all.mk dict/all.mk trie/all.mk unit/all.mk map/all.mk xlat/all.mk keywords/all.mk util/all.mk auth/all.mk modules/all.mk bin/all.mk daemon/all.mk endif # diff --git a/src/tests/radmin/all.mk b/src/tests/radmin/all.mk new file mode 100644 index 00000000000..796d9be231d --- /dev/null +++ b/src/tests/radmin/all.mk @@ -0,0 +1,99 @@ +# +# Unit tests for radmin tool against the radiusd. +# + +# +# Test name +# +TEST := test.radmin + +# +# The test files are files without extensions. +# +FILES := $(subst $(DIR)/cmds/%,,$(wildcard $(DIR)/cmds/*.in)) +OUTPUT := $(subst $(top_srcdir)/src,$(BUILD_DIR),$(dir $(abspath $(lastword $(MAKEFILE_LIST))))) + +# +# Config settings +# +RADMIN_BIN := $(TESTBINDIR)/radmin +RADMIN_OUTPUT_DIR := $(BUILD_DIR)/tests/radmin +RADMIN_RADIUS_LOG := $(RADMIN_OUTPUT_DIR)/radius.log +RADMIN_GDB_LOG := $(RADMIN_OUTPUT_DIR)/gdb.log +RADMIN_SOCKET_FILE := $(RADMIN_OUTPUT_DIR)/control-socket.sock +RADMIN_CONFIG_PATH := $(DIR)/config + +include src/tests/radiusd.mk +PORT := 12340 +$(eval $(call RADIUSD_SERVICE,control-socket)) +# +# Create the output directory +# +.PHONY: $(OUTPUT) +$(OUTPUT): + ${Q}mkdir -p $@ + +# +# All of the output files depend on the input files +# +FILES.$(TEST) := $(addprefix $(OUTPUT),$(notdir $(FILES))) + +# +# The output files also depend on the directory +# and on the previous test. +# +$(FILES.$(TEST)): | $(OUTPUT) + +# +# We have a real file that's created if all of the tests pass. +# +$(BUILD_DIR)/tests/$(TEST): $(FILES.$(TEST)) + ${Q}touch $@ + +# +# For simplicity, we create a phony target so that the poor developer +# doesn't need to remember path names +# +$(TEST): $(BUILD_DIR)/tests/$(TEST) + +# +# Clean the output directory and files. +# +.PHONY: clean.$(TEST) +clean.$(TEST): + ${Q}rm -rf $(RADMIN_OUTPUT_DIR) + +clean.test: clean.$(TEST) + +# +# Run the radmin commands against the radiusd. +# +$(RADMIN_OUTPUT_DIR)/%: $(DIR)/cmds/% test.radmin.radiusd_kill test.radmin.radiusd_start + $(eval EXPECTED := $(patsubst %.in,%.ret,$<)) + $(eval FOUND := $(patsubst %.in,%.ret,$@)) + $(eval TARGET := $(patsubst %.in,%,$(notdir $@))) + ${Q}echo "RADMIN-TEST $(TARGET)"; \ + if ! $(RADMIN_BIN) -q -f $(RADMIN_SOCKET_FILE) > $(FOUND) < $<; then\ + echo "--------------------------------------------------"; \ + tail -n 20 "$(RADMIN_RADIUS_LOG)"; \ + echo "Last entries in server log ($(RADMIN_RADIUS_LOG)):"; \ + echo "--------------------------------------------------"; \ + echo "TEST_PORT=$(PORT) $(JLIBTOOL) --mode=execute $(BIN_PATH)/radiusd -PXxx -d \"$(RADMIN_CONFIG_PATH)\" -n control-socket -D \"${top_builddir}/share/dictionary/\""; \ + echo "$(RADMIN_BIN) -q -f $(RADMIN_SOCKET_FILE) > $(FOUND) < $<"; \ + $(MAKE) $(TEST).radiusd_kill; \ + exit 1;\ + fi; \ + if ! cmp -s $(FOUND) $(EXPECTED); then \ + echo "RADMIN FAILED $@"; \ + echo "ERROR: It is expected to $(FOUND) be same as $(EXPECTED)"; \ + echo "If you did some update on the Radmin code, please be sure to update the unit tests."; \ + echo "e.g: $(EXPECTED)"; \ + diff $(FOUND) $(EXPECTED); \ + exit 1; \ + else \ + touch $@;\ + fi + +$(TEST): $(FILES) + ${Q}$(MAKE) test.radmin.radiusd_kill + diff --git a/src/tests/radmin/cmds/00-help.in b/src/tests/radmin/cmds/00-help.in new file mode 100644 index 00000000000..a87bf434991 --- /dev/null +++ b/src/tests/radmin/cmds/00-help.in @@ -0,0 +1 @@ +help diff --git a/src/tests/radmin/cmds/00-help.ret b/src/tests/radmin/cmds/00-help.ret new file mode 100644 index 00000000000..f29737e4baf --- /dev/null +++ b/src/tests/radmin/cmds/00-help.ret @@ -0,0 +1,17 @@ +help +exit + Exit from the current context. +help [(all|commands)] + Display list of commands and their help text. +quit + Quit and close the command line immediately. +set + Change settings in the server. +show + Show settings in the server. +stats + Show statistics in the server. +terminate + Terminate the running server and cause it to exit. +uptime + Show uptime since the server started. diff --git a/src/tests/radmin/cmds/01-help-all.in b/src/tests/radmin/cmds/01-help-all.in new file mode 100644 index 00000000000..a87bf434991 --- /dev/null +++ b/src/tests/radmin/cmds/01-help-all.in @@ -0,0 +1 @@ +help diff --git a/src/tests/radmin/cmds/01-help-all.ret b/src/tests/radmin/cmds/01-help-all.ret new file mode 100644 index 00000000000..f29737e4baf --- /dev/null +++ b/src/tests/radmin/cmds/01-help-all.ret @@ -0,0 +1,17 @@ +help +exit + Exit from the current context. +help [(all|commands)] + Display list of commands and their help text. +quit + Quit and close the command line immediately. +set + Change settings in the server. +show + Show settings in the server. +stats + Show statistics in the server. +terminate + Terminate the running server and cause it to exit. +uptime + Show uptime since the server started. diff --git a/src/tests/radmin/cmds/02-show-client-all-proto.in b/src/tests/radmin/cmds/02-show-client-all-proto.in new file mode 100644 index 00000000000..91480f94c4b --- /dev/null +++ b/src/tests/radmin/cmds/02-show-client-all-proto.in @@ -0,0 +1 @@ +show client config 127.0.1.1 diff --git a/src/tests/radmin/cmds/02-show-client-all-proto.ret b/src/tests/radmin/cmds/02-show-client-all-proto.ret new file mode 100644 index 00000000000..9ea2801a154 --- /dev/null +++ b/src/tests/radmin/cmds/02-show-client-all-proto.ret @@ -0,0 +1,4 @@ +show client config 127.0.1.1 +shortname rapadura_test_client +secret testing123 +proto * diff --git a/src/tests/radmin/cmds/03-show-client-tcp-proto.in b/src/tests/radmin/cmds/03-show-client-tcp-proto.in new file mode 100644 index 00000000000..27ae51a43e9 --- /dev/null +++ b/src/tests/radmin/cmds/03-show-client-tcp-proto.in @@ -0,0 +1 @@ +show client config 127.0.3.1 diff --git a/src/tests/radmin/cmds/03-show-client-tcp-proto.ret b/src/tests/radmin/cmds/03-show-client-tcp-proto.ret new file mode 100644 index 00000000000..52692113afc --- /dev/null +++ b/src/tests/radmin/cmds/03-show-client-tcp-proto.ret @@ -0,0 +1,4 @@ +show client config 127.0.3.1 +shortname tapioca_test_tcp_client +secret 123testing +proto tcp diff --git a/src/tests/radmin/cmds/04-show-client-udp-proto.in b/src/tests/radmin/cmds/04-show-client-udp-proto.in new file mode 100644 index 00000000000..47abfb58d82 --- /dev/null +++ b/src/tests/radmin/cmds/04-show-client-udp-proto.in @@ -0,0 +1 @@ +show client config 127.0.2.1 diff --git a/src/tests/radmin/cmds/04-show-client-udp-proto.ret b/src/tests/radmin/cmds/04-show-client-udp-proto.ret new file mode 100644 index 00000000000..063ad8d002c --- /dev/null +++ b/src/tests/radmin/cmds/04-show-client-udp-proto.ret @@ -0,0 +1,4 @@ +show client config 127.0.2.1 +shortname paodequeijo_test_udp_client +secret testing123 +proto udp diff --git a/src/tests/radmin/cmds/05-show-config-item1.in b/src/tests/radmin/cmds/05-show-config-item1.in new file mode 100644 index 00000000000..19d5289c97c --- /dev/null +++ b/src/tests/radmin/cmds/05-show-config-item1.in @@ -0,0 +1 @@ +show config item myitem diff --git a/src/tests/radmin/cmds/05-show-config-item1.ret b/src/tests/radmin/cmds/05-show-config-item1.ret new file mode 100644 index 00000000000..6815220875e --- /dev/null +++ b/src/tests/radmin/cmds/05-show-config-item1.ret @@ -0,0 +1,2 @@ +show config item myitem +"It is my item" diff --git a/src/tests/radmin/config/control-socket.conf b/src/tests/radmin/config/control-socket.conf new file mode 100644 index 00000000000..e86c5eeed17 --- /dev/null +++ b/src/tests/radmin/config/control-socket.conf @@ -0,0 +1,71 @@ +# +# src/tests/radmin/config/control-socket.conf configuration file. +# Do not install. +# + +# +# Minimal radiusd.conf for testing radmin +# +raddb = raddb +testdir = build/tests/radmin +pidfile = ${testdir}/radiusd.pid +panic_action = "gdb -batch -x src/tests/panic.gdb %e %p > ${testdir}/gdb.log 2>&1; cat ${testdir}/gdb.log" +run_dir = build/tests/radmin + +security { + allow_vulnerable_openssl = yes +} + +# +# Load some modules +# +modules { + $INCLUDE ${raddb}/mods-enabled/always +} + +# +# Test entries +# +myitem = "It is my item" + +client rapadura_test_client { + ipaddr = 127.0.1.1 + secret = testing123 + proto = * +} + +client paodequeijo_test_udp_client { + ipaddr = 127.0.2.1 + secret = testing123 + proto = udp +} + +client tapioca_test_tcp_client { + ipaddr = 127.0.3.1 + secret = 123testing + proto = tcp +} + +# +# Based on src/tests/radmin/config/control-socket.conf +# +server control { + namespace = control + listen { + transport = unix + unix { + filename = build/tests/radmin/control-socket.sock +# peercred = no +# uid = radius +# gid = radius + mode = rw + } + } + recv { + ok + } + + send { + ok + } +}