Changed invalid number ranges outside type scope.
This commit is contained in:
parent
4cd63f6b55
commit
6dec522af1
4 changed files with 73 additions and 8 deletions
|
|
@ -72,8 +72,8 @@
|
||||||
* Error messages for invalid number ranges and string lengths have been uniformed and changed.
|
* Error messages for invalid number ranges and string lengths have been uniformed and changed.
|
||||||
* Error messages for invalid ranges are now on the form:
|
* Error messages for invalid ranges are now on the form:
|
||||||
```
|
```
|
||||||
Number 23 out of range: 1-10
|
Number 23 out of range: 1 - 10
|
||||||
String length 23 out of range: 1-10
|
String length 23 out of range: 1 - 10
|
||||||
```
|
```
|
||||||
* On validation callbacks, XML_FLAG_ADD is added to all nodes at startup validation, not just the top-level. This is the same behaviour as for steady-state validation.
|
* On validation callbacks, XML_FLAG_ADD is added to all nodes at startup validation, not just the top-level. This is the same behaviour as for steady-state validation.
|
||||||
* All hash_ functions have been prefixed with `clicon_` to avoid name collision with other packages (frr)
|
* All hash_ functions have been prefixed with `clicon_` to avoid name collision with other packages (frr)
|
||||||
|
|
|
||||||
|
|
@ -626,7 +626,7 @@ outofrange(cg_var *cv0,
|
||||||
if (i>2)
|
if (i>2)
|
||||||
cprintf(cb, ", ");
|
cprintf(cb, ", ");
|
||||||
cv2cbuf(cv1, cb);
|
cv2cbuf(cv1, cb);
|
||||||
cprintf(cb, "-");
|
cprintf(cb, " - ");
|
||||||
cv2cbuf(cv2, cb);
|
cv2cbuf(cv2, cb);
|
||||||
}
|
}
|
||||||
if (reason && (*reason = strdup(cbuf_get(cb))) == NULL)
|
if (reason && (*reason = strdup(cbuf_get(cb))) == NULL)
|
||||||
|
|
@ -675,7 +675,7 @@ outoflength(uint64_t u64,
|
||||||
if (i>2)
|
if (i>2)
|
||||||
cprintf(cb, ", ");
|
cprintf(cb, ", ");
|
||||||
cv2cbuf(cv1, cb);
|
cv2cbuf(cv1, cb);
|
||||||
cprintf(cb, "-");
|
cprintf(cb, " - ");
|
||||||
cv2cbuf(cv2, cb);
|
cv2cbuf(cv2, cb);
|
||||||
}
|
}
|
||||||
if (reason && (*reason = strdup(cbuf_get(cb))) == NULL)
|
if (reason && (*reason = strdup(cbuf_get(cb))) == NULL)
|
||||||
|
|
|
||||||
|
|
@ -407,7 +407,7 @@ EOF
|
||||||
expectfn "$clixon_cli -1f $cfg -l o set num3 42" 0 '^$'
|
expectfn "$clixon_cli -1f $cfg -l o set num3 42" 0 '^$'
|
||||||
|
|
||||||
new "cli range test num3 260 fail"
|
new "cli range test num3 260 fail"
|
||||||
expectfn "$clixon_cli -1f $cfg -l o set num3 260" 255 '^CLI syntax error: "set num3 260": 260 is out of range\(type is uint8\)$'
|
expectfn "$clixon_cli -1f $cfg -l o set num3 260" 255 '^CLI syntax error: "set num3 260": Number 260 out of range: 0-255$'
|
||||||
|
|
||||||
new "cli range test num3 -1 fail"
|
new "cli range test num3 -1 fail"
|
||||||
expectfn "$clixon_cli -1f $cfg -l o set num3 -1" 255 "CLI syntax error:"
|
expectfn "$clixon_cli -1f $cfg -l o set num3 -1" 255 "CLI syntax error:"
|
||||||
|
|
@ -416,7 +416,7 @@ EOF
|
||||||
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></target><config><num3 xmlns="urn:example:clixon">260</num3></config></edit-config></rpc>]]>]]>' "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></target><config><num3 xmlns="urn:example:clixon">260</num3></config></edit-config></rpc>]]>]]>' "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
||||||
|
|
||||||
new "netconf validate num3 260 fail"
|
new "netconf validate num3 260 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>bad-element</error-tag><error-info><bad-element>num3</bad-element></error-info><error-severity>error</error-severity><error-message>260 is out of range(type is uint8)</error-message></rpc-error></rpc-reply>]]>]]>$'
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><validate><source><candidate/></source></validate></rpc>]]>]]>" '^<rpc-reply><rpc-error><error-type>application</error-type><error-tag>bad-element</error-tag><error-info><bad-element>num3</bad-element></error-info><error-severity>error</error-severity><error-message>Number 260 out of range: 0-255</error-message></rpc-error></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
new "netconf discard-changes"
|
new "netconf discard-changes"
|
||||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><discard-changes/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><discard-changes/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ module example{
|
||||||
length "1..10 | 14..20";
|
length "1..10 | 14..20";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* here follows constrained ints */
|
||||||
leaf lint8 {
|
leaf lint8 {
|
||||||
type tint8;
|
type tint8;
|
||||||
}
|
}
|
||||||
|
|
@ -103,6 +104,36 @@ module example{
|
||||||
leaf lstring {
|
leaf lstring {
|
||||||
type tstring;
|
type tstring;
|
||||||
}
|
}
|
||||||
|
/* here follows unlimited ints */
|
||||||
|
leaf rint8 {
|
||||||
|
type int8;
|
||||||
|
}
|
||||||
|
leaf rint16 {
|
||||||
|
type int16;
|
||||||
|
}
|
||||||
|
leaf rint32 {
|
||||||
|
type int32;
|
||||||
|
}
|
||||||
|
leaf rint64 {
|
||||||
|
type int64;
|
||||||
|
}
|
||||||
|
leaf ruint8 {
|
||||||
|
type uint8;
|
||||||
|
}
|
||||||
|
leaf ruint16 {
|
||||||
|
type uint16;
|
||||||
|
}
|
||||||
|
leaf ruint32 {
|
||||||
|
type uint32;
|
||||||
|
}
|
||||||
|
leaf ruint64 {
|
||||||
|
type uint64;
|
||||||
|
}
|
||||||
|
leaf rdecimal64 {
|
||||||
|
type decimal64{
|
||||||
|
fraction-digits 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
@ -168,9 +199,9 @@ testrange(){
|
||||||
|
|
||||||
if [ $t = "string" ]; then # special case for string type error msg
|
if [ $t = "string" ]; then # special case for string type error msg
|
||||||
len=$(echo -n "$eval" | wc -c)
|
len=$(echo -n "$eval" | wc -c)
|
||||||
errmsg="String length $len out of range: 1$post-10$post, 14$post-20$post"
|
errmsg="String length $len out of range: 1$post - 10$post, 14$post - 20$post"
|
||||||
else
|
else
|
||||||
errmsg="Number $eval$post out of range: 1$post-10$post, 14$post-20$post"
|
errmsg="Number $eval$post out of range: 1$post - 10$post, 14$post - 20$post"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "generated cli set $t leaf invalid"
|
new "generated cli set $t leaf invalid"
|
||||||
|
|
@ -212,6 +243,29 @@ testrange(){
|
||||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><discard-changes/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><discard-changes/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Type unlimited value range test. Only test invalid number out of range of type
|
||||||
|
# Parameters: 1: type (eg uint8)
|
||||||
|
# 2: val
|
||||||
|
# 3: post (eg .000 - special for decimal64, others should have "")
|
||||||
|
testunlimit(){
|
||||||
|
t=$1
|
||||||
|
val=$2
|
||||||
|
rmin=$3
|
||||||
|
rmax=$4
|
||||||
|
post=$5
|
||||||
|
|
||||||
|
errmsg="Number $val$post out of range: $rmin$post - $rmax$post"
|
||||||
|
|
||||||
|
new "Netconf set invalid $t leaf"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><edit-config><target><candidate/></target><config><l$t xmlns=\"urn:example:clixon\">$val</l$t></config></edit-config></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
||||||
|
|
||||||
|
new "netconf validate invalid range"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><validate><source><candidate/></source></validate></rpc>]]>]]>" "^<rpc-reply><rpc-error><error-type>application</error-type><error-tag>bad-element</error-tag><error-info><bad-element>l$t</bad-element></error-info><error-severity>error</error-severity><error-message>$errmsg</error-message></rpc-error></rpc-reply>]]>]]>$"
|
||||||
|
|
||||||
|
new "discard"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><discard-changes/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
||||||
|
}
|
||||||
|
|
||||||
if [ $BE -ne 0 ]; then
|
if [ $BE -ne 0 ]; then
|
||||||
new "kill old backend"
|
new "kill old backend"
|
||||||
sudo clixon_backend -zf $cfg
|
sudo clixon_backend -zf $cfg
|
||||||
|
|
@ -227,6 +281,17 @@ fi
|
||||||
|
|
||||||
new "test params: -f $cfg"
|
new "test params: -f $cfg"
|
||||||
|
|
||||||
|
# Test all int types
|
||||||
|
testunlimit int8 300 -128 127 ""
|
||||||
|
testunlimit int16 73000 -32768 32767 ""
|
||||||
|
testunlimit int32 4900000000 -2147483648 2147483647 ""
|
||||||
|
testunlimit int64 49739274983274983274983274 -9223372036854775808 9223372036854775807 ""
|
||||||
|
testunlimit uint8 300 0 255 ""
|
||||||
|
testunlimit uint16 73000 0 65535 ""
|
||||||
|
testunlimit uint32 4900000000 0 4294967295 ""
|
||||||
|
testunlimit uint64 49739274983274983274983274 0 18446744073709551615 ""
|
||||||
|
#testunlimit decimal64 49739274983274983274983274 -9223372036854775808 9223372036854775807 ".000"
|
||||||
|
|
||||||
# Test all int types
|
# Test all int types
|
||||||
for t in int8 int16 int32 int64 uint8 uint16 uint32 uint64; do
|
for t in int8 int16 int32 int64 uint8 uint16 uint32 uint64; do
|
||||||
testrange $t 1 0 ""
|
testrange $t 1 0 ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue