Skip to content

Commit

Permalink
Fixed: [NACM create rules do not work properly on objects with defaul…
Browse files Browse the repository at this point in the history
…t values](#506)

Extend testcase
  • Loading branch information
olofhagsand committed Apr 3, 2024
1 parent 3a0a5c3 commit 75aaae3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/src/clixon_datastore_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,14 @@ text_modify(clixon_handle h,
}
case OP_REPLACE: /* fall thru */
case OP_MERGE:
/* If default flag, clear it */
if (x0 && xml_flag(x0, XML_FLAG_DEFAULT))
xml_flag_reset(x0, XML_FLAG_DEFAULT);
if (!(op == OP_MERGE && (instr==NULL))) {
/* Remove existing, also applies to merge in the special case
* of ordered-by user and (changed) insert attribute.
*/
if (!permit && xnacm){
if ((ret = nacm_datanode_write(h, x1, x1t, x0?NACM_UPDATE:NACM_CREATE, username, xnacm, cbret)) < 0)
if ((ret = nacm_datanode_write(h, x1, x1t,
(x0 == NULL || xml_default_nopresence(x0, 0, 0))?NACM_CREATE:NACM_UPDATE,
username, xnacm, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
Expand All @@ -603,6 +602,9 @@ text_modify(clixon_handle h,
x0 = NULL;
}
} /* OP_MERGE & insert */
/* If default flag, clear it, since replaced */
if (x0 && xml_flag(x0, XML_FLAG_DEFAULT))
xml_flag_reset(x0, XML_FLAG_DEFAULT);
case OP_NONE: /* fall thru */
if (x0==NULL){
if ((op != OP_NONE) && !permit && xnacm){
Expand Down Expand Up @@ -718,7 +720,6 @@ text_modify(clixon_handle h,
/* Purge if x1 value is NULL(match-all) or both values are equal */
if ((x1bstr == NULL) ||
((x0bstr=xml_body(x0)) != NULL && strcmp(x0bstr, x1bstr)==0)){

if (xml_purge(x0) < 0)
goto done;
xml_flag_set(x0p, XML_FLAG_DEL);
Expand Down
9 changes: 9 additions & 0 deletions test/test_nacm_module_write.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ module nacm-example{
import ietf-netconf-acm {
prefix nacm;
}
container global {
leaf enabled {
type boolean;
default false;
}
}
leaf x{
type int32;
description "something to edit";
Expand Down Expand Up @@ -283,6 +289,9 @@ expectpart "$(curl -u wilma:bar $CURLOPTS -X PUT -H "Content-Type: application/y
new "default delete list deny"
expectpart "$(curl -u wilma:bar $CURLOPTS -X DELETE $RCPROTO://localhost/restconf/data/clixon-example:table/parameter=key42)" 0 "HTTP/$HVER 403" '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"access-denied","error-severity":"error","error-message":"default deny"}}'

new "create leaf w default value"
expectpart "$(curl -u wilma:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+json" $RCPROTO://localhost/restconf/data/nacm-example:global/enabled -d '{"nacm-example:enabled": true}')" 0 "HTTP/$HVER 201"

if [ $RC -ne 0 ]; then
new "Kill restconf daemon"
stop_restconf
Expand Down

0 comments on commit 75aaae3

Please sign in to comment.