-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrestconf-defaults.cpp
102 lines (88 loc) · 3.67 KB
/
restconf-defaults.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright (C) 2023 CESNET, https://photonics.cesnet.cz/
*
* Written by Tomáš Pecka <[email protected]>
* Written by Jan Kundrát <[email protected]>
*
*/
static const auto SERVER_PORT = "10087";
#include <nghttp2/asio_http2.h>
#include <spdlog/spdlog.h>
#include "restconf/Server.h"
#include "tests/aux-utils.h"
#include "tests/event_watchers.h"
TEST_CASE("default handling")
{
trompeloeil::sequence seq1;
spdlog::set_level(spdlog::level::trace);
auto srConn = sysrepo::Connection{};
auto srSess = srConn.sessionStart(sysrepo::Datastore::Running);
auto nacmGuard = manageNacm(srSess);
srSess.sendRPC(srSess.getContext().newPath("/ietf-factory-default:factory-reset"));
setupRealNacm(srSess);
DatastoreChangesMock dsChangesMock;
auto changesExampleRunning = datastoreChangesSubscription(srSess, dsChangesMock, "example");
auto server = rousette::restconf::Server{srConn, SERVER_ADDRESS, SERVER_PORT};
// default value of /example:a/b/c/enabled is implicitly set so it should not be printed
REQUIRE(get(RESTCONF_DATA_ROOT "/example:a/b/c", {}) == Response{200, jsonHeaders, R"({
"example:a": {
"b": {
"c": {}
}
}
}
)"});
// RFC 6243, sec. 2.3.3: A valid 'delete' operation attribute for a data node that has been set by the server to its schema default value MUST fail with a 'data-missing' error-tag.
REQUIRE(httpDelete(RESTCONF_DATA_ROOT "/example:a/b/c/enabled", {AUTH_ROOT}) == Response{404, jsonHeaders, R"({
"ietf-restconf:errors": {
"error": [
{
"error-type": "application",
"error-tag": "data-missing",
"error-path": "/example:a/b/c/enabled",
"error-message": "Data is missing."
}
]
}
}
)"});
// RFC 6243, sec. 2.3.3: A valid 'create' operation attribute for a data node that has been set by the server to its schema default value MUST succeed.
REQUIRE(post(RESTCONF_DATA_ROOT "/example:a/b/c", {AUTH_ROOT, CONTENT_TYPE_JSON}, R"({"example:enabled":true}")") == Response{201, jsonHeaders, ""});
// RFC 6243, sec. 2.3.3: A valid 'create' operation attribute for a data node that has been set by a client to its schema default value MUST fail with a 'data-exists' error-tag.
// RFC 8040, sec. 4.4.1: If the data resource already exists, then the POST request MUST fail and a "409 Conflict" status-line MUST be returned. The error-tag value "resource-denied" is used in this case.
// This conflict of RFCs seems to be reported in errata https://www.rfc-editor.org/errata/eid5761 but no action was taken. Let's test according to implementation in RFC 8040
REQUIRE(post(RESTCONF_DATA_ROOT "/example:a/b/c", {AUTH_ROOT, CONTENT_TYPE_JSON}, R"({"example:enabled":true}")") == Response{409, jsonHeaders, R"({
"ietf-restconf:errors": {
"error": [
{
"error-type": "application",
"error-tag": "resource-denied",
"error-message": "Resource already exists."
}
]
}
}
)"});
// default value is explicitly set so it should be printed
REQUIRE(get(RESTCONF_DATA_ROOT "/example:a/b/c", {}) == Response{200, jsonHeaders, R"({
"example:a": {
"b": {
"c": {
"enabled": true
}
}
}
}
)"});
// RFC 6243, sec. 2.3.3: A valid 'delete' operation attribute for a data node that has been set by a client to its schema default value MUST succeed.
REQUIRE(httpDelete(RESTCONF_DATA_ROOT "/example:a/b/c/enabled", {AUTH_ROOT}) == Response{204, noContentTypeHeaders, ""});
// default value is only there implicitly, so it should *not* be printed
REQUIRE(get(RESTCONF_DATA_ROOT "/example:a/b/c", {}) == Response{200, jsonHeaders, R"({
"example:a": {
"b": {
"c": {}
}
}
}
)"});
}