{
fr_assert(node->type == XLAT_FUNC);
- if (node->call.func->args && node->call.func->args->required &&
- (node->child->type == XLAT_LITERAL) && (talloc_array_length(node->child->fmt) == 1)) {
+ if (node->call.func->args && node->call.func->args->required && !node->child) {
fr_strerror_const("Missing required input");
return -1;
}
json_object *root;
} rlm_json_jpath_to_eval_t;
+static xlat_arg_parser_t const json_quote_xlat_arg = {
+ .concat = true, .type = FR_TYPE_STRING
+};
+
/** Ensure contents are quoted correctly for a JSON document
*
* @ingroup xlat_functions
fr_value_box_t *in_head = fr_dlist_head(in);
char *tmp;
- if (!in_head) return XLAT_ACTION_DONE;
-
- if (fr_value_box_list_concat(ctx, in_head, in, FR_TYPE_STRING, true) < 0) {
- RPEDEBUG("Failed concatenating input");
- return XLAT_ACTION_FAIL;
- }
+ if (!in_head) return XLAT_ACTION_DONE; /* Empty input is allowed */
MEM(vb = fr_value_box_alloc_null(ctx));
return ret;
}
+static xlat_arg_parser_t const json_encode_xlat_arg = {
+ .required = true, .concat = true, .type = FR_TYPE_STRING
+};
+
/** Convert given attributes to a JSON document
*
* Usage is `%{json_encode:attr tmpl list}`
fr_pair_list_init(&json_vps);
fr_pair_list_init(&vps);
- if (!in_head) {
- REDEBUG("Missing attribute(s)");
- return XLAT_ACTION_FAIL;
- }
-
- if (fr_value_box_list_concat(ctx, in_head, in, FR_TYPE_STRING, true) < 0) {
- RPEDEBUG("Failed concatenating input");
- return XLAT_ACTION_FAIL;
- }
sbuff = FR_SBUFF_IN(in_head->vb_strvalue, in_head->vb_length);
fr_sbuff_adv_past_whitespace(&sbuff, SIZE_MAX, NULL);
return XLAT_ACTION_DONE;
}
-
/** Pre-parse and validate literal jpath expressions for maps
*
* @param[in] cs #CONF_SECTION that defined the map instance.
static int mod_bootstrap(void *instance, CONF_SECTION *conf)
{
rlm_json_t *inst = talloc_get_type_abort(instance, rlm_json_t);
- xlat_t const *xlat;
+ xlat_t *xlat;
char *name;
fr_json_format_t *format = inst->format;
inst->name = cf_section_name2(conf);
if (!inst->name) inst->name = cf_section_name1(conf);
- xlat_register(instance, "jsonquote", json_quote_xlat, false);
+ xlat = xlat_register(instance, "jsonquote", json_quote_xlat, false);
+ xlat_func_mono(xlat, &json_quote_xlat_arg);
xlat_register_legacy(instance, "jpathvalidate", jpath_validate_xlat, NULL, NULL, 0, XLAT_DEFAULT_BUF_LEN);
name = talloc_asprintf(inst, "%s_encode", inst->name);
xlat = xlat_register(instance, name, json_encode_xlat, false);
+ xlat_func_mono(xlat, &json_encode_xlat_arg);
xlat_async_instantiate_set(xlat, json_xlat_instantiate,
rlm_json_t *, NULL, inst);
talloc_free(name);
echo "MODULE_TEST_DIR=$(dir $<) MODULE_TEST_UNLANG=$< $(TEST_BIN)/unit_test_module -D share/dictionary -d src/tests/modules/ -i \"$@.attrs\" -f \"$@.attrs\" -r \"$@\" -xx"; \
exit 1; \
fi; \
- FOUND=$$(grep ^$< $@.log | head -1 | sed 's/:.*//;s/.*\[//;s/\].*//'); \
+ FOUND=$$(grep -E 'Error : $<' $@.log | head -1 | sed 's/.*\[//;s/\].*//'); \
EXPECTED=$$(grep -n ERROR $< | sed 's/:.*//'); \
if [ "$$EXPECTED" != "$$FOUND" ]; then \
cat "$@.log"; \
}
-if (&Tmp-String-1 == '{"User-Name":{"type":"string","value":"john"},"Filter-Id":{"type":"string","value":["f1","f2"]},"NAS-Port":{"type":"uint32","value":999},"Service-Type":{"type":"uint32","value":"Login-User"}}') {
- test_pass
-} else {
+if (&Tmp-String-1 != '{"User-Name":{"type":"string","value":"john"},"Filter-Id":{"type":"string","value":["f1","f2"]},"NAS-Port":{"type":"uint32","value":999},"Service-Type":{"type":"uint32","value":"Login-User"}}') {
test_fail
}
test_fail
}
-if (&Tmp-String-5 == '{"User-Name":{"type":"string","value":"john"},"NAS-Port":{"type":"uint32","value":999},"Service-Type":{"type":"uint32","value":"Login-User"}}') {
- test_pass
-} else {
+if (&Tmp-String-5 != '{"User-Name":{"type":"string","value":"john"},"NAS-Port":{"type":"uint32","value":999},"Service-Type":{"type":"uint32","value":"Login-User"}}') {
test_fail
}
-if (&Tmp-String-6 == '') {
- test_pass
-} else {
+if (&Tmp-String-6 != '') {
test_fail
}
&Tmp-String-2 := "%{json_object_ex_encode:&request[*]}"
}
-if (&Tmp-String-1 == '{"User-Name":{"type":"string","value":"john"},"Filter-Id":{"type":"string","value":["f1","f2"]},"NAS-Port":{"type":"uint32","value":999},"Service-Type":{"type":"uint32","value":"Login-User"}}') {
- test_pass
-} else {
+if (&Tmp-String-1 != '{"User-Name":{"type":"string","value":"john"},"Filter-Id":{"type":"string","value":["f1","f2"]},"NAS-Port":{"type":"uint32","value":999},"Service-Type":{"type":"uint32","value":"Login-User"}}') {
test_fail
}
-if (&Tmp-String-2 == '{"pf:User-Name":{"type":"string","value":["john"]},"pf:Filter-Id":{"type":"string","value":["f1","f2"]},"pf:NAS-Port":{"type":"uint32","value":["999"]},"pf:Service-Type":{"type":"uint32","value":["1"]}}') {
- test_pass
-} else {
+if (&Tmp-String-2 != '{"pf:User-Name":{"type":"string","value":["john"]},"pf:Filter-Id":{"type":"string","value":["f1","f2"]},"pf:NAS-Port":{"type":"uint32","value":["999"]},"pf:Service-Type":{"type":"uint32","value":["1"]}}') {
test_fail
}
update request {
&Tmp-String-1 := "%{json_object_encode:!&request[*]}"
- &Tmp-String-2 := "%{json_object_ex_encode:}"
}
-if (&Module-Failure-Message == 'Missing attribute(s)') {
- test_pass
-} else {
- test_fail
-}
-
-if (&Tmp-String-1 == '{}') {
- test_pass
-} else {
- test_fail
-}
-
-if (&Tmp-String-2 == '') {
- test_pass
-} else {
+if (&Tmp-String-1 != '{}') {
test_fail
}
&Tmp-String-2 := "%{json_object_simple_ex_encode:&request[*]}"
}
-if (&Tmp-String-1 == '{"User-Name":"john","Filter-Id":["f1","f2"],"NAS-Port":999,"Service-Type":"Login-User"}') {
- test_pass
-} else {
+if (&Tmp-String-1 != '{"User-Name":"john","Filter-Id":["f1","f2"],"NAS-Port":999,"Service-Type":"Login-User"}') {
test_fail
}
-if (&Tmp-String-2 == '{"pf:User-Name":["john"],"pf:Filter-Id":["f1","f2"],"pf:NAS-Port":["999"],"pf:Service-Type":["1"]}') {
- test_pass
-} else {
+if (&Tmp-String-2 != '{"pf:User-Name":["john"],"pf:Filter-Id":["f1","f2"],"pf:NAS-Port":["999"],"pf:Service-Type":["1"]}') {
test_fail
}
update request {
&Tmp-String-1 := "%{json_object_simple_encode:!&request[*]}"
- &Tmp-String-2 := "%{json_object_simple_ex_encode:}"
-}
-
-if (&Module-Failure-Message == 'Missing attribute(s)') {
- test_pass
-} else {
- test_fail
-}
-
-if (&Tmp-String-1 == '{}') {
- test_pass
-} else {
- test_fail
}
-if (&Tmp-String-2 == '') {
- test_pass
-} else {
+if (&Tmp-String-1 != '{}') {
test_fail
}
&Tmp-String-2 := "%{json_array_ex_encode:&request[*]}"
}
-if (&Tmp-String-1 == '[{"name":"User-Name","type":"string","value":"john"},{"name":"Filter-Id","type":"string","value":"f1"},{"name":"Filter-Id","type":"string","value":"f2"},{"name":"NAS-Port","type":"uint32","value":999},{"name":"Service-Type","type":"uint32","value":"Login-User"}]') {
- test_pass
-} else {
+if (&Tmp-String-1 != '[{"name":"User-Name","type":"string","value":"john"},{"name":"Filter-Id","type":"string","value":"f1"},{"name":"Filter-Id","type":"string","value":"f2"},{"name":"NAS-Port","type":"uint32","value":999},{"name":"Service-Type","type":"uint32","value":"Login-User"}]') {
test_fail
}
-if (&Tmp-String-2 == '[{"name":"pf:User-Name","type":"string","value":["john"]},{"name":"pf:Filter-Id","type":"string","value":["f1","f2"]},{"name":"pf:NAS-Port","type":"uint32","value":["999"]},{"name":"pf:Service-Type","type":"uint32","value":["1"]}]') {
- test_pass
-} else {
+if (&Tmp-String-2 != '[{"name":"pf:User-Name","type":"string","value":["john"]},{"name":"pf:Filter-Id","type":"string","value":["f1","f2"]},{"name":"pf:NAS-Port","type":"uint32","value":["999"]},{"name":"pf:Service-Type","type":"uint32","value":["1"]}]') {
test_fail
}
update request {
&Tmp-String-1 := "%{json_array_encode:!&request[*]}"
- &Tmp-String-2 := "%{json_array_ex_encode:}"
}
-if (&Module-Failure-Message == 'Missing attribute(s)') {
- test_pass
-} else {
- test_fail
-}
-
-if (&Tmp-String-1 == '[]') {
- test_pass
-} else {
- test_fail
-}
-
-if (&Tmp-String-2 == '') {
- test_pass
-} else {
+if (&Tmp-String-1 != '[]') {
test_fail
}
&Tmp-String-2 := "%{json_array_names_ex_encode:&request[*]}"
}
-if (&Tmp-String-1 == '["User-Name","Filter-Id","Filter-Id","NAS-Port","Service-Type"]') {
- test_pass
-} else {
+if (&Tmp-String-1 != '["User-Name","Filter-Id","Filter-Id","NAS-Port","Service-Type"]') {
test_fail
}
-if (&Tmp-String-2 == '["pf:User-Name","pf:Filter-Id","pf:Filter-Id","pf:NAS-Port","pf:Service-Type"]') {
- test_pass
-} else {
+if (&Tmp-String-2 != '["pf:User-Name","pf:Filter-Id","pf:Filter-Id","pf:NAS-Port","pf:Service-Type"]') {
test_fail
}
update request {
&Tmp-String-1 := "%{json_array_names_encode:!&request[*]}"
- &Tmp-String-2 := "%{json_array_names_ex_encode:}"
-}
-
-if (&Module-Failure-Message == 'Missing attribute(s)') {
- test_pass
-} else {
- test_fail
-}
-
-if (&Tmp-String-1 == '[]') {
- test_pass
-} else {
- test_fail
}
-if (&Tmp-String-2 == '') {
- test_pass
-} else {
+if (&Tmp-String-1 != '[]') {
test_fail
}
&Tmp-String-2 := "%{json_array_values_ex_encode:&request[*]}"
}
-if (&Tmp-String-1 == '["john","f1","f2",999,"Login-User"]') {
- test_pass
-} else {
+if (&Tmp-String-1 != '["john","f1","f2",999,"Login-User"]') {
test_fail
}
-if (&Tmp-String-2 == '["john","f1","f2","999","1"]') {
- test_pass
-} else {
+if (&Tmp-String-2 != '["john","f1","f2","999","1"]') {
test_fail
}
update request {
&Tmp-String-1 := "%{json_array_values_encode:!&request[*]}"
- &Tmp-String-2 := "%{json_array_values_ex_encode:}"
}
-if (&Module-Failure-Message == 'Missing attribute(s)') {
- test_pass
-} else {
- test_fail
-}
-
-if (&Tmp-String-1 == '[]') {
- test_pass
-} else {
- test_fail
-}
-
-if (&Tmp-String-2 == '') {
- test_pass
-} else {
+if (&Tmp-String-1 != '[]') {
test_fail
}
# -e 's/^/if (/' \
# -e "s/\"$/') {/" \
# -e "s/$/\n test_pass\n} else {\n test_fail\n}\n/"
+
+test_pass
--- /dev/null
+#
+# Input packet
+#
+Packet-Type = Access-Request
+User-Name = 'john'
+
+#
+# Expected answer
+#
+Packet-Type == Access-Accept
--- /dev/null
+#
+# json xlat input parsing test - error with no input
+#
+
+update request {
+ &Tmp-String-1 := "%{json_object_ex_encode:}" # ERROR
+}
&Tmp-String-1 := '$.foo'
}
-if (&Tmp-String-1 == 'bar') {
- test_pass
-} else {
+if (&Tmp-String-1 != 'bar') {
test_fail
}
}
# 1. Array type
-if (&Tmp-String-1[0] == '[ 0, 1, 2, 3, 4, 5 ]') {
- test_pass
-} else {
+if (&Tmp-String-1[0] != '[ 0, 1, 2, 3, 4, 5 ]') {
test_fail
}
# 2. Object type
-if (&Tmp-String-1[1] == '{ "foo": "bar", "num": 42 }') {
- test_pass
-} else {
+if (&Tmp-String-1[1] != '{ "foo": "bar", "num": 42 }') {
test_fail
}
# 3. Integer type
-if (&Tmp-String-1[2] == '99') {
- test_pass
-} else {
+if (&Tmp-String-1[2] != '99') {
test_fail
}
# 4. Double type
-if (&Tmp-String-1[3] == '5.9') {
- test_pass
-} else {
+if (&Tmp-String-1[3] != '5.9') {
test_fail
}
# 5. null type
-if (&Tmp-String-1[4] == 'null') {
- test_pass
-} else {
+if (&Tmp-String-1[4] != 'null') {
test_fail
}
# 6. Boolean true
-if (&Tmp-String-1[5] == 'yes') {
- test_pass
-} else {
+if (&Tmp-String-1[5] != 'yes') {
test_fail
}
# 7. Boolean false
-if (&Tmp-String-1[6] == 'no') {
- test_pass
-} else {
+if (&Tmp-String-1[6] != 'no') {
test_fail
}
map json &Tmp-String-0 {
&Tmp-String-1 := '$.my_array'
}
-if (&Tmp-String-1 == '[ 0, 1, 2, 3, 4, 5 ]') {
- test_pass
-} else {
+if (&Tmp-String-1 != '[ 0, 1, 2, 3, 4, 5 ]') {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 := '$.my_array[0]'
}
-if (&Tmp-Integer-0 == 0) {
- test_pass
-} else {
+if (&Tmp-Integer-0 != 0) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 := '$.my_array[5]' # Past the end of the array (should be skipped)
}
-if (&Tmp-Integer-0 == 5) {
- test_pass
-} else {
+if (&Tmp-Integer-0 != 5) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 := '$.my_array[6]' # Past the end of the array (should be skipped)
}
-if (!&Tmp-Integer-0) {
- test_pass
-} else {
+if (&Tmp-Integer-0) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 += '$.my_array[0:2]' # A single value
}
-if ((&Tmp-Integer-0[0] == 0) && (&Tmp-Integer-0[1] == 1)) {
- test_pass
-} else {
+if ((&Tmp-Integer-0[0] != 0) || (&Tmp-Integer-0[1] != 1)) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 += '$.my_array[-1:6]' # A single value (last eelement of the array)
}
-if (&Tmp-Integer-0 == 5) {
- test_pass
-} else {
+if (&Tmp-Integer-0 != 5) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 += '$.my_array[-1:-3]' # Start after end (should be skipped)
}
-if (!&Tmp-Integer-0) {
- test_pass
-} else {
+if (&Tmp-Integer-0) {
test_fail
}
map json &Tmp-String-0 {
&Tmp-Integer-0 += '$.my_array[1:-3]'
}
-if ((&Tmp-Integer-0[0] == 1) && (&Tmp-Integer-0[1] == 2)) {
- test_pass
-} else {
+if ((&Tmp-Integer-0[0] != 1) && (&Tmp-Integer-0[1] != 2)) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 += '$.my_array[4:2:-1]'
}
-if ((&Tmp-Integer-0[0] == 4) && (&Tmp-Integer-0[1] == 3)) {
- test_pass
-} else {
+if ((&Tmp-Integer-0[0] != 4) || (&Tmp-Integer-0[1] != 3)) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 += '$.my_array[2:4:-1]'
}
-if (!&Tmp-Integer-0) {
- test_pass
-} else {
+if (&Tmp-Integer-0) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 += '$.my_array[2:4:1]'
}
-if ((&Tmp-Integer-0[0] == 2) && (&Tmp-Integer-0[1] == 3)) {
- test_pass
-} else {
+if ((&Tmp-Integer-0[0] != 2) || (&Tmp-Integer-0[1] != 3)) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 += '$.my_array[1:5:2]'
}
-if ((&Tmp-Integer-0[0] == 1) && (&Tmp-Integer-0[1] == 3)) {
- test_pass
-} else {
+if ((&Tmp-Integer-0[0] != 1) && (&Tmp-Integer-0[1] != 3)) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 += '$.my_array[1:5:4]'
}
-if ((&Tmp-Integer-0[0] == 1) && !&Tmp-Integer-0[1]) {
- test_pass
-} else {
+if ((&Tmp-Integer-0[0] != 1) || &Tmp-Integer-0[1]) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 += '$.my_array[5:1:-4]'
}
-if ((&Tmp-Integer-0[0] == 5) && !&Tmp-Integer-0[1]) {
- test_pass
-} else {
+if ((&Tmp-Integer-0[0] != 5) || &Tmp-Integer-0[1]) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 += '$.my_array[::3]'
}
-if ((&Tmp-Integer-0[0] == 0) && (&Tmp-Integer-0[1] == 3) && !&Tmp-Integer-0[2]) {
- test_pass
-} else {
+if ((&Tmp-Integer-0[0] != 0) || (&Tmp-Integer-0[1] != 3) || &Tmp-Integer-0[2]) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 += '$.my_array[::-3]'
}
-if ((&Tmp-Integer-0[0] == 5) && (&Tmp-Integer-0[1] == 2) && !&Tmp-Integer-0[2]) {
- test_pass
-} else {
+if ((&Tmp-Integer-0[0] != 5) || (&Tmp-Integer-0[1] != 2) || &Tmp-Integer-0[2]) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 += '$.my_array[3:0:-3]'
}
-if ((&Tmp-Integer-0[0] == 3) && !&Tmp-Integer-0[1]) {
- test_pass
-} else {
+if ((&Tmp-Integer-0[0] != 3) || &Tmp-Integer-0[1]) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 += '$.my_array[0::-3]'
}
-if ((&Tmp-Integer-0[0] == 0) && !&Tmp-Integer-0[1]) {
- test_pass
-} else {
+if ((&Tmp-Integer-0[0] != 0) || &Tmp-Integer-0[1]) {
test_fail
}
update request {
&Tmp-String-1 += '$.*.*'
}
-if ((&Tmp-String-1[0] == '0') && \
- (&Tmp-String-1[1] == '1') && \
- (&Tmp-String-1[2] == '2') && \
- (&Tmp-String-1[3] == '3') && \
- (&Tmp-String-1[4] == '4') && \
- (&Tmp-String-1[5] == '5') && \
- (&Tmp-String-1[6] == 'bar') && \
- (&Tmp-String-1[7] == '42')) {
- test_pass
-} else {
+if ((&Tmp-String-1[0] != '0') || \
+ (&Tmp-String-1[1] != '1') || \
+ (&Tmp-String-1[2] != '2') || \
+ (&Tmp-String-1[3] != '3') || \
+ (&Tmp-String-1[4] != '4') || \
+ (&Tmp-String-1[5] != '5') || \
+ (&Tmp-String-1[6] != 'bar') || \
+ (&Tmp-String-1[7] != '42')) {
test_fail
}
&Tmp-String-1 += '$.*.*.*'
}
-if (!&Tmp-String-1) {
- test_pass
-} else {
+if (&Tmp-String-1) {
test_fail
}
&Tmp-String-1 += '$.my_object[0]'
}
-if (!&Tmp-String-1) {
- test_pass
-} else {
+if (&Tmp-String-1) {
test_fail
}
&Tmp-String-1 += '$.my_object.my_other_object'
}
-if (!&Tmp-String-1) {
- test_pass
-} else {
+if (&Tmp-String-1) {
test_fail
}
map json &Tmp-String-0 {
&Tmp-Integer-0 := '$[3][0]'
}
-if (&Tmp-Integer-0 == 2147483647) {
- test_pass
-} else {
+if (&Tmp-Integer-0 != 2147483647) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Signed-0 += '$[3][0,1]'
}
-if ((&Tmp-Signed-0[0] == 2147483647) && (&Tmp-signed-0[1] == -2147483647)) {
- test_pass
-} else {
+if ((&Tmp-Signed-0[0] != 2147483647) || (&Tmp-signed-0[1] != -2147483647)) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-Integer-0 += "$[3][%{Tmp-Integer-2}]"
}
-if (&Tmp-Integer-0 == 2147483647) {
- test_pass
-} else {
+if (&Tmp-Integer-0 != 2147483647) {
test_fail
}
update request {
&Tmp-String-1 := "$.%{Tmp-String-2}"
}
-if (&Tmp-String-1 == 'baz') {
- test_pass
-} else {
+if (&Tmp-String-1 != 'baz') {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-String-1 += '$..bool'
}
-if (("%{Tmp-String-1[#]}" == 1) && (&Tmp-String-1 == 'yes')) {
- test_pass
-} else {
+if (("%{Tmp-String-1[#]}" != 1) || (&Tmp-String-1 != 'yes')) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-String-1 += '$..[1]'
}
-if (("%{Tmp-String-1[#]}" == 3) && (&Tmp-String-1[0] == '1') && (&Tmp-String-1[1] == 'scratchy') && (&Tmp-String-1[2] == 'clawy')) {
- test_pass
-} else {
+if (("%{Tmp-String-1[#]}" != 3) || (&Tmp-String-1[0] != '1') || (&Tmp-String-1[1] != 'scratchy') || (&Tmp-String-1[2] != 'clawy')) {
test_fail
}
update request {
map json &Tmp-String-0 {
&Tmp-String-1 += '$..my_cats[2]'
}
-if (("%{Tmp-String-1[#]}" == 2) && (&Tmp-String-1[0] == 'flat') && (&Tmp-String-1[1] == 'woofy')) {
- test_pass
-} else {
+if (("%{Tmp-String-1[#]}" != 2) || (&Tmp-String-1[0] != 'flat') || (&Tmp-String-1[1] != 'woofy')) {
test_fail
}
update request {
&Tmp-String-1 !* ANY
}
-# Disabled until a json-c >= 0.10 is available in travis
-## xx. Unsigned 64bit integers
-#map json &Tmp-String-0 {
-# &Tmp-Integer64-0 := '$[0]'
-#}
-#if (&Tmp-Integer64-0 == 9223372036854775807) {
-# test_pass
-#} else {
-# test_fail
-#}
-#update request {
-# &Tmp-Integer64-0 !* ANY
-#}
-#
-## xx. Signed 64bit integers (not supported)
-#redundant {
-# group {
-# map json &Tmp-String-0 {
-# &Tmp-Integer64-0 := '$[1]'
-# }
-# }
-# ok
-#}
-#if (!fail && !&Tmp-Integer64-0) {
-# test_pass
-#} else {
-# test_fail
-#}
-#update request {
-# &Tmp-Integer64-0 !* ANY
-#}
-#
-## xx. Signed 64bit integers (not supported)
-#redundant {
-# group {
-# map json &Tmp-String-0 {
-# &Tmp-Integer64-0 := '$[1]'
-# }
-# }
-# ok
-#}
-#if (!fail && !&Tmp-Integer64-0) {
-# test_pass
-#} else {
-# test_fail
-#}
-#update request {
-# &Tmp-Integer64-0 !* ANY
-#}
+# 39. Unsigned 64bit integers
+map json &Tmp-String-0 {
+ &Tmp-Integer64-0 := '$[0]'
+}
+if (&Tmp-Integer64-0 != 9223372036854775807) {
+ test_fail
+}
+update request {
+ &Tmp-Integer64-0 !* ANY
+}
+
+# 40. Signed 64bit integers (not supported)
+redundant {
+ group {
+ map json &Tmp-String-0 {
+ &Tmp-Integer64-0 := '$[1]'
+ }
+ }
+ ok
+}
+if (fail || &Tmp-Integer64-0) {
+ test_fail
+}
+update request {
+ &Tmp-Integer64-0 !* ANY
+}
+
+# 41. Signed 64bit integers (not supported)
+redundant {
+ group {
+ map json &Tmp-String-0 {
+ &Tmp-Integer64-0 := '$[1]'
+ }
+ }
+ ok
+}
+if (fail || &Tmp-Integer64-0) {
+ test_fail
+}
+update request {
+ &Tmp-Integer64-0 !* ANY
+}
+
+test_pass
#
# 0. Expect success - Field selectors
-if ("%{jpathvalidate:$.foo.bar}" == '9:$.foo.bar') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo.bar}" != '9:$.foo.bar') {
test_fail
}
# 1. Expect success - Field selectors
-if ("%{jpathvalidate:@.foo.bar}" == '9:@.foo.bar') {
- test_pass
-} else {
+if ("%{jpathvalidate:@.foo.bar}" != '9:@.foo.bar') {
test_fail
}
# 2. Expect success - Array selector
-if ("%{jpathvalidate:$.foo[1]}" == '8:$.foo[1]') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[1]}" != '8:$.foo[1]') {
test_fail
}
# 3. Expect success - Array selector
-if ("%{jpathvalidate:$.foo[1:2]}" == '10:$.foo[1:2]') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[1:2]}" != '10:$.foo[1:2]') {
test_fail
}
# 4. Expect success - Array slice selector
-if ("%{jpathvalidate:$.foo[:1]}" == '9:$.foo[:1]') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[:1]}" != '9:$.foo[:1]') {
test_fail
}
# 5. Expect success - Array slice selector
-if ("%{jpathvalidate:$.foo[1::1]}" == '11:$.foo[1::1]') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[1::1]}" != '11:$.foo[1::1]') {
test_fail
}
# 6. Expect success - Array step selector
-if ("%{jpathvalidate:$.foo[::2]}" == '10:$.foo[::2]') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[::2]}" != '10:$.foo[::2]') {
test_fail
}
# 7. Expect success - Array step selector
-if ("%{jpathvalidate:$.foo[1:1:2]}" == '12:$.foo[1:1:2]') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[1:1:2]}" != '12:$.foo[1:1:2]') {
test_fail
}
# 8. Expect success - Array multiple selectors
-if ("%{jpathvalidate:$.foo[1,1:1:2]}" == '14:$.foo[1,1:1:2]') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[1,1:1:2]}" != '14:$.foo[1,1:1:2]') {
test_fail
}
# 9. Expect success - Wildcard selector 1
-if ("%{jpathvalidate:$.*}" == '3:$.*') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.*}" != '3:$.*') {
test_fail
}
# 10. Expect success - Wildcard selector 2
-if ("%{jpathvalidate:$.*.foo}" == '7:$.*.foo') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.*.foo}" != '7:$.*.foo') {
test_fail
}
# 11. Expect success - Mixture of selectors
-if ("%{jpathvalidate:$.foo[::2].*.bar[::1]}" == '21:$.foo[::2].*.bar[::1]') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[::2].*.bar[::1]}" != '21:$.foo[::2].*.bar[::1]') {
test_fail
}
# 12. Expect success - Escape sequence
-if ("%{jpathvalidate:$.foo.bar\[\]}" == '13:$.foo.bar\[\]') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo.bar\[\]}" != '13:$.foo.bar\[\]') {
test_fail
}
# 13. Expect success - Non escape sequence
-if ("%{jpathvalidate:$.foo.bar\@}" == '11:$.foo.bar\@') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo.bar\@}" != '11:$.foo.bar\@') {
test_fail
}
# 14. Expect failure - Invalid starting char
-if ("%{jpathvalidate:[.foo}" == '0:Expected root specifier \'$\', or current node specifier \'@\'') {
- test_pass
-} else {
+if ("%{jpathvalidate:[.foo}" != '0:Expected root specifier \'$\', or current node specifier \'@\'') {
test_fail
}
# 15. Expect failure - Invalid char following root specifier
-if ("%{jpathvalidate:$[]}" == '2:Empty selector') {
- test_pass
-} else {
+if ("%{jpathvalidate:$[]}" != '2:Empty selector') {
test_fail
}
# 16. Expect failure - Invalid char following root specifier
-if ("%{jpathvalidate:$.}" == '2:Expected recursive descent \'..\' wildcard \'*\' or field specifier') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.}" != '2:Expected recursive descent \'..\' wildcard \'*\' or field specifier') {
test_fail
}
# 17. Expect failure - Recursive descent after child delimiter
-if ("%{jpathvalidate:$...}" == '3:Recursive descent must not be followed by child delimiter \'.\'') {
- test_pass
-} else {
+if ("%{jpathvalidate:$...}" != '3:Recursive descent must not be followed by child delimiter \'.\'') {
test_fail
}
# 18. Expect failure - Missing selector terminator
-if ("%{jpathvalidate:$.foo[}" == '6:Missing selector terminator \']\'') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[}" != '6:Missing selector terminator \']\'') {
test_fail
}
# 19. Expect failure - Missing selector terminator
-if ("%{jpathvalidate:$.foo[0}" == '7:Missing selector delimiter \',\' or terminator \']\'') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[0}" != '7:Missing selector delimiter \',\' or terminator \']\'') {
test_fail
}
# 20. Expect failure - Unexpected selector terminator
-if ("%{jpathvalidate:$.foo]}" == '5:Expected field specifier \'.\' or selector \'[\'') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo]}" != '5:Expected field specifier \'.\' or selector \'[\'') {
test_fail
}
# 21. Expect failure - Empty selector
-if ("%{jpathvalidate:$.foo[,}" == '6:Empty selector') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[,}" != '6:Empty selector') {
test_fail
}
# 22. Expect failure - Empty selector
-if ("%{jpathvalidate:$.foo[,]}" == '6:Empty selector') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[,]}" != '6:Empty selector') {
test_fail
}
# 23. Expect failure - Empty selector
-if ("%{jpathvalidate:$.foo[]}" == '6:Empty selector') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[]}" != '6:Empty selector') {
test_fail
}
# 24. Expect failure - Empty selector
-if ("%{jpathvalidate:$.foo[1,1:1:2,]}" == '14:Empty selector') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[1,1:1:2,]}" != '14:Empty selector') {
test_fail
}
# 25. Expect failure - Bad array index
-if ("%{jpathvalidate:$.foo[a]}" == '6:Expected num, \':\' or \']\'') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[a]}" != '6:Expected num, \':\' or \']\'') {
test_fail
}
# 26. Expect failure - Bad array end
-if ("%{jpathvalidate:$.foo[0:a]}" == '8:Expected num, \':\' or \']\'') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[0:a]}" != '8:Expected num, \':\' or \']\'') {
test_fail
}
# 27. Expect failure - Bad array slice
-if ("%{jpathvalidate:$.foo[0:0:a]}" == '10:Expected num or \']\'') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[0:0:a]}" != '10:Expected num or \']\'') {
test_fail
}
# 28. Expect failure - Bad array slice value
-if ("%{jpathvalidate:$.foo[0:0:0]}" == '10:Step cannot be 0') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[0:0:0]}" != '10:Step cannot be 0') {
test_fail
}
# 29. Expect failure - Field too long
-if ("%{jpathvalidate:$.foo.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}" == '134:Exceeded maximum field name length') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}" != '134:Exceeded maximum field name length') {
test_fail
}
# 30. Expect success - Field ok
-if ("%{jpathvalidate:$.foo.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}" == '134:$.foo.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}" != '134:$.foo.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') {
test_fail
}
# 31. Expect failure - Empty field
-if ("%{jpathvalidate:$.foo.[]}" == '6:Empty field specifier') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo.[]}" != '6:Empty field specifier') {
test_fail
}
# 32. Expect success - Nested array
-if ("%{jpathvalidate:$[0][1]}" == '7:$[0][1]') {
- test_pass
-} else {
+if ("%{jpathvalidate:$[0][1]}" != '7:$[0][1]') {
test_fail
}
# 33. Expect success - Nested array with multiple indicies
-if ("%{jpathvalidate:$[0][1,2]}" == '9:$[0][1,2]') {
- test_pass
-} else {
+if ("%{jpathvalidate:$[0][1,2]}" != '9:$[0][1,2]') {
test_fail
}
# 34. Expect failure - Recursive descent followed by nothing
-if ("%{jpathvalidate:$..}" == '2:Path may not end in recursive descent') {
- test_pass
-} else {
+if ("%{jpathvalidate:$..}" != '2:Path may not end in recursive descent') {
test_fail
}
# 35. Expect success - Recursive descent followed by field
-if ("%{jpathvalidate:$..foo}" == '6:$..foo') {
- test_pass
-} else {
+if ("%{jpathvalidate:$..foo}" != '6:$..foo') {
test_fail
}
# 36. Expect success - Recursive descent followed by selector
-if ("%{jpathvalidate:$..[0]}" == '6:$..[0]') {
- test_pass
-} else {
+if ("%{jpathvalidate:$..[0]}" != '6:$..[0]') {
test_fail
}
# 37. Expect success - Recursive descent followed by two selectors
-if ("%{jpathvalidate:$..foo[0]}" == '9:$..foo[0]') {
- test_pass
-} else {
+if ("%{jpathvalidate:$..foo[0]}" != '9:$..foo[0]') {
test_fail
}
# 38. Expect success - Recursive descent followed by wildcard
-if ("%{jpathvalidate:$..*}" == '4:$..*') {
- test_pass
-} else {
+if ("%{jpathvalidate:$..*}" != '4:$..*') {
test_fail
}
# 39. Expect failure - Filter expressions NYI
-if ("%{jpathvalidate:$.foo[?@.bar = baz]}" == '6:Filter expressions not yet implemented') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[?@.bar = baz]}" != '6:Filter expressions not yet implemented') {
test_fail
}
# 40. Expect failure - Expressions NYI
-if ("%{jpathvalidate:$.foo[(@.bar = baz)]}" == '6:Expressions not yet implemented') {
- test_pass
-} else {
+if ("%{jpathvalidate:$.foo[(@.bar = baz)]}" != '6:Expressions not yet implemented') {
test_fail
}
+test_pass
}
# Check for correct escapes
-if (&Tmp-String-2 == 'foo\/bar') {
- test_pass
-} else {
+if (&Tmp-String-2 != 'foo\/bar') {
test_fail
}
-if (&Tmp-String-3 == 'foo\"bar') {
- test_pass
-} else {
+if (&Tmp-String-3 != 'foo\"bar') {
test_fail
}
&Tmp-String-4 := "%{jsonquote:}"
}
-if (&Tmp-String-4 == '') {
- test_pass
-} else {
+if (&Tmp-String-4 != '') {
test_fail
}
#
# Quoting nothing is not an error
#
-if (!&Module-Failure-Message) {
- test_pass
-} else {
+if (&Module-Failure-Message) {
test_fail
}
+
+test_pass
\ No newline at end of file