LCOV - code coverage report
Current view: top level - libsecret - test-paths.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 395 395 100.0 %
Date: 2024-02-08 14:44:34 Functions: 25 25 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 153 306 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* libsecret - GLib wrapper for Secret Service
       2                 :            :  *
       3                 :            :  * Copyright 2011 Collabora Ltd.
       4                 :            :  *
       5                 :            :  * This program is free software: you can redistribute it and/or modify
       6                 :            :  * it under the terms of the GNU Lesser General Public License as published
       7                 :            :  * by the Free Software Foundation; either version 2 of the licence or (at
       8                 :            :  * your option) any later version.
       9                 :            :  *
      10                 :            :  * See the included COPYING file for more information.
      11                 :            :  */
      12                 :            : 
      13                 :            : 
      14                 :            : #include "config.h"
      15                 :            : 
      16                 :            : #undef G_DISABLE_ASSERT
      17                 :            : 
      18                 :            : #include "secret-attributes.h"
      19                 :            : #include "secret-collection.h"
      20                 :            : #include "secret-item.h"
      21                 :            : #include "secret-paths.h"
      22                 :            : #include "secret-private.h"
      23                 :            : #include "secret-service.h"
      24                 :            : 
      25                 :            : #include "mock-service.h"
      26                 :            : 
      27                 :            : #include "egg/egg-testing.h"
      28                 :            : 
      29                 :            : #include <glib.h>
      30                 :            : 
      31                 :            : #include <errno.h>
      32                 :            : #include <stdlib.h>
      33                 :            : 
      34                 :            : static const SecretSchema MOCK_SCHEMA = {
      35                 :            :         "org.mock.Schema",
      36                 :            :         SECRET_SCHEMA_NONE,
      37                 :            :         {
      38                 :            :                 { "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
      39                 :            :                 { "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
      40                 :            :                 { "even", SECRET_SCHEMA_ATTRIBUTE_BOOLEAN },
      41                 :            :         }
      42                 :            : };
      43                 :            : 
      44                 :            : typedef struct {
      45                 :            :         SecretService *service;
      46                 :            : } Test;
      47                 :            : 
      48                 :            : static void
      49                 :         20 : setup_mock (Test *test,
      50                 :            :             gconstpointer data)
      51                 :            : {
      52                 :         20 :         GError *error = NULL;
      53                 :         20 :         const gchar *mock_script = data;
      54                 :            : 
      55                 :         20 :         mock_service_start (mock_script, &error);
      56         [ -  + ]:         20 :         g_assert_no_error (error);
      57                 :         20 : }
      58                 :            : 
      59                 :            : static void
      60                 :         20 : setup (Test *test,
      61                 :            :        gconstpointer data)
      62                 :            : {
      63                 :         20 :         GError *error = NULL;
      64                 :            : 
      65                 :         20 :         setup_mock (test, data);
      66                 :            : 
      67                 :         20 :         test->service = secret_service_get_sync (SECRET_SERVICE_NONE, NULL, &error);
      68         [ -  + ]:         20 :         g_assert_no_error (error);
      69                 :         20 :         g_object_add_weak_pointer (G_OBJECT (test->service), (gpointer *)&test->service);
      70                 :         20 : }
      71                 :            : 
      72                 :            : static void
      73                 :         20 : teardown_mock (Test *test,
      74                 :            :                gconstpointer unused)
      75                 :            : {
      76                 :         20 :         secret_service_disconnect ();
      77                 :         20 :         mock_service_stop ();
      78                 :         20 : }
      79                 :            : 
      80                 :            : static void
      81                 :         20 : teardown (Test *test,
      82                 :            :           gconstpointer unused)
      83                 :            : {
      84                 :         20 :         egg_test_wait_idle ();
      85                 :            : 
      86                 :         20 :         g_object_unref (test->service);
      87                 :         20 :         secret_service_disconnect ();
      88         [ -  + ]:         20 :         g_assert_null (test->service);
      89                 :            : 
      90                 :         20 :         teardown_mock (test, unused);
      91                 :         20 : }
      92                 :            : 
      93                 :            : static void
      94                 :          8 : on_complete_get_result (GObject *source,
      95                 :            :                         GAsyncResult *result,
      96                 :            :                         gpointer user_data)
      97                 :            : {
      98                 :          8 :         GAsyncResult **ret = user_data;
      99         [ -  + ]:          8 :         g_assert_nonnull (ret);
     100         [ -  + ]:          8 :         g_assert_null (*ret);
     101                 :          8 :         *ret = g_object_ref (result);
     102                 :          8 :         egg_test_wait_stop ();
     103                 :          8 : }
     104                 :            : 
     105                 :            : static void
     106                 :          1 : test_search_paths_sync (Test *test,
     107                 :            :                         gconstpointer used)
     108                 :            : {
     109                 :            :         GHashTable *attributes;
     110                 :            :         gboolean ret;
     111                 :            :         gchar **locked;
     112                 :            :         gchar **unlocked;
     113                 :          1 :         GError *error = NULL;
     114                 :            : 
     115                 :          1 :         attributes = g_hash_table_new (g_str_hash, g_str_equal);
     116                 :          1 :         g_hash_table_insert (attributes, "number", "1");
     117                 :            : 
     118                 :          1 :         ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes, NULL,
     119                 :            :                                                          &unlocked, &locked, &error);
     120         [ -  + ]:          1 :         g_assert_no_error (error);
     121         [ -  + ]:          1 :         g_assert_true (ret);
     122                 :            : 
     123         [ -  + ]:          1 :         g_assert_nonnull (locked);
     124         [ -  + ]:          1 :         g_assert_cmpstr (locked[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
     125                 :            : 
     126         [ -  + ]:          1 :         g_assert_nonnull (unlocked);
     127         [ -  + ]:          1 :         g_assert_cmpstr (unlocked[0], ==, "/org/freedesktop/secrets/collection/english/1");
     128                 :            : 
     129                 :          1 :         g_strfreev (unlocked);
     130                 :          1 :         g_strfreev (locked);
     131                 :            : 
     132                 :          1 :         g_hash_table_unref (attributes);
     133                 :          1 : }
     134                 :            : 
     135                 :            : static void
     136                 :          1 : test_search_paths_async (Test *test,
     137                 :            :                          gconstpointer used)
     138                 :            : {
     139                 :          1 :         GAsyncResult *result = NULL;
     140                 :            :         GHashTable *attributes;
     141                 :            :         gboolean ret;
     142                 :            :         gchar **locked;
     143                 :            :         gchar **unlocked;
     144                 :          1 :         GError *error = NULL;
     145                 :            : 
     146                 :          1 :         attributes = g_hash_table_new (g_str_hash, g_str_equal);
     147                 :          1 :         g_hash_table_insert (attributes, "number", "1");
     148                 :            : 
     149                 :          1 :         secret_service_search_for_dbus_paths (test->service, &MOCK_SCHEMA, attributes, NULL,
     150                 :            :                                               on_complete_get_result, &result);
     151         [ -  + ]:          1 :         egg_test_wait ();
     152                 :            : 
     153   [ -  +  +  -  :          1 :         g_assert_true (G_IS_ASYNC_RESULT (result));
             -  +  -  + ]
     154                 :          1 :         ret = secret_service_search_for_dbus_paths_finish (test->service, result,
     155                 :            :                                                                 &unlocked, &locked,
     156                 :            :                                                                 &error);
     157         [ -  + ]:          1 :         g_assert_no_error (error);
     158         [ -  + ]:          1 :         g_assert_true (ret);
     159                 :            : 
     160         [ -  + ]:          1 :         g_assert_nonnull (locked);
     161         [ -  + ]:          1 :         g_assert_cmpstr (locked[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
     162                 :            : 
     163         [ -  + ]:          1 :         g_assert_nonnull (unlocked);
     164         [ -  + ]:          1 :         g_assert_cmpstr (unlocked[0], ==, "/org/freedesktop/secrets/collection/english/1");
     165                 :            : 
     166                 :          1 :         g_strfreev (unlocked);
     167                 :          1 :         g_strfreev (locked);
     168                 :          1 :         g_object_unref (result);
     169                 :            : 
     170                 :          1 :         g_hash_table_unref (attributes);
     171                 :          1 : }
     172                 :            : 
     173                 :            : static void
     174                 :          1 : test_search_paths_nulls (Test *test,
     175                 :            :                          gconstpointer used)
     176                 :            : {
     177                 :          1 :         GAsyncResult *result = NULL;
     178                 :            :         GHashTable *attributes;
     179                 :            :         gboolean ret;
     180                 :            :         gchar **paths;
     181                 :          1 :         GError *error = NULL;
     182                 :            : 
     183                 :          1 :         attributes = g_hash_table_new (g_str_hash, g_str_equal);
     184                 :          1 :         g_hash_table_insert (attributes, "number", "1");
     185                 :            : 
     186                 :          1 :         ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes, NULL,
     187                 :            :                                                      &paths, NULL, &error);
     188         [ -  + ]:          1 :         g_assert_no_error (error);
     189         [ -  + ]:          1 :         g_assert_true (ret);
     190         [ -  + ]:          1 :         g_assert_nonnull (paths);
     191         [ -  + ]:          1 :         g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/english/1");
     192                 :          1 :         g_strfreev (paths);
     193                 :            : 
     194                 :          1 :         ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes, NULL,
     195                 :            :                                                          NULL, &paths, &error);
     196         [ -  + ]:          1 :         g_assert_no_error (error);
     197         [ -  + ]:          1 :         g_assert_true (ret);
     198         [ -  + ]:          1 :         g_assert_nonnull (paths);
     199         [ -  + ]:          1 :         g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
     200                 :          1 :         g_strfreev (paths);
     201                 :            : 
     202                 :          1 :         ret = secret_service_search_for_dbus_paths_sync (test->service, &MOCK_SCHEMA, attributes, NULL,
     203                 :            :                                                          NULL, NULL, &error);
     204         [ -  + ]:          1 :         g_assert_no_error (error);
     205         [ -  + ]:          1 :         g_assert_true (ret);
     206                 :            : 
     207                 :          1 :         secret_service_search_for_dbus_paths (test->service, &MOCK_SCHEMA, attributes, NULL,
     208                 :            :                                               on_complete_get_result, &result);
     209         [ -  + ]:          1 :         egg_test_wait ();
     210   [ -  +  +  -  :          1 :         g_assert_true (G_IS_ASYNC_RESULT (result));
             -  +  -  + ]
     211                 :          1 :         ret = secret_service_search_for_dbus_paths_finish (test->service, result,
     212                 :            :                                                            &paths, NULL, &error);
     213         [ -  + ]:          1 :         g_assert_no_error (error);
     214         [ -  + ]:          1 :         g_assert_true (ret);
     215         [ -  + ]:          1 :         g_assert_nonnull (paths);
     216         [ -  + ]:          1 :         g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/english/1");
     217                 :          1 :         g_strfreev (paths);
     218         [ +  - ]:          1 :         g_clear_object (&result);
     219                 :            : 
     220                 :          1 :         secret_service_search_for_dbus_paths (test->service, &MOCK_SCHEMA, attributes, NULL,
     221                 :            :                                               on_complete_get_result, &result);
     222         [ -  + ]:          1 :         egg_test_wait ();
     223   [ -  +  +  -  :          1 :         g_assert_true (G_IS_ASYNC_RESULT (result));
             -  +  -  + ]
     224                 :          1 :         ret = secret_service_search_for_dbus_paths_finish (test->service, result,
     225                 :            :                                                            NULL, &paths, &error);
     226         [ -  + ]:          1 :         g_assert_no_error (error);
     227         [ -  + ]:          1 :         g_assert_true (ret);
     228         [ -  + ]:          1 :         g_assert_nonnull (paths);
     229         [ -  + ]:          1 :         g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/spanish/10");
     230                 :          1 :         g_strfreev (paths);
     231         [ +  - ]:          1 :         g_clear_object (&result);
     232                 :            : 
     233                 :          1 :         secret_service_search_for_dbus_paths (test->service, &MOCK_SCHEMA, attributes, NULL,
     234                 :            :                                               on_complete_get_result, &result);
     235         [ -  + ]:          1 :         egg_test_wait ();
     236   [ -  +  +  -  :          1 :         g_assert_true (G_IS_ASYNC_RESULT (result));
             -  +  -  + ]
     237                 :          1 :         ret = secret_service_search_for_dbus_paths_finish (test->service, result,
     238                 :            :                                                            NULL, NULL, &error);
     239         [ -  + ]:          1 :         g_assert_no_error (error);
     240         [ -  + ]:          1 :         g_assert_true (ret);
     241         [ +  - ]:          1 :         g_clear_object (&result);
     242                 :            : 
     243                 :          1 :         g_hash_table_unref (attributes);
     244                 :          1 : }
     245                 :            : 
     246                 :            : static void
     247                 :          2 : test_secret_for_path_sync (Test *test,
     248                 :            :                            gconstpointer used)
     249                 :            : {
     250                 :            :         SecretValue *value;
     251                 :          2 :         GError *error = NULL;
     252                 :            :         const gchar *path;
     253                 :            :         const gchar *password;
     254                 :            :         gsize length;
     255                 :            : 
     256                 :          2 :         path = "/org/freedesktop/secrets/collection/english/1";
     257                 :          2 :         value = secret_service_get_secret_for_dbus_path_sync (test->service, path, NULL, &error);
     258         [ -  + ]:          2 :         g_assert_no_error (error);
     259         [ -  + ]:          2 :         g_assert_nonnull (value);
     260                 :            : 
     261                 :          2 :         password = secret_value_get (value, &length);
     262         [ -  + ]:          2 :         g_assert_cmpuint (length, ==, 3);
     263         [ -  + ]:          2 :         g_assert_cmpstr (password, ==, "111");
     264                 :            : 
     265                 :          2 :         password = secret_value_get (value, NULL);
     266         [ -  + ]:          2 :         g_assert_cmpstr (password, ==, "111");
     267                 :            : 
     268                 :          2 :         secret_value_unref (value);
     269                 :          2 : }
     270                 :            : 
     271                 :            : static void
     272                 :          1 : test_secret_for_path_async (Test *test,
     273                 :            :                             gconstpointer used)
     274                 :            : {
     275                 :            :         SecretValue *value;
     276                 :          1 :         GError *error = NULL;
     277                 :            :         const gchar *path;
     278                 :            :         const gchar *password;
     279                 :          1 :         GAsyncResult *result = NULL;
     280                 :            :         gsize length;
     281                 :            : 
     282                 :          1 :         path = "/org/freedesktop/secrets/collection/english/1";
     283                 :          1 :         secret_service_get_secret_for_dbus_path (test->service, path, NULL,
     284                 :            :                                                  on_complete_get_result, &result);
     285         [ -  + ]:          1 :         g_assert_null (result);
     286         [ -  + ]:          1 :         egg_test_wait ();
     287                 :            : 
     288                 :          1 :         value = secret_service_get_secret_for_dbus_path_finish (test->service, result, &error);
     289         [ -  + ]:          1 :         g_assert_no_error (error);
     290         [ -  + ]:          1 :         g_assert_nonnull (value);
     291                 :          1 :         g_object_unref (result);
     292                 :            : 
     293                 :          1 :         password = secret_value_get (value, &length);
     294         [ -  + ]:          1 :         g_assert_cmpuint (length, ==, 3);
     295         [ -  + ]:          1 :         g_assert_cmpstr (password, ==, "111");
     296                 :            : 
     297                 :          1 :         password = secret_value_get (value, NULL);
     298         [ -  + ]:          1 :         g_assert_cmpstr (password, ==, "111");
     299                 :            : 
     300                 :          1 :         secret_value_unref (value);
     301                 :          1 : }
     302                 :            : 
     303                 :            : static void
     304                 :          1 : test_secrets_for_paths_sync (Test *test,
     305                 :            :                              gconstpointer used)
     306                 :            : {
     307                 :          1 :         const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
     308                 :          1 :         const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
     309                 :          1 :         const gchar *paths[] = {
     310                 :            :                 path_item_one,
     311                 :            :                 path_item_two,
     312                 :            : 
     313                 :            :                 /* This one is locked, and not returned */
     314                 :            :                 "/org/freedesktop/secrets/collection/spanish/10",
     315                 :            :                 NULL
     316                 :            :         };
     317                 :            : 
     318                 :            :         SecretValue *value;
     319                 :            :         GHashTable *values;
     320                 :          1 :         GError *error = NULL;
     321                 :            :         const gchar *password;
     322                 :            :         gsize length;
     323                 :            : 
     324                 :          1 :         values = secret_service_get_secrets_for_dbus_paths_sync (test->service, paths, NULL, &error);
     325         [ -  + ]:          1 :         g_assert_no_error (error);
     326                 :            : 
     327         [ -  + ]:          1 :         g_assert_nonnull (values);
     328         [ -  + ]:          1 :         g_assert_cmpuint (g_hash_table_size (values), ==, 2);
     329                 :            : 
     330                 :          1 :         value = g_hash_table_lookup (values, path_item_one);
     331         [ -  + ]:          1 :         g_assert_nonnull (value);
     332                 :          1 :         password = secret_value_get (value, &length);
     333         [ -  + ]:          1 :         g_assert_cmpuint (length, ==, 3);
     334         [ -  + ]:          1 :         g_assert_cmpstr (password, ==, "111");
     335                 :            : 
     336                 :          1 :         value = g_hash_table_lookup (values, path_item_two);
     337         [ -  + ]:          1 :         g_assert_nonnull (value);
     338                 :          1 :         password = secret_value_get (value, &length);
     339         [ -  + ]:          1 :         g_assert_cmpuint (length, ==, 3);
     340         [ -  + ]:          1 :         g_assert_cmpstr (password, ==, "222");
     341                 :            : 
     342                 :          1 :         g_hash_table_unref (values);
     343                 :          1 : }
     344                 :            : 
     345                 :            : static void
     346                 :          1 : test_secrets_for_paths_async (Test *test,
     347                 :            :                               gconstpointer used)
     348                 :            : {
     349                 :          1 :         const gchar *path_item_one = "/org/freedesktop/secrets/collection/english/1";
     350                 :          1 :         const gchar *path_item_two = "/org/freedesktop/secrets/collection/english/2";
     351                 :          1 :         const gchar *paths[] = {
     352                 :            :                 path_item_one,
     353                 :            :                 path_item_two,
     354                 :            : 
     355                 :            :                 /* This one is locked, and not returned */
     356                 :            :                 "/org/freedesktop/secrets/collection/spanish/10",
     357                 :            :                 NULL
     358                 :            :         };
     359                 :            : 
     360                 :            :         SecretValue *value;
     361                 :            :         GHashTable *values;
     362                 :          1 :         GError *error = NULL;
     363                 :            :         const gchar *password;
     364                 :          1 :         GAsyncResult *result = NULL;
     365                 :            :         gsize length;
     366                 :            : 
     367                 :          1 :         secret_service_get_secrets_for_dbus_paths (test->service, paths, NULL,
     368                 :            :                                                    on_complete_get_result, &result);
     369         [ -  + ]:          1 :         g_assert_null (result);
     370         [ -  + ]:          1 :         egg_test_wait ();
     371                 :            : 
     372                 :          1 :         values = secret_service_get_secrets_for_dbus_paths_finish (test->service, result, &error);
     373         [ -  + ]:          1 :         g_assert_no_error (error);
     374                 :          1 :         g_object_unref (result);
     375                 :            : 
     376         [ -  + ]:          1 :         g_assert_nonnull (values);
     377         [ -  + ]:          1 :         g_assert_cmpuint (g_hash_table_size (values), ==, 2);
     378                 :            : 
     379                 :          1 :         value = g_hash_table_lookup (values, path_item_one);
     380         [ -  + ]:          1 :         g_assert_nonnull (value);
     381                 :          1 :         password = secret_value_get (value, &length);
     382         [ -  + ]:          1 :         g_assert_cmpuint (length, ==, 3);
     383         [ -  + ]:          1 :         g_assert_cmpstr (password, ==, "111");
     384                 :            : 
     385                 :          1 :         value = g_hash_table_lookup (values, path_item_two);
     386         [ -  + ]:          1 :         g_assert_nonnull (value);
     387                 :          1 :         password = secret_value_get (value, &length);
     388         [ -  + ]:          1 :         g_assert_cmpuint (length, ==, 3);
     389         [ -  + ]:          1 :         g_assert_cmpstr (password, ==, "222");
     390                 :            : 
     391                 :          1 :         g_hash_table_unref (values);
     392                 :          1 : }
     393                 :            : 
     394                 :            : static void
     395                 :          1 : test_delete_for_path_sync (Test *test,
     396                 :            :                            gconstpointer used)
     397                 :            : 
     398                 :            : {
     399                 :          1 :         const gchar *path_item_one = "/org/freedesktop/secrets/collection/todelete/item";
     400                 :          1 :         GError *error = NULL;
     401                 :            :         gboolean ret;
     402                 :            : 
     403                 :          1 :         ret = secret_service_delete_item_dbus_path_sync (test->service, path_item_one, NULL, &error);
     404         [ -  + ]:          1 :         g_assert_no_error (error);
     405         [ -  + ]:          1 :         g_assert_true (ret);
     406                 :          1 : }
     407                 :            : 
     408                 :            : static void
     409                 :          1 : test_delete_for_path_sync_prompt (Test *test,
     410                 :            :                                   gconstpointer used)
     411                 :            : 
     412                 :            : {
     413                 :          1 :         const gchar *path_item_one = "/org/freedesktop/secrets/collection/todelete/confirm";
     414                 :          1 :         GError *error = NULL;
     415                 :            :         gboolean ret;
     416                 :            : 
     417                 :          1 :         ret = secret_service_delete_item_dbus_path_sync (test->service, path_item_one, NULL, &error);
     418         [ -  + ]:          1 :         g_assert_no_error (error);
     419         [ -  + ]:          1 :         g_assert_true (ret);
     420                 :          1 : }
     421                 :            : 
     422                 :            : static void
     423                 :          1 : test_lock_paths_sync (Test *test,
     424                 :            :                       gconstpointer used)
     425                 :            : {
     426                 :          1 :         const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
     427                 :          1 :         const gchar *paths[] = {
     428                 :            :                 collection_path,
     429                 :            :                 NULL,
     430                 :            :         };
     431                 :            : 
     432                 :          1 :         GError *error = NULL;
     433                 :          1 :         gchar **locked = NULL;
     434                 :            :         gboolean ret;
     435                 :            : 
     436                 :          1 :         ret = secret_service_lock_dbus_paths_sync (test->service, paths, NULL, &locked, &error);
     437         [ -  + ]:          1 :         g_assert_no_error (error);
     438         [ -  + ]:          1 :         g_assert_true (ret);
     439                 :            : 
     440         [ -  + ]:          1 :         g_assert_nonnull (locked);
     441         [ -  + ]:          1 :         g_assert_cmpstr (locked[0], ==, collection_path);
     442         [ -  + ]:          1 :         g_assert_null (locked[1]);
     443                 :          1 :         g_strfreev (locked);
     444                 :          1 : }
     445                 :            : 
     446                 :            : static void
     447                 :          1 : test_lock_prompt_sync (Test *test,
     448                 :            :                        gconstpointer used)
     449                 :            : {
     450                 :          1 :         const gchar *collection_path = "/org/freedesktop/secrets/collection/lockprompt";
     451                 :          1 :         const gchar *paths[] = {
     452                 :            :                 collection_path,
     453                 :            :                 NULL,
     454                 :            :         };
     455                 :            : 
     456                 :          1 :         GError *error = NULL;
     457                 :          1 :         gchar **locked = NULL;
     458                 :            :         gboolean ret;
     459                 :            : 
     460                 :          1 :         ret = secret_service_lock_dbus_paths_sync (test->service, paths, NULL, &locked, &error);
     461         [ -  + ]:          1 :         g_assert_no_error (error);
     462         [ -  + ]:          1 :         g_assert_true (ret);
     463                 :            : 
     464         [ -  + ]:          1 :         g_assert_nonnull (locked);
     465         [ -  + ]:          1 :         g_assert_cmpstr (locked[0], ==, collection_path);
     466         [ -  + ]:          1 :         g_assert_null (locked[1]);
     467                 :          1 :         g_strfreev (locked);
     468                 :          1 : }
     469                 :            : 
     470                 :            : static void
     471                 :          1 : test_unlock_paths_sync (Test *test,
     472                 :            :                         gconstpointer used)
     473                 :            : {
     474                 :          1 :         const gchar *collection_path = "/org/freedesktop/secrets/collection/lockone";
     475                 :          1 :         const gchar *paths[] = {
     476                 :            :                 collection_path,
     477                 :            :                 NULL,
     478                 :            :         };
     479                 :            : 
     480                 :          1 :         GError *error = NULL;
     481                 :          1 :         gchar **unlocked = NULL;
     482                 :            :         gboolean ret;
     483                 :            : 
     484                 :          1 :         ret = secret_service_unlock_dbus_paths_sync (test->service, paths, NULL, &unlocked, &error);
     485         [ -  + ]:          1 :         g_assert_no_error (error);
     486         [ -  + ]:          1 :         g_assert_true (ret);
     487                 :            : 
     488         [ -  + ]:          1 :         g_assert_nonnull (unlocked);
     489         [ -  + ]:          1 :         g_assert_cmpstr (unlocked[0], ==, collection_path);
     490         [ -  + ]:          1 :         g_assert_null (unlocked[1]);
     491                 :          1 :         g_strfreev (unlocked);
     492                 :          1 : }
     493                 :            : 
     494                 :            : static void
     495                 :          1 : test_unlock_prompt_sync (Test *test,
     496                 :            :                          gconstpointer used)
     497                 :            : {
     498                 :          1 :         const gchar *collection_path = "/org/freedesktop/secrets/collection/lockprompt";
     499                 :          1 :         const gchar *paths[] = {
     500                 :            :                 collection_path,
     501                 :            :                 NULL,
     502                 :            :         };
     503                 :            : 
     504                 :          1 :         GError *error = NULL;
     505                 :          1 :         gchar **unlocked = NULL;
     506                 :            :         gboolean ret;
     507                 :            : 
     508                 :          1 :         ret = secret_service_unlock_dbus_paths_sync (test->service, paths, NULL, &unlocked, &error);
     509         [ -  + ]:          1 :         g_assert_no_error (error);
     510         [ -  + ]:          1 :         g_assert_true (ret);
     511                 :            : 
     512         [ -  + ]:          1 :         g_assert_nonnull (unlocked);
     513         [ -  + ]:          1 :         g_assert_cmpstr (unlocked[0], ==, collection_path);
     514         [ -  + ]:          1 :         g_assert_null (unlocked[1]);
     515                 :          1 :         g_strfreev (unlocked);
     516                 :          1 : }
     517                 :            : 
     518                 :            : static void
     519                 :          1 : test_collection_sync (Test *test,
     520                 :            :                       gconstpointer used)
     521                 :            : {
     522                 :            :         GHashTable *properties;
     523                 :          1 :         GError *error = NULL;
     524                 :            :         gchar *path;
     525                 :            : 
     526                 :          1 :         properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
     527                 :            :                                             (GDestroyNotify)g_variant_unref);
     528                 :          1 :         g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
     529                 :          1 :                              g_variant_ref_sink (g_variant_new_string ("Wheeee")));
     530                 :            : 
     531                 :          1 :         path = secret_service_create_collection_dbus_path_sync (test->service, properties,
     532                 :            :                                                                 NULL, SECRET_COLLECTION_CREATE_NONE,
     533                 :            :                                                                 NULL, &error);
     534                 :            : 
     535                 :          1 :         g_hash_table_unref (properties);
     536                 :            : 
     537         [ -  + ]:          1 :         g_assert_no_error (error);
     538         [ -  + ]:          1 :         g_assert_nonnull (path);
     539   [ +  -  -  +  :          1 :         g_assert_true (g_str_has_prefix (path, "/org/freedesktop/secrets/collection/"));
             +  -  -  + ]
     540                 :            : 
     541                 :          1 :         g_free (path);
     542                 :          1 : }
     543                 :            : 
     544                 :            : static void
     545                 :          1 : test_collection_async (Test *test,
     546                 :            :                        gconstpointer used)
     547                 :            : {
     548                 :          1 :         GAsyncResult *result = NULL;
     549                 :            :         GHashTable *properties;
     550                 :          1 :         GError *error = NULL;
     551                 :            :         gchar *path;
     552                 :            : 
     553                 :          1 :         properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
     554                 :            :                                             (GDestroyNotify)g_variant_unref);
     555                 :          1 :         g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
     556                 :          1 :                              g_variant_ref_sink (g_variant_new_string ("Wheeee")));
     557                 :            : 
     558                 :          1 :         secret_service_create_collection_dbus_path (test->service, properties,
     559                 :            :                                                     NULL, SECRET_COLLECTION_CREATE_NONE,
     560                 :            :                                                     NULL, on_complete_get_result, &result);
     561                 :            : 
     562                 :          1 :         g_hash_table_unref (properties);
     563         [ -  + ]:          1 :         g_assert_null (result);
     564                 :            : 
     565         [ -  + ]:          1 :         egg_test_wait ();
     566                 :            : 
     567                 :          1 :         path = secret_service_create_collection_dbus_path_finish (test->service, result, &error);
     568                 :          1 :         g_object_unref (result);
     569                 :            : 
     570         [ -  + ]:          1 :         g_assert_no_error (error);
     571         [ -  + ]:          1 :         g_assert_nonnull (path);
     572   [ +  -  -  +  :          1 :         g_assert_true (g_str_has_prefix (path, "/org/freedesktop/secrets/collection/"));
             +  -  -  + ]
     573                 :            : 
     574                 :          1 :         g_free (path);
     575                 :          1 : }
     576                 :            : 
     577                 :            : static void
     578                 :          1 : test_item_sync (Test *test,
     579                 :            :                 gconstpointer used)
     580                 :            : {
     581                 :          1 :         const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
     582                 :            :         GHashTable *properties;
     583                 :            :         GHashTable *attributes;
     584                 :            :         SecretValue *value;
     585                 :          1 :         GError *error = NULL;
     586                 :            :         gchar *path;
     587                 :            : 
     588                 :          1 :         attributes = g_hash_table_new (g_str_hash, g_str_equal);
     589                 :          1 :         g_hash_table_insert (attributes, "even", "true");
     590                 :          1 :         g_hash_table_insert (attributes, "string", "ten");
     591                 :          1 :         g_hash_table_insert (attributes, "number", "10");
     592                 :            : 
     593                 :          1 :         properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
     594                 :            :                                             (GDestroyNotify)g_variant_unref);
     595                 :          1 :         g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
     596                 :          1 :                              g_variant_ref_sink (g_variant_new_string ("Wheeee")));
     597                 :          1 :         g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Attributes",
     598                 :          1 :                              g_variant_ref_sink (_secret_attributes_to_variant (attributes, "org.gnome.Test")));
     599                 :            : 
     600                 :          1 :         g_hash_table_unref (attributes);
     601                 :            : 
     602                 :          1 :         value = secret_value_new ("andmoreandmore", -1, "text/plain");
     603                 :            : 
     604                 :          1 :         path = secret_service_create_item_dbus_path_sync (test->service, collection_path,
     605                 :            :                                                           properties, value, SECRET_ITEM_CREATE_NONE,
     606                 :            :                                                           NULL, &error);
     607                 :            : 
     608                 :          1 :         secret_value_unref (value);
     609                 :          1 :         g_hash_table_unref (properties);
     610                 :            : 
     611         [ -  + ]:          1 :         g_assert_no_error (error);
     612         [ -  + ]:          1 :         g_assert_nonnull (path);
     613         [ -  + ]:          1 :         g_assert_true (g_str_has_prefix (path, collection_path));
     614                 :            : 
     615                 :          1 :         g_free (path);
     616                 :          1 : }
     617                 :            : 
     618                 :            : static void
     619                 :          1 : test_item_async (Test *test,
     620                 :            :                        gconstpointer used)
     621                 :            : {
     622                 :          1 :         const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
     623                 :            :         GHashTable *properties;
     624                 :            :         GHashTable *attributes;
     625                 :            :         SecretValue *value;
     626                 :          1 :         GError *error = NULL;
     627                 :          1 :         GAsyncResult *result = NULL;
     628                 :            :         gchar *path;
     629                 :            : 
     630                 :          1 :         attributes = g_hash_table_new (g_str_hash, g_str_equal);
     631                 :          1 :         g_hash_table_insert (attributes, "even", "true");
     632                 :          1 :         g_hash_table_insert (attributes, "string", "ten");
     633                 :          1 :         g_hash_table_insert (attributes, "number", "10");
     634                 :            : 
     635                 :          1 :         properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
     636                 :            :                                             (GDestroyNotify)g_variant_unref);
     637                 :          1 :         g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Label",
     638                 :          1 :                              g_variant_ref_sink (g_variant_new_string ("Wheeee")));
     639                 :          1 :         g_hash_table_insert (properties, SECRET_COLLECTION_INTERFACE ".Attributes",
     640                 :          1 :                              g_variant_ref_sink (_secret_attributes_to_variant (attributes, NULL)));
     641                 :            : 
     642                 :          1 :         g_hash_table_unref (attributes);
     643                 :            : 
     644                 :          1 :         value = secret_value_new ("andmoreandmore", -1, "text/plain");
     645                 :            : 
     646                 :          1 :         secret_service_create_item_dbus_path (test->service, collection_path,
     647                 :            :                                               properties, value, SECRET_ITEM_CREATE_NONE,
     648                 :            :                                               NULL, on_complete_get_result, &result);
     649                 :            : 
     650         [ -  + ]:          1 :         g_assert_null (result);
     651                 :          1 :         secret_value_unref (value);
     652                 :          1 :         g_hash_table_unref (properties);
     653                 :            : 
     654         [ -  + ]:          1 :         egg_test_wait ();
     655                 :            : 
     656                 :          1 :         path = secret_service_create_item_dbus_path_finish (test->service, result, &error);
     657                 :          1 :         g_object_unref (result);
     658                 :            : 
     659         [ -  + ]:          1 :         g_assert_no_error (error);
     660         [ -  + ]:          1 :         g_assert_nonnull (path);
     661         [ -  + ]:          1 :         g_assert_true (g_str_has_prefix (path, collection_path));
     662                 :            : 
     663                 :          1 :         g_free (path);
     664                 :          1 : }
     665                 :            : 
     666                 :            : static void
     667                 :          1 : test_set_alias_path (Test *test,
     668                 :            :                      gconstpointer used)
     669                 :            : {
     670                 :            :         gchar *path;
     671                 :          1 :         GError *error = NULL;
     672                 :            :         gboolean ret;
     673                 :            : 
     674                 :          1 :         path = secret_service_read_alias_dbus_path_sync (test->service, "blah", NULL, &error);
     675         [ -  + ]:          1 :         g_assert_no_error (error);
     676         [ -  + ]:          1 :         g_assert_null (path);
     677                 :            : 
     678                 :          1 :         ret = secret_service_set_alias_to_dbus_path_sync (test->service, "blah", "/org/freedesktop/secrets/collection/english", NULL, &error);
     679         [ -  + ]:          1 :         g_assert_no_error (error);
     680         [ -  + ]:          1 :         g_assert_true (ret);
     681                 :            : 
     682                 :          1 :         path = secret_service_read_alias_dbus_path_sync (test->service, "blah", NULL, &error);
     683         [ -  + ]:          1 :         g_assert_no_error (error);
     684         [ -  + ]:          1 :         g_assert_cmpstr (path, ==, "/org/freedesktop/secrets/collection/english");
     685                 :          1 :         g_free (path);
     686                 :            : 
     687                 :          1 :         ret = secret_service_set_alias_to_dbus_path_sync (test->service, "blah", NULL, NULL, &error);
     688         [ -  + ]:          1 :         g_assert_no_error (error);
     689         [ -  + ]:          1 :         g_assert_true (ret);
     690                 :            : 
     691                 :          1 :         path = secret_service_read_alias_dbus_path_sync (test->service, "blah", NULL, &error);
     692         [ -  + ]:          1 :         g_assert_no_error (error);
     693         [ -  + ]:          1 :         g_assert_null (path);
     694                 :          1 : }
     695                 :            : 
     696                 :            : static void
     697                 :          1 : test_encode_decode_secret (Test *test,
     698                 :            :                            gconstpointer unused)
     699                 :            : {
     700                 :            :         GVariant *variant;
     701                 :            :         SecretValue *value;
     702                 :            :         SecretValue *decoded;
     703                 :          1 :         GError *error = NULL;
     704                 :            : 
     705                 :          1 :         value = secret_value_new ("zerogjuggs", -1, "text/plain");
     706                 :            : 
     707                 :          1 :         secret_service_ensure_session_sync (test->service, NULL, &error);
     708         [ -  + ]:          1 :         g_assert_no_error (error);
     709                 :            : 
     710                 :          1 :         variant = secret_service_encode_dbus_secret (test->service, value);
     711         [ -  + ]:          1 :         g_assert_nonnull (variant);
     712         [ -  + ]:          1 :         g_assert_cmpstr (g_variant_get_type_string (variant), ==, "(oayays)");
     713                 :          1 :         secret_value_unref (value);
     714                 :            : 
     715                 :          1 :         decoded = secret_service_decode_dbus_secret (test->service, variant);
     716         [ -  + ]:          1 :         g_assert_nonnull (variant);
     717                 :          1 :         g_variant_unref (variant);
     718                 :            : 
     719         [ -  + ]:          1 :         g_assert_cmpstr (secret_value_get_text (decoded), ==, "zerogjuggs");
     720                 :          1 :         secret_value_unref (decoded);
     721                 :          1 : }
     722                 :            : 
     723                 :            : int
     724                 :          1 : main (int argc, char **argv)
     725                 :            : {
     726                 :          1 :         g_test_init (&argc, &argv, NULL);
     727                 :          1 :         g_set_prgname ("test-service");
     728                 :            : 
     729                 :          1 :         g_test_add ("/service/search-for-paths", Test, "mock-service-normal.py", setup, test_search_paths_sync, teardown);
     730                 :          1 :         g_test_add ("/service/search-for-paths-async", Test, "mock-service-normal.py", setup, test_search_paths_async, teardown);
     731                 :          1 :         g_test_add ("/service/search-for-paths-nulls", Test, "mock-service-normal.py", setup, test_search_paths_nulls, teardown);
     732                 :            : 
     733                 :          1 :         g_test_add ("/service/secret-for-path-sync", Test, "mock-service-normal.py", setup, test_secret_for_path_sync, teardown);
     734                 :          1 :         g_test_add ("/service/secret-for-path-plain", Test, "mock-service-only-plain.py", setup, test_secret_for_path_sync, teardown);
     735                 :          1 :         g_test_add ("/service/secret-for-path-async", Test, "mock-service-normal.py", setup, test_secret_for_path_async, teardown);
     736                 :          1 :         g_test_add ("/service/secrets-for-paths-sync", Test, "mock-service-normal.py", setup, test_secrets_for_paths_sync, teardown);
     737                 :          1 :         g_test_add ("/service/secrets-for-paths-async", Test, "mock-service-normal.py", setup, test_secrets_for_paths_async, teardown);
     738                 :            : 
     739                 :          1 :         g_test_add ("/service/delete-for-path", Test, "mock-service-delete.py", setup, test_delete_for_path_sync, teardown);
     740                 :          1 :         g_test_add ("/service/delete-for-path-with-prompt", Test, "mock-service-delete.py", setup, test_delete_for_path_sync_prompt, teardown);
     741                 :            : 
     742                 :          1 :         g_test_add ("/service/lock-paths-sync", Test, "mock-service-lock.py", setup, test_lock_paths_sync, teardown);
     743                 :          1 :         g_test_add ("/service/lock-prompt-sync", Test, "mock-service-lock.py", setup, test_lock_prompt_sync, teardown);
     744                 :            : 
     745                 :          1 :         g_test_add ("/service/unlock-paths-sync", Test, "mock-service-lock.py", setup, test_unlock_paths_sync, teardown);
     746                 :          1 :         g_test_add ("/service/unlock-prompt-sync", Test, "mock-service-lock.py", setup, test_unlock_prompt_sync, teardown);
     747                 :            : 
     748                 :          1 :         g_test_add ("/service/create-collection-sync", Test, "mock-service-normal.py", setup, test_collection_sync, teardown);
     749                 :          1 :         g_test_add ("/service/create-collection-async", Test, "mock-service-normal.py", setup, test_collection_async, teardown);
     750                 :            : 
     751                 :          1 :         g_test_add ("/service/create-item-sync", Test, "mock-service-normal.py", setup, test_item_sync, teardown);
     752                 :          1 :         g_test_add ("/service/create-item-async", Test, "mock-service-normal.py", setup, test_item_async, teardown);
     753                 :            : 
     754                 :          1 :         g_test_add ("/service/set-alias-path", Test, "mock-service-normal.py", setup, test_set_alias_path, teardown);
     755                 :            : 
     756                 :          1 :         g_test_add ("/service/encode-decode-secret", Test, "mock-service-normal.py", setup, test_encode_decode_secret, teardown);
     757                 :            : 
     758                 :          1 :         return egg_tests_run_with_loop ();
     759                 :            : }

Generated by: LCOV version 1.14