From 8272626c3bf410ad792da6f167cc7b06627f197c Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 10 Mar 2020 22:37:28 +0100 Subject: [PATCH] Update the invite-join test. - Check that duplicate addresses get culled correctly. - Check that we can add lots of extra invitation addresses, and that they are in the expected order in the invitation URL. --- test/invite-join.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/invite-join.c b/test/invite-join.c index 831cac41..0bb09b0b 100644 --- a/test/invite-join.c +++ b/test/invite-join.c @@ -51,6 +51,7 @@ int main() { meshlink_set_node_status_cb(mesh1, status_cb); assert(meshlink_set_canonical_address(mesh1, meshlink_get_self(mesh1), "localhost", NULL)); + char *baz_url = meshlink_invite(mesh1, NULL, "baz"); assert(baz_url); @@ -140,6 +141,40 @@ int main() { assert(meshlink_join(mesh3, quux_url)); free(quux_url); + // Check that adding duplicate addresses get removed correctly + + assert(meshlink_add_invitation_address(mesh1, "localhost", portstr + 1)); + corge_url = meshlink_invite(mesh1, NULL, "corge"); + assert(corge_url); + char *localhost = strstr(corge_url, "localhost"); + assert(localhost); + assert(!strstr(localhost + 1, "localhost")); + free(corge_url); + + // Check that resetting and adding multiple, different invitation address works + + meshlink_clear_invitation_addresses(mesh1); + assert(meshlink_add_invitation_address(mesh1, "1.invalid.", NULL)); + assert(meshlink_add_invitation_address(mesh1, "2.invalid.", NULL)); + assert(meshlink_add_invitation_address(mesh1, "3.invalid.", NULL)); + assert(meshlink_add_invitation_address(mesh1, "4.invalid.", NULL)); + assert(meshlink_add_invitation_address(mesh1, "5.invalid.", NULL)); + char *grault_url = meshlink_invite(mesh1, NULL, "grault"); + assert(grault_url); + fprintf(stderr, "%s\n", grault_url); + localhost = strstr(grault_url, "localhost"); + assert(localhost); + char *invalid1 = strstr(grault_url, "1.invalid."); + assert(invalid1); + char *invalid5 = strstr(grault_url, "5.invalid."); + assert(invalid5); + + // Check that explicitly added invitation addresses come before others, in the order they were specified. + + assert(invalid1 < invalid5); + assert(invalid5 < localhost); + free(grault_url); + // Clean up. meshlink_close(mesh3); -- 2.39.2