diff options
author | Dan Williams <dcbw@redhat.com> | 2011-08-16 15:47:12 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2011-08-16 15:48:38 -0500 |
commit | e2d88f59e6b95edfbd0b5ae7e7e396e8ab462664 (patch) | |
tree | c7eb4e459b015814449625200703e79e48d19f4e /libnm-util/tests/test-secrets.c | |
parent | 4d635844ec900f6d422b12b2d848b6705e937e76 (diff) | |
download | NetworkManager-e2d88f59e6b95edfbd0b5ae7e7e396e8ab462664.tar.gz |
settings: preserve agent secrets over Update operation
The core problem was that the Update would trigger a write to
disk to save the connection's new settings, which called
nm_settings_connection_replace_settings(). Which saved existing
transient (agent/unsaved) secrets, replaced settings with the
new ones from Update(), then copied back the old transient
secrets. This was to ensure that changes triggered from getting
agent secrets during activation (which might write the connection
out to disk if new system secrets were provided, which triggered
an inotify read-back of the connection, which blew away the
transient secrets just returned from the agent) didn't blow away
transient secrets. Unfortunately that fix was too general.
As a quick hack for now, copy the new secrets and re-apply them
after nm_connection_replace_settings() has run. We'll do the
actual fix later, but it's more involved and needs more testing
so we don't want to apply it this close to release.
Diffstat (limited to 'libnm-util/tests/test-secrets.c')
-rw-r--r-- | libnm-util/tests/test-secrets.c | 83 |
1 files changed, 82 insertions, 1 deletions
diff --git a/libnm-util/tests/test-secrets.c b/libnm-util/tests/test-secrets.c index f1d105fcd2..1fe3c43823 100644 --- a/libnm-util/tests/test-secrets.c +++ b/libnm-util/tests/test-secrets.c @@ -591,7 +591,84 @@ test_update_secrets_wifi_bad_setting_name (void) "asdfasdfasdfasf", secrets, &error); - g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_CONNECTION_SETTING_NOT_FOUND); + g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND); + g_assert (success == FALSE); + + g_object_unref (connection); +} + +static void +test_update_secrets_whole_connection (void) +{ + NMConnection *connection; + NMSettingWirelessSecurity *s_wsec; + GHashTable *secrets, *wsec_hash; + GError *error = NULL; + gboolean success; + const char *wepkey = "11111111111111111111111111"; + + connection = wifi_connection_new (); + + /* Build up the secrets hash */ + secrets = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); + wsec_hash = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); + g_assert (wsec_hash); + g_hash_table_insert (wsec_hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey)); + + success = nm_connection_update_secrets (connection, NULL, secrets, &error); + g_assert_no_error (error); + g_assert (success == TRUE); + + s_wsec = nm_connection_get_setting_wireless_security (connection); + g_assert (s_wsec); + g_assert_cmpstr (nm_setting_wireless_security_get_wep_key (s_wsec, 0), ==, wepkey); + + g_object_unref (connection); +} + +static void +test_update_secrets_whole_connection_empty_hash (void) +{ + NMConnection *connection; + GHashTable *secrets; + GError *error = NULL; + gboolean success; + + connection = wifi_connection_new (); + secrets = g_hash_table_new (g_str_hash, g_str_equal); + success = nm_connection_update_secrets (connection, NULL, secrets, &error); + g_assert_no_error (error); + g_assert (success == TRUE); + g_object_unref (connection); +} + +static void +test_update_secrets_whole_connection_bad_setting (void) +{ + NMConnection *connection; + GHashTable *secrets, *wsec_hash; + GError *error = NULL; + gboolean success; + const char *wepkey = "11111111111111111111111111"; + + connection = wifi_connection_new (); + + /* Build up the secrets hash */ + secrets = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); + wsec_hash = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); + g_assert (wsec_hash); + g_hash_table_insert (wsec_hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey)); + + /* Steal the wsec setting hash so it's not deallocated, and stuff it back + * in with a different name so we ensure libnm-util is returning the right + * error when it finds an entry in the connection hash that doesn't match + * any setting in the connection. + */ + g_hash_table_steal (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); + g_hash_table_insert (secrets, "asdfasdfasdfasdf", wsec_hash); + + success = nm_connection_update_secrets (connection, NULL, secrets, &error); + g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND); g_assert (success == FALSE); g_object_unref (connection); @@ -617,6 +694,10 @@ int main (int argc, char **argv) test_update_secrets_wifi_full_hash (); test_update_secrets_wifi_bad_setting_name (); + test_update_secrets_whole_connection (); + test_update_secrets_whole_connection_empty_hash (); + test_update_secrets_whole_connection_bad_setting (); + base = g_path_get_basename (argv[0]); fprintf (stdout, "%s: SUCCESS\n", base); g_free (base); |