Files
federated-calendar/tests/test-federated-core.c
T
davidandClaude Opus 5.5 3c118fbb9d Add a Jitsi video conference to events on Core calendars
The event editor offers "Add Video Conference" on the calendars of a
Federated Computer Core. It makes a room with an unguessable name, like
BraveOttersSing-k3f9x2m7, on the Core's Jitsi at jitsi.<CORE_DOMAIN>,
and shows its link with Copy and Remove buttons.

The link goes at the end of the event's notes, which reach everyone
invited whatever their mail app, and in an RFC 7986 CONFERENCE property.
Saving puts the link back in the notes if it was taken out, and "All
events" copies the conference to the whole series.

Existing conferences are found in CONFERENCE, or as Jitsi links in the
notes or location, so the editor doesn't offer a second one and the
popover shows a Join button. The popover now keeps showing a place in
the location alongside a meeting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 07:28:20 -07:00

212 lines
7.6 KiB
C

/* test-federated-core.c
*
* Copyright (C) 2026 David Young <david@federated.computer>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <glib.h>
#include <glib/gstdio.h>
#include "gcal-federated-core.h"
/*
* Written by CoreDesktop's configure with bash's printf %q
*/
#define CORE_CONF(domain, email, name) \
"CORE_DOMAIN=" domain "\n" \
"CORE_EMAIL=" email "\n" \
"CORE_NAME=" name "\n"
static gchar *
create_config_dir (void)
{
g_autoptr (GError) error = NULL;
gchar *config_dir;
config_dir = g_dir_make_tmp ("gcal-federated-core-XXXXXX", &error);
g_assert_no_error (error);
return config_dir;
}
static void
write_file (const gchar *config_dir,
const gchar *filename,
const gchar *contents)
{
g_autoptr (GError) error = NULL;
g_autofree gchar *path = g_build_filename (config_dir, filename, NULL);
g_autofree gchar *dir = g_path_get_dirname (path);
g_mkdir_with_parents (dir, 0700);
g_file_set_contents (path, contents, -1, &error);
g_assert_no_error (error);
}
static void
remove_config_dir (const gchar *config_dir)
{
g_autoptr (GFile) dir = g_file_new_for_path (config_dir);
g_autoptr (GFileEnumerator) children = NULL;
GFileInfo *info;
GFile *child;
children = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL);
while (children && g_file_enumerator_iterate (children, &info, &child, NULL, NULL) && info)
{
if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
{
g_autofree gchar *path = g_file_get_path (child);
remove_config_dir (path);
}
else
{
g_file_delete (child, NULL, NULL);
}
}
g_file_delete (dir, NULL, NULL);
}
/*********************************************************************************************************************/
static void
federated_core_find_core (void)
{
g_autofree gchar *config_dir = create_config_dir ();
g_autofree gchar *email = NULL;
g_autofree gchar *name = NULL;
/* Nothing set up */
g_assert_false (gcal_federated_core_find_core (config_dir, "nextcloud.example.com", NULL, NULL));
write_file (config_dir, "cores/example.com.conf", CORE_CONF ("example.com", "ana@example.com", "Ana\\ Lima"));
write_file (config_dir, "cores/example.org.conf", CORE_CONF ("example.org", "bo@example.org", "Bo"));
g_assert_true (gcal_federated_core_find_core (config_dir, "nextcloud.example.com", &email, &name));
g_assert_cmpstr (email, ==, "ana@example.com");
g_assert_cmpstr (name, ==, "Ana Lima");
g_clear_pointer (&email, g_free);
g_clear_pointer (&name, g_free);
g_assert_true (gcal_federated_core_find_core (config_dir, "NextCloud.Example.Org", &email, &name));
g_assert_cmpstr (email, ==, "bo@example.org");
g_assert_cmpstr (name, ==, "Bo");
/* Only the Core's own Nextcloud */
g_assert_false (gcal_federated_core_find_core (config_dir, "example.com", NULL, NULL));
g_assert_false (gcal_federated_core_find_core (config_dir, "caldav.example.com", NULL, NULL));
g_assert_false (gcal_federated_core_find_core (config_dir, "nextcloud.example.com.evil.net", NULL, NULL));
g_assert_false (gcal_federated_core_find_core (config_dir, NULL, NULL, NULL));
remove_config_dir (config_dir);
}
static void
federated_core_single_core_conf (void)
{
g_autofree gchar *config_dir = create_config_dir ();
g_autofree gchar *email = NULL;
g_autofree gchar *name = NULL;
/* Before CoreDesktop supported several Cores */
write_file (config_dir, "core.conf", CORE_CONF ("example.com", "ana@example.com", "\\'Ana\\'"));
g_assert_true (gcal_federated_core_find_core (config_dir, "nextcloud.example.com", &email, &name));
g_assert_cmpstr (email, ==, "ana@example.com");
g_assert_cmpstr (name, ==, "'Ana'");
remove_config_dir (config_dir);
}
static void
federated_core_incomplete_conf (void)
{
g_autofree gchar *config_dir = create_config_dir ();
write_file (config_dir, "cores/example.com.conf", "CORE_DOMAIN=example.com\n");
write_file (config_dir, "cores/example.org.conf", CORE_CONF ("example.org", "not-an-email", "Bo"));
write_file (config_dir, "cores/example.net.conf.bak", CORE_CONF ("example.net", "cy@example.net", "Cy"));
g_assert_false (gcal_federated_core_find_core (config_dir, "nextcloud.example.com", NULL, NULL));
g_assert_false (gcal_federated_core_find_core (config_dir, "nextcloud.example.org", NULL, NULL));
g_assert_false (gcal_federated_core_find_core (config_dir, "nextcloud.example.net", NULL, NULL));
remove_config_dir (config_dir);
}
static void
federated_core_find_jitsi_server (void)
{
g_autofree gchar *config_dir = create_config_dir ();
g_autofree gchar *server = NULL;
/* Nothing set up */
g_assert_null (gcal_federated_core_find_jitsi_server (config_dir, "nextcloud.example.com"));
write_file (config_dir, "cores/example.com.conf", CORE_CONF ("example.com", "ana@example.com", "Ana\\ Lima"));
write_file (config_dir, "cores/example.org.conf", CORE_CONF ("example.org", "bo@example.org", "Bo"));
server = gcal_federated_core_find_jitsi_server (config_dir, "nextcloud.example.com");
g_assert_cmpstr (server, ==, "https://jitsi.example.com");
g_clear_pointer (&server, g_free);
server = gcal_federated_core_find_jitsi_server (config_dir, "NextCloud.Example.Org");
g_assert_cmpstr (server, ==, "https://jitsi.example.org");
g_clear_pointer (&server, g_free);
/* Only for calendars on the Core's own Nextcloud */
g_assert_null (gcal_federated_core_find_jitsi_server (config_dir, "example.com"));
g_assert_null (gcal_federated_core_find_jitsi_server (config_dir, "jitsi.example.com"));
g_assert_null (gcal_federated_core_find_jitsi_server (config_dir, "nextcloud.example.com.evil.net"));
g_assert_null (gcal_federated_core_find_jitsi_server (config_dir, "nextcloud.example.net"));
g_assert_null (gcal_federated_core_find_jitsi_server (config_dir, NULL));
remove_config_dir (config_dir);
}
static void
federated_core_jitsi_server_single_core_conf (void)
{
g_autofree gchar *config_dir = create_config_dir ();
g_autofree gchar *server = NULL;
write_file (config_dir, "core.conf", CORE_CONF ("example.com", "ana@example.com", "Ana"));
server = gcal_federated_core_find_jitsi_server (config_dir, "nextcloud.example.com");
g_assert_cmpstr (server, ==, "https://jitsi.example.com");
remove_config_dir (config_dir);
}
/*********************************************************************************************************************/
gint
main (gint argc,
gchar *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/federated-core/find-core", federated_core_find_core);
g_test_add_func ("/federated-core/single-core-conf", federated_core_single_core_conf);
g_test_add_func ("/federated-core/incomplete-conf", federated_core_incomplete_conf);
g_test_add_func ("/federated-core/find-jitsi-server", federated_core_find_jitsi_server);
g_test_add_func ("/federated-core/jitsi-server-single-core-conf", federated_core_jitsi_server_single_core_conf);
return g_test_run ();
}