From: Jason Ish Date: Tue, 24 Jan 2023 23:26:29 +0000 (-0600) Subject: yaml-loader: add test for fully qualified override X-Git-Tag: suricata-7.0.0-rc1~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb1ae92a1bc5b7e9821daa5db8ed0f2e339be1b8;p=thirdparty%2Fsuricata.git yaml-loader: add test for fully qualified override Also set the parent node for regular nodes on creation as this is useful in unit-tests to verify the parent of a node. --- diff --git a/src/conf-yaml-loader.c b/src/conf-yaml-loader.c index d941db69f6..e7906b0a48 100644 --- a/src/conf-yaml-loader.c +++ b/src/conf-yaml-loader.c @@ -316,6 +316,7 @@ ConfYamlParse(yaml_parser_t *parser, ConfNode *parent, int inseq, int rlevel) } else { node = ConfNodeNew(); node->name = SCStrdup(value); + node->parent = parent; if (node->name && strchr(node->name, '_')) { if (!(parent->name && ((strcmp(parent->name, "address-groups") == 0) || @@ -858,19 +859,22 @@ ConfYamlFileIncludeTest(void) static int ConfYamlOverrideTest(void) { - char config[] = - "%YAML 1.1\n" - "---\n" - "some-log-dir: /var/log\n" - "some-log-dir: /tmp\n" - "\n" - "parent:\n" - " child0:\n" - " key: value\n" - "parent:\n" - " child1:\n" - " key: value\n" - ; + char config[] = "%YAML 1.1\n" + "---\n" + "some-log-dir: /var/log\n" + "some-log-dir: /tmp\n" + "\n" + "parent:\n" + " child0:\n" + " key: value\n" + "parent:\n" + " child1:\n" + " key: value\n" + "vars:\n" + " address-groups:\n" + " HOME_NET: \"[192.168.0.0/16,10.0.0.0/8,172.16.0.0/12]\"\n" + " EXTERNAL_NET: any\n" + "vars.address-groups.HOME_NET: \"10.10.10.10/32\"\n"; const char *value; ConfCreateContextBackup(); @@ -885,6 +889,24 @@ ConfYamlOverrideTest(void) FAIL_IF_NOT(ConfGet("parent.child1.key", &value)); FAIL_IF(strcmp(value, "value") != 0); + /* First check that vars.address-groups.EXTERNAL_NET has the + * expected parent of vars.address-groups and save this + * pointer. We want to make sure that the overrided value has the + * same parent later on. */ + ConfNode *vars_address_groups = ConfGetNode("vars.address-groups"); + FAIL_IF_NULL(vars_address_groups); + ConfNode *vars_address_groups_external_net = ConfGetNode("vars.address-groups.EXTERNAL_NET"); + FAIL_IF_NULL(vars_address_groups_external_net); + FAIL_IF_NOT(vars_address_groups_external_net->parent == vars_address_groups); + + /* Now check that HOME_NET has the overrided value. */ + ConfNode *vars_address_groups_home_net = ConfGetNode("vars.address-groups.HOME_NET"); + FAIL_IF_NULL(vars_address_groups_home_net); + FAIL_IF(strcmp(vars_address_groups_home_net->val, "10.10.10.10/32") != 0); + + /* And check that it has the correct parent. */ + FAIL_IF_NOT(vars_address_groups_home_net->parent == vars_address_groups); + ConfDeInit(); ConfRestoreContextBackup();