Skip to content

Commit

Permalink
* Fixed [identityref validation fails when using typedef #87](#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Jun 20, 2019
1 parent 97529a2 commit c90aa83
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 13 additions & 12 deletions lib/src/clixon_xml_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion lib/src/clixon_yang_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 54 additions & 2 deletions test/test_identity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,31 @@ cat <<EOF > $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"
Expand All @@ -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"
Expand Down Expand Up @@ -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 '<rpc><edit-config><target><candidate/></target><config><acls xmlns="urn:example:my-crypto"><acl><name>x</name><type>mc:ipv4-acl-type</type></acl></acls></config></edit-config></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'

new "netconf validate "
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><validate><source><candidate/></source></validate></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"

new "Netconf set undefined acl-type"
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></target><config><acls xmlns="urn:example:my-crypto"><acl><name>x</name><type>undefined</type></acl></acls></config></edit-config></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'

new "netconf validate fail"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><validate><source><candidate/></source></validate></rpc>]]>]]>" '^<rpc-reply><rpc-error><error-type>application</error-type><error-tag>operation-failed</error-tag><error-severity>error</error-severity><error-message>Identityref validation failed, Identityref validation failed, not derived from acl-base</error-message></rpc-error></rpc-reply>]]>]]>$'

new "netconf discard-changes"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><discard-changes/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"

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
Expand Down

0 comments on commit c90aa83

Please sign in to comment.