]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
make Net.* mutable for tests, and delete them in json.encode
authorAlan T. DeKok <aland@freeradius.org>
Sat, 2 Sep 2023 14:14:40 +0000 (10:14 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 2 Sep 2023 14:14:40 +0000 (10:14 -0400)
src/bin/unit_test_module.c
src/tests/modules/json/encode.unlang

index df4ea16b9966f08067de3f6991b4e5b4eeef2954..490af139f660fb34aadb8900b8bb69f662de08da 100644 (file)
@@ -76,10 +76,12 @@ fr_dict_autoload_t unit_test_module_dict[] = {
 };
 
 static fr_dict_attr_t const *attr_packet_type;
+static fr_dict_attr_t const *attr_net;
 
 extern fr_dict_attr_autoload_t unit_test_module_dict_attr[];
 fr_dict_attr_autoload_t unit_test_module_dict_attr[] = {
        { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_protocol },
+       { .out = &attr_net, .name = "Net", .type = FR_TYPE_TLV, .dict = &dict_freeradius },
 
        { NULL }
 };
@@ -231,7 +233,17 @@ static request_t *request_from_file(TALLOC_CTX *ctx, FILE *fp, fr_client_t *clie
        if (fr_packet_pairs_from_packet(request->request_ctx, &request->request_pairs, request->packet) < 0) {
                fr_strerror_const("Failed converting packet IPs to attributes");
                goto error;
-       }
+       }
+
+       /*
+        *      For lazines in the tests, allow the Net.* to be mutable
+        */
+       for (vp = fr_pair_dcursor_by_ancestor_init(&cursor, &request->request_pairs, attr_net);
+            vp != NULL;
+            vp = fr_dcursor_next(&cursor)) {
+               if (!fr_type_is_leaf(vp->vp_type)) continue;
+               vp->data.immutable = false;
+       }
 
        if (fr_debug_lvl) {
                for (vp = fr_pair_dcursor_init(&cursor, &request->request_pairs);
index d04d54cf98fd3ec05574af18360808bdf9a352c0..f2c5b82a7d0d39be1524b58114b9154cc52c7936 100644 (file)
@@ -3,6 +3,19 @@
 #
 &request -= &Packet-Type[*]
 
+#
+#  HACK: the edit code does not currently support deleted by parent
+#  when doing &request -= &Net[*]
+#  or even &request -= &Net.[*]
+#  which returns an error?
+#
+&request -= &Net.Src.IP
+&request -= &Net.Src.Port
+&request -= &Net.Dst.IP
+&request -= &Net.Dst.Port
+&request -= &Net.Timestamp
+&request -= &Net[*]
+
 # 0. Check basic xlat parsing
 &control.Tmp-String-1 := "%{json.encode:&request.[*]}"
 &control.Tmp-String-2 := "%{json.encode:&request.[*] }"