libnm-core/tests: add test for connection.uuid of settings

This commit is contained in:
Thomas Haller 2021-05-04 14:29:19 +02:00
parent 05130b6e10
commit 36d92182a8
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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);