Skip to content

Commit

Permalink
Investigation of #414
Browse files Browse the repository at this point in the history
New tests and help texts
  • Loading branch information
olofhagsand committed Feb 2, 2023
1 parent af1f5a0 commit 6d82c70
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/src/clixon_xpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ xpath_vec(cxobj *xcur,
goto done;
}
va_end(ap);
*vec=NULL;
*vec = NULL;
*veclen = 0;
if (xpath_vec_ctx(xcur, nsc, xpath, 0, &xr) < 0)
goto done;
Expand Down
14 changes: 14 additions & 0 deletions test/test_netconf_filter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS>
new "netconf commit"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><commit/></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"

new "given key show key"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get><filter type='xpath' select=\"/fi:x/fi:y[fi:a='1']/fi:a\" xmlns:fi='urn:example:filter' /></get></rpc>" "" "<rpc-reply $DEFAULTNS><data><x xmlns=\"urn:example:filter\"><y><a>1</a></y></x></data></rpc-reply>"

new "given key show value"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get><filter type='xpath' select=\"/fi:x/fi:y[fi:a='1']/fi:b\" xmlns:fi='urn:example:filter' /></get></rpc>" "" "<rpc-reply $DEFAULTNS><data><x xmlns=\"urn:example:filter\"><y><a>1</a><b>1</b></y></x></data></rpc-reply>"

# XXX Bug, see https://github.com/clicon/clixon/issues/414
#new "given value show key"
#expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get><filter type='xpath' select=\"/fi:x/fi:y[fi:b='1']/fi:a\" xmlns:fi='urn:example:filter' /></get></rpc>" "" "<rpc-reply $DEFAULTNS><data><x xmlns=\"urn:example:filter\"><y><a>1</a></y></x></data></rpc-reply>"

# OK, see motivation of case (2) in https://github.com/clicon/clixon/issues/414
new "given value show value"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get><filter type='xpath' select=\"/fi:x/fi:y[fi:b='1']/fi:b\" xmlns:fi='urn:example:filter' /></get></rpc>" "" "<rpc-reply $DEFAULTNS><data><x xmlns=\"urn:example:filter\"><y><a>1</a><b>1</b></y></x></data></rpc-reply>"

new "wrong filter type"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get><filter type='foo'><x xmlns='urn:example:filter'><y><a>1</a></y></x></filter></get></rpc>" "" "<rpc-reply $DEFAULTNS><rpc-error><error-tag>operation-failed</error-tag><error-type>applicatio</error-type><error-severity>error</error-severity><error-message>filter type not supported</error-message><error-info>type</error-info></rpc-error></rpc-reply>"

Expand Down
75 changes: 67 additions & 8 deletions test/test_xpath.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# - /aaa/bbb/comment, where "comment" is nodetype
# - //b*, combinations of // and "*"
# For more (outdated info): https://github.com/clicon/clixon/issues/54
# Test has three parts:
# - Only XML no YANG
# - negative tests with YANG
# - simple key/value test with YANG

# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
Expand All @@ -17,6 +21,9 @@ xml3=$dir/xml3.xml
xml4=$dir/xml4.xml
xmlfn=$dir/xmlfn.xml

fyang=$dir/clixon-example.yang


cat <<EOF > $xml
<aaa>
<bbb x="hello">
Expand Down Expand Up @@ -120,6 +127,25 @@ cat <<EOF > $xmlfn
</root>
EOF

cat <<EOF > $fyang
module clixon-example {
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
container table{
list parameter{
key name;
leaf name{
type string;
}
leaf value{
type string;
}
}
}
}
EOF

new "xpath not(aaa)"
expectpart "$($clixon_util_xpath -D $DBG -f $xml -p "not(aaa)")" 0 "bool:false"

Expand Down Expand Up @@ -325,6 +351,7 @@ expectpart "$($clixon_util_xpath -D $DBG -f $xmlfn -p "root/count/node[99=ancest
new "xpath functions as ncname: functioname:count"
expectpart "$($clixon_util_xpath -D $DBG -f $xmlfn -p "root/node/ancestor[73=count]")" 0 "<ancestor><count>73</count></ancestor>"

# PART 2
# Negative tests from fuzz crashes
cat <<EOF > $dir/1.xml
<table xmlns="urn:example:clixon">
Expand All @@ -340,56 +367,88 @@ cat <<EOF > $dir/1.xpath
EOF

new "negative xpath 1"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "bool:false"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "bool:false"

cat <<EOF > $dir/1.xpath
ter='x'/ex:table[exmeter='x']
EOF

new "negative xpath 2"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "bool:false"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "bool:false"

cat <<EOF > $dir/1.xpath
/ex:table<ex*ptramble
EOF

new "negative xpath 3"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "bool:false"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "bool:false"

cat <<EOF > $dir/1.xpath
7/ex:table['x']
EOF

new "negative xpath 4"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "number:7"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "number:7"

cat <<EOF > $dir/1.xpath
/>meter*//ter
EOF

new "negative xpath 5"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "bool:false"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "bool:false"

cat <<EOF > $dir/1.xpath
7=/ ter
EOF

new "negative xpath 6"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "bool:false"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "bool:false"

cat <<EOF > $dir/1.xpath
/=7 ter
EOF

new "negative xpath 7"
#expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "bool:false"
#expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "bool:false"

cat <<EOF > $dir/1.xpath
*<-9****
EOF

new "negative xpath 8"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "bool:false"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "bool:false"

# PART 3


cat <<EOF > $dir/1.xpath
/table/parameter[name='x']/name
EOF

new "given key show key"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "<name>x</name>"

cat <<EOF > $dir/1.xpath
/table/parameter[name='x']/value
EOF

new "given key show value"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "<value>42</value>"

cat <<EOF > $dir/1.xpath
/table/parameter[value='42']/name
EOF

new "given value show key"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "<name>x</name>"


cat <<EOF > $dir/1.xpath
/table/parameter[value='42']/value
EOF

new "given value show value"
expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "<value>42</value>"

rm -rf $dir

Expand Down

0 comments on commit 6d82c70

Please sign in to comment.