From 36d92182a8797a47f79f9d1fbcc1b08563eb252d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 4 May 2021 14:29:19 +0200 Subject: [PATCH] libnm-core/tests: add test for connection.uuid of settings --- src/libnm-core-impl/tests/test-setting.c | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 5f9877c134..4516c472dc 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -229,6 +229,79 @@ test_private_key_import(const char *path, const char *password, NMSetting8021xCK g_object_unref(s_8021x); } +/*****************************************************************************/ + +static void +_do_test_connection_uuid(NMConnection *con, const char *uuid, const char *expected_uuid) +{ + NMSettingConnection *s_con; + gs_free char * uuid_old = NULL; + gboolean success; + + nmtst_assert_connection_verifies_without_normalization(con); + + s_con = NM_SETTING_CONNECTION(nm_connection_get_setting(con, NM_TYPE_SETTING_CONNECTION)); + g_assert(NM_IS_SETTING_CONNECTION(s_con)); + + g_assert(uuid); + + uuid_old = g_strdup(nm_setting_connection_get_uuid(s_con)); + + g_assert(nm_utils_is_uuid(uuid_old)); + + g_object_set(s_con, NM_SETTING_CONNECTION_UUID, uuid, NULL); + + g_assert_cmpstr(uuid, ==, nm_setting_connection_get_uuid(s_con)); + + if (nm_streq0(uuid, expected_uuid)) { + nmtst_assert_connection_verifies_without_normalization(con); + g_assert(nm_utils_is_uuid(uuid)); + } else if (!expected_uuid) { + gs_free_error GError *error = NULL; + + success = nm_connection_verify(con, &error); + nmtst_assert_no_success(success, error); + g_assert_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY); + + g_assert(!nm_utils_is_uuid(uuid)); + } else + g_assert_not_reached(); + + g_object_set(s_con, NM_SETTING_CONNECTION_UUID, uuid_old, NULL); + nmtst_assert_connection_verifies_without_normalization(con); +} + +static void +test_connection_uuid(void) +{ + gs_unref_object NMConnection *con = NULL; + + con = nmtst_create_minimal_connection("test-uuid", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); + + nmtst_connection_normalize(con); + +#define _do_test_connection_uuid_bad(con, uuid) _do_test_connection_uuid((con), "" uuid "", NULL) + +#define _do_test_connection_uuid_good(con, uuid) \ + _do_test_connection_uuid((con), "" uuid "", "" uuid "") + + _do_test_connection_uuid_bad(con, "x1e775e3-a316-4eb2-b4d8-4b0f2bcaea53"); + _do_test_connection_uuid_bad(con, "1e775e3aa3164eb2b4d84b0f2bcaea53abcdabc"); + _do_test_connection_uuid_bad(con, "1e775e3aa3164eb2b4d84b0f2bcaea53abcdabcdd"); + + _do_test_connection_uuid_good(con, "a1e775e3-a316-4eb2-b4d8-4b0f2bcaea53"); + + _do_test_connection_uuid_good(con, "A1E775e3-a316-4eb2-b4d8-4b0f2bcaea53"); + _do_test_connection_uuid_good(con, "A1E775E3-A316-4EB2-B4D8-4B0F2BCAEA53"); + _do_test_connection_uuid_good(con, "-1e775e3aa316-4eb2-b4d8-4b0f2bcaea53"); + _do_test_connection_uuid_good(con, "----1e775e3aa3164eb2b4d84b0f2bcaea53"); + _do_test_connection_uuid_good(con, "1e775e3aa3164eb2b4d84b0f2bcaea53abcdabcd"); + _do_test_connection_uuid_good(con, "1e775e3Aa3164eb2b4d84b0f2bcaea53abcdabcd"); + _do_test_connection_uuid_good(con, "1E775E3AA3164EB2B4D84B0F2BCAEA53ABCDABCD"); +} + +/*****************************************************************************/ + static void test_phase2_private_key_import(const char * path, const char * password, @@ -4258,6 +4331,8 @@ main(int argc, char **argv) { nmtst_init(&argc, &argv, TRUE); + g_test_add_func("/libnm/test_connection_uuid", test_connection_uuid); + g_test_add_data_func("/libnm/setting-8021x/key-and-cert", "test_key_and_cert.pem, test", test_8021x);