From 68697a5454af2457f1d512d91151d5399ff7c557 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 4 Feb 2021 22:47:25 +0100 Subject: [PATCH] Expand the storage policy test to check for correctness during invitations. --- test/storage-policy.c | 58 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/test/storage-policy.c b/test/storage-policy.c index f9593c8e..ed78334b 100644 --- a/test/storage-policy.c +++ b/test/storage-policy.c @@ -148,7 +148,63 @@ int main(void) { assert(last_reachable); assert(last_unreachable); - // That's it. + // Start again from scratch, now use invite/join instead of import/export + + close_meshlink_pair(mesh1, mesh2); + + assert(meshlink_destroy("storage-policy_conf.1")); + assert(meshlink_destroy("storage-policy_conf.2")); + + mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE); + mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE); + assert(mesh1); + assert(mesh2); + meshlink_enable_discovery(mesh1, false); + meshlink_enable_discovery(mesh2, false); + meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_DISABLED); + meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_DISABLED); + + // Check that joining is not possible with storage disabled + + assert(meshlink_set_canonical_address(mesh1, meshlink_get_self(mesh1), "localhost", NULL)); + char *invitation = meshlink_invite(mesh1, NULL, "bar"); + assert(invitation); + assert(meshlink_start(mesh1)); + assert(!meshlink_join(mesh2, invitation)); + assert(meshlink_errno == MESHLINK_EINVAL); + meshlink_stop(mesh1); + + // Try again with KEYS_ONLY + + meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY); + meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY); + + assert(meshlink_start(mesh1)); + assert(meshlink_join(mesh2, invitation)); + assert(meshlink_errno == MESHLINK_EINVAL); + meshlink_stop(mesh1); + + start_meshlink_pair(mesh1, mesh2); + + // Close the instances and reopen them. + + close_meshlink_pair(mesh1, mesh2); + + mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE); + mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE); + assert(mesh1); + assert(mesh2); + meshlink_enable_discovery(mesh1, false); + meshlink_enable_discovery(mesh2, false); + meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY); + meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY); + + // Check that the nodes know each other + + assert(meshlink_get_node(mesh1, "bar")); + assert(meshlink_get_node(mesh2, "foo")); + + // Done. close_meshlink_pair(mesh1, mesh2); } -- 2.39.5