EXIT_WITH_FAILURE;
}
- /*
- * Manually load the protocol dictionary, unless it's "test"
- */
- if (strcmp(PROTOCOL_NAME, "test") != 0) {
- if (fr_dict_autoload(unit_test_module_dict) < 0) {
- fr_perror("%s", config->name);
- EXIT_WITH_FAILURE;
- }
- } else {
- dict_protocol = fr_dict_internal();
- dict_freeradius = dict_protocol;
+ if (fr_dict_autoload(unit_test_module_dict) < 0) {
+ fr_perror("%s", config->name);
+ EXIT_WITH_FAILURE;
}
-
if (fr_dict_attr_autoload(unit_test_module_dict_attr) < 0) {
fr_perror("%s", config->name);
EXIT_WITH_FAILURE;
* Do some sanity checking.
*/
dict_check = virtual_server_dict_by_name("default");
-
if (!dict_check || (dict_check != dict_protocol)) {
ERROR("Virtual server namespace does not match requested namespace '%s'", PROTOCOL_NAME);
EXIT_WITH_FAILURE;
/*
* Free our explicitly loaded internal dictionary
*/
- if ((dict_protocol != dict_freeradius) &&
- (fr_dict_free(&dict, __FILE__) < 0)) {
+ if (fr_dict_free(&dict, __FILE__) < 0) {
fr_perror("unit_test_module - dict");
ret = EXIT_FAILURE;
}
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/arp/arp.h>
-static fr_dict_t const *dict_freeradius;
+static fr_dict_t const *dict_test;
extern fr_dict_autoload_t process_test_dict[];
fr_dict_autoload_t process_test_dict[] = {
- { .out = &dict_freeradius, .proto = "freeradius" },
+ { .out = &dict_test, .proto = "test" },
{ NULL }
};
extern fr_dict_attr_autoload_t process_test_dict_attr[];
fr_dict_attr_autoload_t process_test_dict_attr[] = {
- { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_freeradius},
+ { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_test},
{ NULL }
};
request->component = "test";
request->module = NULL;
- fr_assert(request->dict == dict_freeradius);
+ fr_assert(request->dict == dict_test);
UPDATE_STATE(packet);
},
.process = mod_process,
.compile_list = compile_list,
- .dict = &dict_freeradius,
+ .dict = &dict_test,
};
test_fail {
&reply += {
- &Result-Status = "Failure in test at line %(interpreter:...line)"
+ &Result-Status = "Failure in test file %(interpreter:...filename) at line %(interpreter:...line)"
}
if (&parent.request) {
&parent.reply += {
- &Result-Status = "Failure in test at line %(interpreter:...line)"
+ &Result-Status = "Failure in test file %(interpreter:...filename) at line %(interpreter:...line)"
}
}
}
# -S parse_new_conditions=yes -S use_new_conditions=yes -S forbid_update=yes
+#
+# The dictionaries are in "share", because the server tries to load
+# local dictionaries from "./dictionary".
+#
+src/tests/process/share/%: ${top_srcdir}/share/dictionary/%
+ @ln -sf $< $@
+
+ifneq "$(OPENSSL_LIBS)" ""
+PROCESS_DICT_TLS := $(DIR)/share/tls
+endif
#
# For sheer laziness, allow "make test.process.foo"
# With filenames added for the output files
#
$(OUTPUT)/${1}: $(patsubst %,${BUILD_DIR}/lib/local/process_%.la,$(subst /,,$(dir ${1})) test)
+
+$(OUTPUT)/${1}: $(DIR)/$(subst /,,$(dir ${1}))/server.conf
+
+$(OUTPUT)/${1}: | $(DIR)/share/$(subst /,,$(dir ${1})) $(DIR)/share/freeradius $(PROCESS_DICT_TLS)
endef
$(foreach x,$(FILES),$(eval $(call PROCESS_TEST,$x)))
# (make -k test.process 2>&1) | grep 'PROCESS=' | sed 's/PROCESS=//;s/ .*$//'
#
PROCESS_ARGS := -p test
-PROCESS_ARGS += -D share/dictionary -d $(DIR)/
+PROCESS_ARGS += -D $(DIR)/share -d $(DIR)/
PROCESS_ARGS += -S parse_new_conditions=yes -S use_new_conditions=yes -S forbid_update=yes
-PROCESS_ARGS += -i $(DIR)/test.attrs
+PROCESS_ARGS += -i $(DIR)/test.attrs -f $(DIR)/test.attrs
$(OUTPUT)/%: $(DIR)/% $(TEST_BIN_DIR)/unit_test_module $(DIR)/unit_test_module.conf
- $(eval CMD:=PROCESS=$< $(TEST_BIN)/unit_test_module $(PROCESS_ARGS) -r "$@" -xx)
+ $(eval CMD:=PROCESS=$< PROTOCOL=$(dir $<) $(TEST_BIN)/unit_test_module $(PROCESS_ARGS) -r "$@" -xx)
@echo PROCESS-TEST $(notdir $@)
@mkdir -p $(dir $@)
@if ! $(CMD) > "$@.log" 2>&1 || ! test -f "$@"; then \
--- /dev/null
+#
+# Common policies for the test cases.
+#
+# Copied from test.keywords with some minor changesk
+#
+#
+
+#
+# Outputs the contents of the control list in debugging (-X) mode
+#
+debug_control {
+ %(debug_attr:&control.[*])
+}
+
+#
+# Outputs the contents of the request list in debugging (-X) mode
+#
+debug_request {
+ %(debug_attr:&request.[*])
+}
+
+#
+# Outputs the contents of the reply list in debugging (-X) mode
+#
+debug_reply {
+ %(debug_attr:&reply.[*])
+}
+
+#
+# Outputs the contents of the main lists in debugging (-X) mode
+#
+debug_all {
+ debug_control
+ debug_request
+ debug_reply
+}
+
+#
+# Set the test to successful, but only if there are no failures.
+#
+success {
+ &reply.Result-Status = "success"
+
+ ok
+}
+
+test_fail {
+ &reply += {
+ &Failure = "Failure in test file %(interpreter:....filename) at line %(interpreter:...line)"
+ }
+
+ if (&parent.request) {
+ &parent.reply += {
+ &Failure = "Failure in test file %(interpreter:....filename) at line %(interpreter:...line)"
+ }
+ }
+}
+subrequest RADIUS.Access-Request {
+ &User-Name = "bob"
+ &User-Password = "hello"
+
+
+ call radius {
+ if (&reply.Packet-Type != Access-Accept) {
+ test_fail
+ }
+ }
+}
--- /dev/null
+#
+# Send Access-Accept immediately
+#
+accept {
+ &reply.Packet-Type := Access-Accept
+
+ handled
+}
+
+#
+# Send Access-Challenge immediately
+#
+challenge {
+ &reply.Packet-Type := Access-Challenge
+
+ handled
+}
--- /dev/null
+server radius {
+ namespace = radius
+
+recv Access-Request {
+ accept
+}
+
+send Access-Accept {
+ ok
+}
+
+send Access-Challenge {
+ &reply.Reply-Message := "challenge"
+}
+
+}
\ No newline at end of file
--- /dev/null
+*
+!test
+!.gitignore
+PROTOCOL Test 314159
+
+BEGIN-PROTOCOL Test
+
#
# Only for tests.
#
DEFINE Packet-Type uint32
VALUE Packet-Type Request 1
VALUE Packet-Type Reply 2
+
+END-PROTOCOL Test
+
+#
+# Generic test failure message
+#
+DEFINE Failure string
}
+policy {
+$-INCLUDE $ENV{PROTOCOL}/policy.conf
+$INCLUDE policy.conf
+}
+
+#
+# Include the virtual server for the protocol
+#
+$INCLUDE $ENV{PROTOCOL}/server.conf
+
+#
+# And our basic test framework.
+#
server default {
namespace = test
test {
}
+ #
+ # This section runs the per-protocol state machine.
+ #
+ # It creates subrequests, calls the per-protocol process
+ # routine, and checks the results.
+ #
recv Request {
-
+#
+# All of the tests run within a "subrequest".
+#
$INCLUDE $ENV{PROCESS}
-
- ok
}
send Reply {
- ok
+ if (!&reply.Failure) {
+ success
+ }
}
}