#!/bin/bash # Restconf error-code functionality # See RFC8040 # Testcases: # Sec 4.3 (GET): If a retrieval request for a data resource represents an # instance that does not exist, then an error response containing a "404 Not # Found" status-line MUST be returned by the server. The error-tag # value "invalid-value" is used in this case. # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi APPNAME=example cfg=$dir/conf.xml fyang=$dir/restconf.yang fxml=$dir/initial.xml # example cat < $cfg $cfg /usr/local/share/clixon $IETFRFC $fyang false /usr/local/var/$APPNAME/$APPNAME.sock $dir/restconf.pidfile /usr/local/var/$APPNAME EOF cat < $fyang module example{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; list a { key k; leaf k { type int32; } leaf description{ type string; } leaf b{ type string; } container c{ presence "for test"; } list d{ key k; leaf k { type string; } } } } EOF # Initial tree XML=$(cat <0No leaf b, No container c, No leaf d EOF ) new "test params: -f $cfg" if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi sudo pkill clixon_backend # to be sure new "start backend -s init -f $cfg" start_backend -s init -f $cfg fi new "kill old restconf daemon" sudo pkill -u www-data -f "/www-data/clixon_restconf" new "start restconf daemon" start_restconf -f $cfg new "waiting" wait_backend wait_restconf new "restconf POST initial tree" expecteq "$(curl -s -X POST -H 'Content-Type: application/yang-data+xml' -d "$XML" http://localhost/restconf/data)" 0 '' new "restconf GET initial datastore" expecteq "$(curl -s -X GET -H 'Accept: application/yang-data+xml' http://localhost/restconf/data/example:a)" 0 "$XML " new "restconf GET non-existent container header" expectfn "curl -s -I -X GET http://localhost/restconf/data/example:a/c" 0 "HTTP/1.1 404 Not Found" new "restconf GET non-existent container body" expectfn "curl -s -X GET http://localhost/restconf/data/example:a/c" 0 '{"ietf-restconf:errors":{"error":{"rpc-error":{"error-type":"application","error-tag":"invalid-value","error-severity":"error","error-message":"Instance does not exist"}}}}' new "Kill restconf daemon" stop_restconf if [ $BE -eq 0 ]; then exit # BE fi new "Kill backend" # Check if premature kill pid=`pgrep -u root -f clixon_backend` if [ -z "$pid" ]; then err "backend already dead" fi # kill backend stop_backend -f $cfg rm -rf $dir