Browse Source

common/test/run-json: test JSON escaping.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
112ae0d0f5
  1. 45
      common/test/run-json.c
  2. 2
      lightningd/test/run-cryptomsg.c
  3. 2
      lightningd/test/run-find_my_path.c

45
common/test/run-json.c

@ -0,0 +1,45 @@
#include "../json.c"
#include <stdio.h>
/* AUTOGENERATED MOCKS START */
/* AUTOGENERATED MOCKS END */
int main(void)
{
struct json_result *result = new_json_result(NULL);
jsmntok_t *toks;
const jsmntok_t *x;
bool valid;
int i;
char *badstr = tal_arr(result, char, 256);
const char *str;
/* Fill with junk, and nul-terminate (256 -> 0) */
for (i = 1; i < 257; i++)
badstr[i-1] = i;
json_object_start(result, NULL);
json_add_string(result, "x", badstr);
json_object_end(result);
/* Parse back in, make sure nothing crazy. */
str = json_result_string(result);
toks = json_parse_input(str, strlen(str), &valid);
assert(valid);
assert(toks);
assert(toks[0].type == JSMN_OBJECT);
x = json_get_member(str, toks, "x");
assert(x);
assert(x->type == JSMN_STRING);
assert((x->end - x->start) == 255);
for (i = x->start; i < x->end; i++) {
assert(cisprint(str[i]));
assert(str[i] != '\\');
assert(str[i] != '"');
assert(str[i] == '?' || str[i] == badstr[i - x->start]);
}
tal_free(result);
return 0;
}

2
lightningd/test/run-cryptomsg.c

@ -47,6 +47,8 @@ void dev_blackhole_fd(int fd UNNEEDED)
/* Generated stub for dev_sabotage_fd */
void dev_sabotage_fd(int fd UNNEEDED)
{ fprintf(stderr, "dev_sabotage_fd called!\n"); abort(); }
/* Could not find declaration for secp256k1_ecdsa_recoverable_signature_parse_compact */
/* Could not find declaration for secp256k1_ecdsa_recoverable_signature_serialize_compact */
/* AUTOGENERATED MOCKS END */
enum dev_disconnect dev_disconnect(int pkt_type)

2
lightningd/test/run-find_my_path.c

@ -46,6 +46,8 @@ void populate_peer(struct lightningd *ld UNNEEDED, struct peer *peer UNNEEDED)
/* Generated stub for register_opts */
void register_opts(struct lightningd *ld UNNEEDED)
{ fprintf(stderr, "register_opts called!\n"); abort(); }
/* Could not find declaration for secp256k1_ecdsa_recoverable_signature_parse_compact */
/* Could not find declaration for secp256k1_ecdsa_recoverable_signature_serialize_compact */
/* Generated stub for setup_color_and_alias */
void setup_color_and_alias(struct lightningd *ld UNNEEDED)
{ fprintf(stderr, "setup_color_and_alias called!\n"); abort(); }

Loading…
Cancel
Save