]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Use a proper event loop in unit_test_module.c and remove proto_radius from the test...
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 21 Nov 2017 11:03:31 +0000 (11:03 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 21 Nov 2017 11:17:45 +0000 (11:17 +0000)
We're testing unlang keywords, not the proto_radius module

src/main/unit_test_module.c

index fadb74d1f62db353227837fa66cf1e1364b15758..d08463d4c4d727100d5a24ae7400518e9da34c24 100644 (file)
@@ -662,7 +662,8 @@ int main(int argc, char *argv[])
        fr_state_tree_t         *state = NULL;
        fr_event_list_t         *el = NULL;
        RADCLIENT               *client = NULL;
-
+       CONF_SECTION            *unlang;
+       char                    *auth_type;
        fr_talloc_fault_setup();
 
        /*
@@ -908,6 +909,7 @@ int main(int argc, char *argv[])
                rcode = EXIT_FAILURE;
                goto finish;
        }
+       request->el = el;
 
        /*
         *      No filter file, OR there's no more input, OR we're
@@ -952,10 +954,68 @@ int main(int argc, char *argv[])
        }
 
        /*
-        *      FIXME: create scheduler and inject packets into that!!!
+        *      Simulate an authorize section
+        */
+       unlang = cf_section_find(request->server_cs, "recv", "Access-Request");
+       if (!unlang) {
+               REDEBUG("Failed to find 'recv Access-Request' section");
+               request->reply->code = FR_CODE_ACCESS_REJECT;
+               goto done;
+       }
+
+       switch (unlang_interpret_synchronous(request, unlang, RLM_MODULE_NOOP)) {
+       case RLM_MODULE_OK:
+       case RLM_MODULE_UPDATED:
+       case RLM_MODULE_NOOP:
+               request->reply->code = FR_CODE_ACCESS_ACCEPT;
+               break;
+
+       default:
+               request->reply->code = FR_CODE_ACCESS_REJECT;
+               goto done;
+       }
+
+       /*
+        *      Simulate an authenticate section
         */
-       rad_virtual_server(request);
+       vp = fr_pair_find_by_num(request->control, 0, FR_AUTH_TYPE, TAG_ANY);
+       if (!vp) goto done;
+
+       switch (vp->vp_int32) {
+       case FR_AUTH_TYPE_ACCEPT:
+               request->reply->code = FR_CODE_ACCESS_ACCEPT;
+               goto done;
+
+       case FR_AUTH_TYPE_REJECT:
+               request->reply->code = FR_CODE_ACCESS_REJECT;
+               goto done;
+
+       default:
+               break;
+       }
+
+       auth_type = fr_pair_value_asprint(vp, vp, '\0');
+       unlang = cf_section_find(request->server_cs, "authenticate", auth_type);
+       talloc_free(auth_type);
+       if (!unlang) {
+               REDEBUG("Failed to find 'recv %s' section", auth_type);
+               request->reply->code = FR_CODE_ACCESS_REJECT;
+               goto done;
+       }
+
+       switch (unlang_interpret_synchronous(request, unlang, RLM_MODULE_NOOP)) {
+       case RLM_MODULE_OK:
+       case RLM_MODULE_UPDATED:
+       case RLM_MODULE_NOOP:
+               request->reply->code = FR_CODE_ACCESS_ACCEPT;
+               break;
+
+       default:
+               request->reply->code = FR_CODE_ACCESS_REJECT;
+               goto done;
+       }
 
+done:
        if (!output_file || (strcmp(output_file, "-") == 0)) {
                fp = stdout;
        } else {