MXS-1999: Fix null relationship handling

The data of the relationship should be set to null to delete the
relationship. Conceptually it is different from setting it to an empty
relationship but in practice both lead to the same end result.

Updated tests to use correct relationships and added test cases for
detection of invalid relationships.
This commit is contained in:
Markus Mäkelä
2018-08-06 16:54:38 +03:00
parent 3754008e43
commit 4fd4d6bb01
4 changed files with 51 additions and 14 deletions

View File

@ -21,6 +21,7 @@
#include <set>
#include <iterator>
#include <algorithm>
#include <vector>
#include <maxscale/atomic.h>
#include <maxscale/hk_heartbeat.h>
@ -1132,6 +1133,28 @@ static bool is_valid_resource_body(json_t* json)
runtime_error("No '%s' field defined", MXS_JSON_PTR_DATA);
rval = false;
}
else
{
// Check that the relationship JSON is well-formed
const std::vector<const char*> relations =
{
MXS_JSON_PTR_RELATIONSHIPS "/servers",
MXS_JSON_PTR_RELATIONSHIPS "/services",
MXS_JSON_PTR_RELATIONSHIPS "/monitors",
MXS_JSON_PTR_RELATIONSHIPS "/filters",
};
for (auto it = relations.begin(); it != relations.end(); it++)
{
json_t* j = mxs_json_pointer(json, *it);
if (j && !json_is_object(j))
{
runtime_error("Relationship '%s' is not an object",*it);
rval = false;
}
}
}
return rval;
}
@ -1468,9 +1491,9 @@ static bool is_valid_relationship_body(json_t* json)
runtime_error("Field '%s' is not defined", MXS_JSON_PTR_DATA);
rval = false;
}
else if (!json_is_array(obj))
else if (!json_is_array(obj) && !json_is_null(obj))
{
runtime_error("Field '%s' is not an array", MXS_JSON_PTR_DATA);
runtime_error("Field '%s' is not an array or null", MXS_JSON_PTR_DATA);
rval = false;
}