diff --git a/apps/restconf/restconf_main_native.c b/apps/restconf/restconf_main_native.c index 2f4ec52f..5a19b6db 100644 --- a/apps/restconf/restconf_main_native.c +++ b/apps/restconf/restconf_main_native.c @@ -332,6 +332,13 @@ evhtp_method2str(enum htp_method m) case htp_method_DELETE: return "DELETE"; break; + case htp_method_OPTIONS: + return "OPTIONS"; + break; + case htp_method_PATCH: + return "PATCH"; + break; +#ifdef NOTUSED case htp_method_MKCOL: return "MKCOL"; break; @@ -362,9 +369,7 @@ evhtp_method2str(enum htp_method m) case htp_method_CONNECT: return "CONNECT"; break; - case htp_method_PATCH: - return "PATCH"; - break; +#endif /* NOTUSED */ default: return "UNKNOWN"; break; @@ -898,6 +903,7 @@ restconf_connection(int s, } h = (clicon_handle*)conn->htp->arg; while (readmore) { + clicon_debug(1, "%s readmore", __FUNCTION__); readmore = 0; /* Example: curl -Ssik -u wilma:bar -X GET https://localhost/restconf/data/example:x */ if (conn->ssl){ @@ -991,6 +997,7 @@ restconf_connection(int s, return retval; } +#if 0 /* debug */ /*! Debug print all loaded certs */ static int @@ -1017,6 +1024,7 @@ restconf_listcerts(SSL *ssl) } return 0; } +#endif/* debug */ /*! Check if a "cert" file exists * @@ -1237,9 +1245,10 @@ restconf_accept_client(int fd, clicon_debug(1, "%s peername:%s", __FUNCTION__, peername); } } - +#if 0 /* debug */ if (clicon_debug_get()) restconf_listcerts(ssl); +#endif } /* * Register callbacks for actual data socket diff --git a/codecov.yml b/codecov.yml index f7ba12da..7492cf38 100644 --- a/codecov.yml +++ b/codecov.yml @@ -20,5 +20,6 @@ comment: require_changes: no ignore: - - "util/" # ignore folders and all its contents + - "util/" + - "example/" diff --git a/test/cicd/coverage.sh b/test/cicd/coverage.sh index 7afe18ba..c8929d69 100755 --- a/test/cicd/coverage.sh +++ b/test/cicd/coverage.sh @@ -28,3 +28,5 @@ find . -name "*.gcda" | xargs sudo chmod 777 # The -f dont seem to work bash <(curl -s https://codecov.io/bash) -t ${TOKEN} +sleep 1 # ensure OK is last +echo OK diff --git a/test/lib.sh b/test/lib.sh index 201dc9ef..0ca88932 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -81,6 +81,9 @@ CONFNS='xmlns="http://clicon.org/config"' # Namespace: Clixon lib LIBNS='xmlns="http://clicon.org/lib"' +# Namespace: Clixon restconf +RESTCONFNS='xmlns="http://clicon.org/restconf"' + # Default netconf namespace statement, typically as placed on top-level example +cat < $cfg + + clixon-restconf:allow-auth-none + $cfg + /usr/local/share/clixon + $IETFRFC + $fyang + /usr/local/var/$APPNAME/$APPNAME.sock + $dir/restconf.pidfile + /usr/local/var/$APPNAME + $APPNAME + /usr/local/lib/$APPNAME/cli + /usr/local/lib/$APPNAME/clispec + $RESTCONFIG +nn +EOF + +cat < $fyang +module example{ + yang-version 1.1; + namespace "urn:example:clixon"; + prefix ex; + /* Generic config data */ + container table{ + list parameter{ + key name; + leaf name{ + type string; + } + leaf value{ + type string; + } + } + } +} +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 -f clixon_backend # to be sure + new "start backend -s init -f $cfg" + start_backend -s init -f $cfg +fi + +new "waiting" +wait_backend + +if [ $RC -ne 0 ]; then + new "kill old restconf daemon" + stop_restconf_pre + + new "start restconf daemon" + start_restconf -f $cfg + + new "waiting" + wait_restconf +fi + +new "Set backend debug using netconf" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO1]]>]]>" "^]]>]]>$" + +new "Set backend debug using restconf" +expectpart "$(curl $CURLOPTS -X POST -H 'Content-Type: application/yang-data+json' http://localhost/restconf/operations/clixon-lib:debug -d '{"clixon-lib:input":{"level":1}}')" 0 'HTTP/1.1 204 No Content' + +new "Set restconf debug using netconf" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO1]]>]]>" "^]]>]]>$" + +new "netconf commit" +expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" + +new "Set restconf debug using restconf" +expectpart "$(curl $CURLOPTS -X PUT -H 'Content-Type: application/yang-data+json' http://localhost/restconf/data/clixon-restconf:restconf/debug -d '{"clixon-restconf:debug":1}')" 0 "HTTP/1.1 204 No Content" + +new "Set cli debug using cli" +expectpart "$($clixon_cli -1 -f $cfg -l o debug cli 1)" 0 "^$" + +new "Set backend debug using cli" +expectpart "$($clixon_cli -1 -f $cfg -l o debug backend 1)" 0 "^$" + +new "Set restconf debug using cli" +expectpart "$($clixon_cli -1 -f $cfg -l o debug restconf 1)" 0 "^$" + +# Exercse debug code +new "get and put config using restconf" +expectpart "$(curl $CURLOPTS -H "Accept: application/yang-data+xml" -X GET $RCPROTO://localhost/restconf/data?content=config --next $CURLOPTS -H "Content-Type: application/yang-data+json" -X POST $RCPROTO://localhost/restconf/data -d '{"example:table":{"parameter":{"name":"local0","value":"foo"}}}')" 0 "HTTP/1.1 200 OK" '' 'HTTP/1.1 201 Created' + +if [ $RC -ne 0 ]; then + new "Kill restconf daemon" + stop_restconf +fi + +if [ $BE -ne 0 ]; then + 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 +fi + +# Set by restconf_config +unset RESTCONFIG + +rm -rf $dir + +new "endtest" +endtest diff --git a/test/test_yang_deviation.sh b/test/test_yang_deviation.sh new file mode 100755 index 00000000..4afa4ad0 --- /dev/null +++ b/test/test_yang_deviation.sh @@ -0,0 +1,120 @@ +#!/usr/bin/env bash +# Yang deviate tests +# See RFC 7950 5.6.3 and 7.20.3 +# Four examples: not supported, add, replace, delete + +# 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_yang.xml +fyangbase=$dir/example-base.yang +fyangdev=$dir/example-deviations.yang + +cat < $cfg + + $cfg + /usr/local/share/clixon + $dir + $IETFRFC + $dir + /usr/local/lib/$APPNAME/clispec + /usr/local/lib/$APPNAME/cli + $APPNAME + /usr/local/var/$APPNAME/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + /usr/local/var/$APPNAME + true + +EOF + +cat < $fyangbase +module example-base{ + yang-version 1.1; + prefix base; + namespace "urn:example:base"; + container system { + must "daytime or time"; + leaf daytime{ + type string; + } + list name-server { + key name; + leaf name { + type string; + } + } + list user { + key name; + leaf name { + type string; + } + leaf type { + type string; + } + } + } +} +EOF + +# Example from RFC 7950 Sec 7.20.3.3 +cat < $fyangdev +module $APPNAME{ + yang-version 1.1; + prefix md; + namespace "urn:example:deviations"; + + import example-base { + prefix base; + } + + deviation /base:system/base:daytime { + deviate not-supported; + } + deviation /base:system/base:user/base:type { + deviate add { + default "admin"; // new users are 'admin' by default + } + } + deviation /base:system { + deviate delete { + must "daytime or time"; + } + } +} +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 + new "start backend -s init -f $cfg" + start_backend -s init -f "$cfg" + + new "waiting" + wait_backend +fi + + +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" + +new "endtest" +endtest