From 40f3d48f2bb0e6bf46f85a74941a321a118d437e Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 10 Jun 2019 13:56:06 +0200 Subject: [PATCH] Restconf uri with mismatching keys problem --- lib/src/clixon_xml_map.c | 2 +- test/test_restconf_listkey.sh | 46 ++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index 72cceb71..04cb8b79 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -2503,7 +2503,7 @@ api_path2xml_vec(char **vec, else{ if ((valvec = clicon_strsep(restval, ",", &nvalvec)) == NULL) goto done; - if (nvalvec > cvec_len(cvk)){ + if (nvalvec != cvec_len(cvk)){ clicon_err(OE_XML, EINVAL, "List key %s length mismatch", name); goto fail; } diff --git a/test/test_restconf_listkey.sh b/test/test_restconf_listkey.sh index 54e8e953..4a33b21a 100755 --- a/test/test_restconf_listkey.sh +++ b/test/test_restconf_listkey.sh @@ -42,6 +42,19 @@ module list{ description "non-key element"; type string; } + list e{ + description "A list in a list"; + key "f"; + leaf f{ + type string; + } + leaf nonkey{ + type string; + } + } + leaf-list f{ + type string; + } } leaf-list d{ type string; @@ -84,16 +97,16 @@ new "restconf PUT change list entry (wrong keys)(expect fail)" expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x,y -d {"list:a":{"b":"y","c":"x"}}' 0 '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "operation-failed","error-severity": "error","error-message": "api-path keys do not match data keys"}}}' new "restconf PUT change list entry (just one key)(expect fail)" -expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x -d {"list:a":{"b":"x"}}' 0 '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "operation-failed","error-severity": "error","error-message": "api-path keys do not match data keys"}}}' +expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x -d {"list:a":{"b":"x"}}' 0 '{"ietf-restconf:errors" : {"error": {"error-type": "rpc","error-tag": "malformed-message","error-severity": "error","error-message": "List key a length mismatch"}}} ' new "restconf PUT sub non-key" expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x,y/nonkey -d {"list:nonkey":"u"}' 0 '' new "restconf PUT sub key same value" -expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x/b -d {"b":"x"}' 0 '' +expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x,y/b -d {"list:b":"x"}' 0 '' -new "restconf PUT just key other value (should fail)" -expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x/b -d {"b":"y"}' 0 '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "operation-failed","error-severity": "error","error-message": "api-path keys do not match data keys"}}}' +new "restconf PUT just key other value (should fail)ZX" +expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x/b -d {"b":"y"}' 0 '{"ietf-restconf:errors" : {"error": {"error-type": "rpc","error-tag": "malformed-message","error-severity": "error","error-message": "List key a length mismatch"}}}' new "restconf PUT add leaf-list entry" expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/d=x -d {"list:d":"x"}' 0 '' @@ -101,6 +114,31 @@ expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/d=x -d {"list:d": new "restconf PUT change leaf-list entry (expect fail)" expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/d=x -d {"list:d":"y"}' 0 '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "operation-failed","error-severity": "error","error-message": "api-path keys do not match data keys"}}}' +new "restconf PUT list-list" +expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x,y/e=z -d {"list:e":{"f":"z","nonkey":"0"}}' 0 '' + +new "restconf PUT change list-lst entry (wrong keys)(expect fail)" +expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x,y/e=z -d {"list:e":{"f":"wrong","nonley":"0"}}' 0 '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "operation-failed","error-severity": "error","error-message": "api-path keys do not match data keys"}}}' + +new "restconf PUT list-list sub non-key" +expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x,y/e=z/nonkey -d {"list:nonkey":"u"}' 0 '' + +new "restconf PUT list-list single first key" +expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x/e=z/f -d {"f":"z"}' 0 '{"ietf-restconf:errors" : {"error": {"error-type": "rpc","error-tag": "malformed-message","error-severity": "error","error-message": "List key a length mismatch"}}}' + +new "restconf PUT list-list just key ok" +expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x,y/e=z/f -d {"f":"z"}' 0 '' + +new "restconf PUT list-list just key just key wrong value (should fail)" +expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x,y/e=z/f -d {"f":"wrong"}' 0 '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "operation-failed","error-severity": "error","error-message": "api-path keys do not match data keys"}}}' + +new "restconf PUT add list+leaf-list entry" +expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x,y/f=u -d {"list:f":"u"}' 0 '' + +new "restconf PUT change list+leaf-list entry (expect fail)" +expectfn 'curl -s -X PUT http://localhost/restconf/data/list:c/a=x,y/f=u -d {"list:f":"w"}' 0 '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "operation-failed","error-severity": "error","error-message": "api-path keys do not match data keys"}}}' + + new "Kill restconf daemon" stop_restconf