diff --git a/CHANGELOG.md b/CHANGELOG.md index 988fd9f9..870710bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -251,6 +251,7 @@ ### Corrected Bugs +* Fixed [identityref validation fails when using typedef #87](https://github.com/clicon/clixon/issues/87) * Fixed a problem with some netconf error messages caused restconf daemon to exit due to no XML encoding * Check cligen tab mode, dont start if CLICON_CLI_TAB_MODE is undefined * Startup transactions did not mark added tree with XML_FLAG_ADD as it should. diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index a536e679..3abfcb3a 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -1206,19 +1206,20 @@ xml_yang_validate_all(clicon_handle h, /* Special case if leaf is leafref, then first check against current xml tree */ - if ((yc = yang_find(ys, Y_TYPE, NULL)) != NULL){ - if (strcmp(yc->ys_argument, "leafref") == 0){ - if ((ret = validate_leafref(xt, yc, xret)) < 0) - goto done; - if (ret == 0) - goto fail; - } - else if (strcmp(yc->ys_argument, "identityref") == 0){ - if ((ret = validate_identityref(xt, ys, yc, xret)) < 0) - goto done; - if (ret == 0) - goto fail; + /* Get base type yc */ + if (yang_type_get(ys, NULL, &yc, NULL, NULL, NULL, NULL, NULL) < 0) + goto done; + if (strcmp(yang_argument_get(yc), "leafref") == 0){ + if ((ret = validate_leafref(xt, yc, xret)) < 0) + goto done; + if (ret == 0) + goto fail; } + else if (strcmp(yang_argument_get(yc), "identityref") == 0){ + if ((ret = validate_identityref(xt, ys, yc, xret)) < 0) + goto done; + if (ret == 0) + goto fail; } break; default: diff --git a/lib/src/clixon_yang_type.c b/lib/src/clixon_yang_type.c index 3e00f7e8..61c63d43 100644 --- a/lib/src/clixon_yang_type.c +++ b/lib/src/clixon_yang_type.c @@ -1416,13 +1416,14 @@ yang_type_resolve(yang_stmt *yorig, * * @code * yang_stmt *yrestype; + * char *origtype = NULL; * int options; * cvec *cvv = NULL; * cvec *patterns = cvec_new(0); * cvec *regexps = cvec_new(0); * uint8_t fraction; * - * if (yang_type_get(ys, &type, &yrestype, &options, &cvv, + * if (yang_type_get(ys, &origtype, &yrestype, &options, &cvv, * patterns, regexps, &fraction) < 0) * goto err; * if (yrestype == NULL) # unresolved diff --git a/test/test_identity.sh b/test/test_identity.sh index a31b1bbb..782e8fa6 100755 --- a/test/test_identity.sh +++ b/test/test_identity.sh @@ -106,7 +106,31 @@ cat < $fyang container aes-parameters { when "../crypto = 'mc:aes'"; } - } + identity acl-base; + typedef acl-type { + description "problem detected in ietf-access-control-list.yang"; + type identityref { + base acl-base; + } + } + identity ipv4-acl-type { + base mc:acl-base; + } + identity ipv6-acl-type { + base mc:acl-base; + } + container acls { + list acl { + key name; + leaf name { + type string; + } + leaf type { + type acl-type; + } + } + } + } EOF new "test params: -f $cfg" @@ -120,7 +144,7 @@ if [ $BE -ne 0 ]; then start_backend -s init -f $cfg new "waiting" - sleep $RCWAIT + wait_backend fi new "Set crypto to aes" @@ -186,6 +210,34 @@ expectfn "$clixon_cli -1 -f $cfg -l o set crypto des:des3" 0 "^$" new "cli validate" expectfn "$clixon_cli -1 -f $cfg -l o validate" 0 "^$" +new "Netconf set acl-type" +expecteof "$clixon_netconf -qf $cfg" 0 'xmc:ipv4-acl-type]]>]]>' '^]]>]]>$' + +new "netconf validate " +expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" + +new "Netconf set undefined acl-type" +expecteof "$clixon_netconf -qf $cfg" 0 'xundefined]]>]]>' '^]]>]]>$' + +new "netconf validate fail" +expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" '^applicationoperation-failederrorIdentityref validation failed, Identityref validation failed, not derived from acl-base]]>]]>$' + +new "netconf discard-changes" +expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" + +new "CLI set acl-type" +expectfn "$clixon_cli -1 -f $cfg -l o set acls acl x type mc:ipv4-acl-type" 0 "^$" + +new "cli validate" +expectfn "$clixon_cli -1 -f $cfg -l o validate" 0 "^$" + +new "CLI set wrong acl-type" +expectfn "$clixon_cli -1 -f $cfg -l o set acls acl x type undefined" 0 "^$" + +new "cli validate" +expectfn "$clixon_cli -1 -f $cfg -l o validate" 255 "Identityref validation failed" + + if [ $BE -eq 0 ]; then exit # BE fi