]> git.meshlink.io Git - meshlink/commitdiff
Expand the storage policy test to check for correctness during invitations.
authorGuus Sliepen <guus@meshlink.io>
Thu, 4 Feb 2021 21:47:25 +0000 (22:47 +0100)
committerGuus Sliepen <guus@meshlink.io>
Fri, 5 Feb 2021 08:38:05 +0000 (09:38 +0100)
test/storage-policy.c

index f9593c8e13ec7e8747f3d91b1e62012747ef4541..ed78334b67b2545a3bbbc12f4735dc04386ba953 100644 (file)
@@ -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);
 }