]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add tests for radmin/control-socket
authorJorge Pereira <jpereira@freeradius.org>
Wed, 2 Oct 2019 01:36:24 +0000 (22:36 -0300)
committerAlan DeKok <aland@freeradius.org>
Sun, 6 Oct 2019 11:34:23 +0000 (07:34 -0400)
16 files changed:
Makefile
src/tests/all.mk
src/tests/radmin/all.mk [new file with mode: 0644]
src/tests/radmin/cmds/00-help.in [new file with mode: 0644]
src/tests/radmin/cmds/00-help.ret [new file with mode: 0644]
src/tests/radmin/cmds/01-help-all.in [new file with mode: 0644]
src/tests/radmin/cmds/01-help-all.ret [new file with mode: 0644]
src/tests/radmin/cmds/02-show-client-all-proto.in [new file with mode: 0644]
src/tests/radmin/cmds/02-show-client-all-proto.ret [new file with mode: 0644]
src/tests/radmin/cmds/03-show-client-tcp-proto.in [new file with mode: 0644]
src/tests/radmin/cmds/03-show-client-tcp-proto.ret [new file with mode: 0644]
src/tests/radmin/cmds/04-show-client-udp-proto.in [new file with mode: 0644]
src/tests/radmin/cmds/04-show-client-udp-proto.ret [new file with mode: 0644]
src/tests/radmin/cmds/05-show-config-item1.in [new file with mode: 0644]
src/tests/radmin/cmds/05-show-config-item1.ret [new file with mode: 0644]
src/tests/radmin/config/control-socket.conf [new file with mode: 0644]

index e44157f4e38d9dfb6b378ea50e8271fe50b3b599..be3df5caeda4e8d6f74f0546690238796b56811b 100644 (file)
--- 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
index 0a3861c4c37c0cf641421fb9c6a24bce614f12af..054672e1b385a291a47376a8f4ccc9dc7fa10798 100644 (file)
@@ -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 (file)
index 0000000..796d9be
--- /dev/null
@@ -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 (file)
index 0000000..a87bf43
--- /dev/null
@@ -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 (file)
index 0000000..f29737e
--- /dev/null
@@ -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 (file)
index 0000000..a87bf43
--- /dev/null
@@ -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 (file)
index 0000000..f29737e
--- /dev/null
@@ -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 (file)
index 0000000..91480f9
--- /dev/null
@@ -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 (file)
index 0000000..9ea2801
--- /dev/null
@@ -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 (file)
index 0000000..27ae51a
--- /dev/null
@@ -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 (file)
index 0000000..5269211
--- /dev/null
@@ -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 (file)
index 0000000..47abfb5
--- /dev/null
@@ -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 (file)
index 0000000..063ad8d
--- /dev/null
@@ -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 (file)
index 0000000..19d5289
--- /dev/null
@@ -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 (file)
index 0000000..6815220
--- /dev/null
@@ -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 (file)
index 0000000..e86c5ee
--- /dev/null
@@ -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
+       }
+}