Skip to content

Commit

Permalink
errors UPDATE out-of-bounds type value error
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed Dec 1, 2023
1 parent bedd408 commit 49a205d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/err_netconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ np_err_sr2nc_edit(sr_session_ctx_t *ev_sess, const sr_session_ctx_t *err_sess)
/* data-missing */
sr_session_set_netconf_error(ev_sess, "protocol", "data-missing", NULL, NULL, err->message, 0);
} else if (!strncmp(err->message, "Invalid type", 12) || !strncmp(err->message, "Unsatisfied range", 17) ||
!strncmp(err->message, "Unsatisfied pattern", 19)) {
!strncmp(err->message, "Unsatisfied pattern", 19) || strstr(err->message, "min/max bounds")) {
/* create error message */
str = strndup(err->message, (strchr(err->message, '.') + 1) - err->message);

Expand Down
2 changes: 1 addition & 1 deletion tests/modules/errors.yang
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module errors {
}

leaf num {
type uint32 {
type uint16 {
range "10..100";
}
}
Expand Down
18 changes: 17 additions & 1 deletion tests/test_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ test_bad_element(void **state)
" <error-type>application</error-type>\n"
" <error-tag>bad-element</error-tag>\n"
" <error-severity>error</error-severity>\n"
" <error-message xml:lang=\"en\">Invalid type uint32 value \"string\".</error-message>\n"
" <error-message xml:lang=\"en\">Invalid type uint16 value \"string\".</error-message>\n"
" <error-info>\n"
" <bad-element>/errors:num</bad-element>\n"
" </error-info>\n"
Expand All @@ -410,6 +410,22 @@ test_bad_element(void **state)
"</rpc-error>\n");
FREE_TEST_VARS(st);

/* out of type range */
data = "<num xmlns=\"urn:errors\">100000</num>";
SEND_EDIT_RPC(st, data);
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>bad-element</error-tag>\n"
" <error-severity>error</error-severity>\n"
" <error-message xml:lang=\"en\">Value \"100000\" is out of type uint16 min/max bounds.</error-message>\n"
" <error-info>\n"
" <bad-element>/errors:num</bad-element>\n"
" </error-info>\n"
"</rpc-error>\n");
FREE_TEST_VARS(st);

/* unsatisfied pattern */
data = "<str xmlns=\"urn:errors\">bb</str>";
SEND_EDIT_RPC(st, data);
Expand Down

0 comments on commit 49a205d

Please sign in to comment.