X-Git-Url: http://git.meshlink.io/?p=meshlink;a=blobdiff_plain;f=test%2Finvite-join.c;h=f76dc536fffeb57da76f7e69400ebec5924c8ba0;hp=52a922a89a9509695639dd88e90623255e039884;hb=15b02e0766ce4fdbf604489fdb1f55c9a0cce850;hpb=93a7614d2aa368a9799d6e39c73542a3998e70bf diff --git a/test/invite-join.c b/test/invite-join.c index 52a922a8..f76dc536 100644 --- a/test/invite-join.c +++ b/test/invite-join.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "meshlink.h" @@ -183,6 +184,42 @@ int main() { free(corge_url); + // Check that invitations work correctly after changing ports + + meshlink_set_invitation_timeout(mesh1, 86400); + meshlink_stop(mesh1); + meshlink_stop(mesh3); + + int oldport = meshlink_get_port(mesh1); + bool success; + + for(int i = 0; i < 100; i++) { + success = meshlink_set_port(mesh1, 0x9000 + rand() % 0x1000); + } + + assert(success); + int newport = meshlink_get_port(mesh1); + assert(oldport != newport); + + assert(meshlink_start(mesh1)); + quux_url = meshlink_invite(mesh1, NULL, "quux"); + fprintf(stderr, "Invitation URL for quux: %s\n", quux_url); + + // The old port should not be in the invitation URL + + char portstr[10]; + snprintf(portstr, sizeof(portstr), ":%d", oldport); + assert(!strstr(quux_url, portstr)); + + // The new port should be in the invitation URL + + snprintf(portstr, sizeof(portstr), ":%d", newport); + assert(strstr(quux_url, portstr)); + + // The invitation should work + + assert(meshlink_join(mesh3, quux_url)); + // Clean up. meshlink_close(mesh3);