Skip to content

Commit

Permalink
common UPDATE generate invalid xpath NC error
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed Nov 3, 2022
1 parent 95e3289 commit 5806717
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 7 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ endif()
set(NP2SRV_VERSION 2.1.41)

# libyang required version
set(LIBYANG_DEP_VERSION 2.0.263)
set(LIBYANG_DEP_SOVERSION 2.24.22)
set(LIBYANG_DEP_VERSION 2.0.267)
set(LIBYANG_DEP_SOVERSION 2.24.26)
set(LIBYANG_DEP_SOVERSION_MAJOR 2)

# libnetconf2 required version
Expand Down
5 changes: 2 additions & 3 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include "common.h"
#include "compat.h"
#include "err_netconf.h"
#include "log.h"
#include "netconf_monitoring.h"

Expand Down Expand Up @@ -1331,7 +1332,6 @@ int
op_filter_data_get(sr_session_ctx_t *session, uint32_t max_depth, sr_get_options_t get_opts,
const struct np2_filter *filter, sr_session_ctx_t *ev_sess, struct lyd_node **data)
{
const sr_error_info_t *err_info;
sr_data_t *sr_data;
uint32_t i;
int rc;
Expand All @@ -1342,8 +1342,7 @@ op_filter_data_get(sr_session_ctx_t *session, uint32_t max_depth, sr_get_options
rc = sr_get_data(session, filter->filters[i].str, max_depth, np2srv.sr_timeout, get_opts, &sr_data);
if (rc) {
ERR("Getting data \"%s\" from sysrepo failed (%s).", filter->filters[i].str, sr_strerror(rc));
sr_session_get_error(session, &err_info);
sr_session_set_error_message(ev_sess, err_info->err[0].message);
np_err_sr2nc_get(ev_sess, session);
return rc;
}

Expand Down
20 changes: 20 additions & 0 deletions src/err_netconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,23 @@ np_err_sr2nc_edit(sr_session_ctx_t *ev_sess, const sr_session_ctx_t *err_sess)
free(str);
free(str2);
}

void
np_err_sr2nc_get(sr_session_ctx_t *ev_sess, const sr_session_ctx_t *err_sess)
{
const sr_error_info_t *err_info;
const sr_error_info_err_t *err;

/* get the error */
sr_session_get_error((sr_session_ctx_t *)err_sess, &err_info);
assert(err_info);
err = &err_info->err[0];

if (strstr(err->message, " result is not a node set.")) {
/* invalid-value */
np_err_invalid_value(ev_sess, err->message, NULL);
} else {
/* other error */
sr_session_dup_error((sr_session_ctx_t *)err_sess, ev_sess);
}
}
2 changes: 2 additions & 0 deletions src/err_netconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ void np_err_ntf_sub_no_such_sub(sr_session_ctx_t *ev_sess, const char *message);

void np_err_sr2nc_edit(sr_session_ctx_t *ev_sess, const sr_session_ctx_t *err_sess);

void np_err_sr2nc_get(sr_session_ctx_t *ev_sess, const sr_session_ctx_t *err_sess);

#endif /* NP2SRV_ERR_NETCONF_H_ */
7 changes: 5 additions & 2 deletions tests/np_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@
assert_null(state->op); \
assert_string_equal(LYD_NAME(lyd_child(state->envp)), "rpc-error");

#define GET_CONFIG_DS_WD_FILTER(state, ds, wd, filter) \
#define SEND_GET_CONFIG_PARAM(state, ds, wd, filter) \
state->rpc = nc_rpc_getconfig(ds, filter, wd, NC_PARAMTYPE_CONST); \
state->msgtype = nc_send_rpc(state->nc_sess, state->rpc, 1000, &state->msgid); \
assert_int_equal(NC_MSG_RPC, state->msgtype); \
assert_int_equal(NC_MSG_RPC, state->msgtype);

#define GET_CONFIG_DS_WD_FILTER(state, ds, wd, filter) \
SEND_GET_CONFIG_PARAM(state, ds, wd, filter) \
state->msgtype = nc_recv_reply(state->nc_sess, state->rpc, state->msgid, 3000, &state->envp, &state->op); \
assert_int_equal(state->msgtype, NC_MSG_REPLY); \
assert_non_null(state->op); \
Expand Down
20 changes: 20 additions & 0 deletions tests/test_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,25 @@ test_none_missing(void **state)
FREE_TEST_VARS(st);
}

/* RFC 6241 sec.8.9.1. */
static void
test_invalid_xpath_filter(void **state)
{
struct np_test *st = *state;

/* use Xpath filter that does not evaluate to a node set */
SEND_GET_CONFIG_PARAM(st, NC_DATASTORE_RUNNING, NC_WD_ALL, "count(/errors:cont/l)");
ASSERT_ERROR_REPLY(st);
assert_string_equal(st->str,
"<rpc-error xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
" <error-type>application</error-type>\n"
" <error-tag>invalid-value</error-tag>\n"
" <error-severity>error</error-severity>\n"
" <error-message xml:lang=\"en\">XPath \"count(/errors:cont/l)\" result is not a node set.</error-message>\n"
"</rpc-error>\n");
FREE_TEST_VARS(st);
}

/* RFC 6241 Appendix A bad-element */
static void
test_bad_element(void **state)
Expand Down Expand Up @@ -465,6 +484,7 @@ main(int argc, char **argv)
cmocka_unit_test(test_create_exists),
cmocka_unit_test(test_delete_missing),
cmocka_unit_test(test_none_missing),
cmocka_unit_test(test_invalid_xpath_filter),
cmocka_unit_test(test_bad_element),
cmocka_unit_test(test_unknown_element),
cmocka_unit_test(test_unknown_namespace),
Expand Down

0 comments on commit 5806717

Please sign in to comment.