LCOV - code coverage report
Current view: top level - daemon/dbus - test-dbus-lock.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 34 34
Test Date: 2024-04-08 13:24:42 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
       2              : /* test-secret-lock.c: Test secret lock
       3              : 
       4              :    Copyright (C) 2013 Red Hat Inc
       5              : 
       6              :    The Gnome Keyring Library is free software; you can redistribute it and/or
       7              :    modify it under the terms of the GNU Library General Public License as
       8              :    published by the Free Software Foundation; either version 2 of the
       9              :    License, or (at your option) any later version.
      10              : 
      11              :    The Gnome Keyring Library is distributed in the hope that it will be useful,
      12              :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13              :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14              :    Library General Public License for more details.
      15              : 
      16              :    You should have received a copy of the GNU Library General Public
      17              :    License along with the Gnome Library; see the file COPYING.LIB.  If not,
      18              :    <http://www.gnu.org/licenses/>.
      19              : 
      20              :    Author: Stef Walter <stefw@gnome.org>
      21              : */
      22              : 
      23              : #include "config.h"
      24              : 
      25              : #include "gkd-secret-types.h"
      26              : 
      27              : #include "test-service.h"
      28              : 
      29              : #include "egg/egg-testing.h"
      30              : 
      31              : typedef struct {
      32              :         TestService service;
      33              : } Test;
      34              : 
      35              : static void
      36            1 : setup (Test *test,
      37              :        gconstpointer unused)
      38              : {
      39            1 :         test_service_setup (&test->service);
      40            1 : }
      41              : 
      42              : static void
      43            1 : teardown (Test *test,
      44              :           gconstpointer unused)
      45              : {
      46            1 :         test_service_teardown (&test->service);
      47            1 : }
      48              : 
      49              : static gboolean
      50            3 : get_locked (Test *test,
      51              :             const gchar *path,
      52              :             const gchar *interface)
      53              : {
      54              :         GVariant *retval;
      55              :         GVariant *prop;
      56            3 :         GError *error = NULL;
      57              :         gboolean locked;
      58              : 
      59            3 :         retval = g_dbus_connection_call_sync (test->service.connection,
      60            3 :                                               test->service.bus_name,
      61              :                                               path, "org.freedesktop.DBus.Properties",
      62              :                                               "Get", g_variant_new ("(ss)", interface, "Locked"),
      63              :                                               G_VARIANT_TYPE ("(v)"),
      64              :                                               G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, &error);
      65            3 :         g_assert_no_error (error);
      66              : 
      67            3 :         g_variant_get (retval, "(v)", &prop);
      68            3 :         g_variant_unref (retval);
      69              : 
      70            3 :         locked = g_variant_get_boolean (prop);
      71            3 :         g_variant_unref (prop);
      72              : 
      73            3 :         return locked;
      74              : }
      75              : 
      76              : 
      77              : static void
      78            1 : test_lock_service (Test *test,
      79              :                    gconstpointer unused)
      80              : {
      81            1 :         GError *error = NULL;
      82              :         GVariant *retval;
      83              : 
      84            1 :         g_assert (get_locked (test, "/org/freedesktop/secrets/collection/test", SECRET_COLLECTION_INTERFACE) == TRUE);
      85              : 
      86              :         /* Unlock the test collection */
      87            1 :         retval = g_dbus_connection_call_sync (test->service.connection,
      88            1 :                                               test->service.bus_name,
      89              :                                               SECRET_SERVICE_PATH,
      90              :                                               INTERNAL_SERVICE_INTERFACE,
      91              :                                               "UnlockWithMasterPassword",
      92              :                                               g_variant_new ("(o@(oayays))",
      93              :                                                              "/org/freedesktop/secrets/collection/test",
      94              :                                                              test_service_build_secret (&test->service, "booo")),
      95              :                                               G_VARIANT_TYPE ("()"),
      96              :                                               G_DBUS_CALL_FLAGS_NO_AUTO_START,
      97              :                                               -1, NULL, &error);
      98            1 :         g_assert_no_error (error);
      99            1 :         g_variant_unref (retval);
     100              : 
     101              :         /* Check not locked */
     102            1 :         g_assert (get_locked (test, "/org/freedesktop/secrets/collection/test", SECRET_COLLECTION_INTERFACE) == FALSE);
     103              : 
     104              :         /* Lock everything */
     105            1 :         retval = g_dbus_connection_call_sync (test->service.connection,
     106            1 :                                               test->service.bus_name,
     107              :                                               "/org/freedesktop/secrets",
     108              :                                               SECRET_SERVICE_INTERFACE,
     109              :                                               "LockService",
     110              :                                               g_variant_new ("()"),
     111              :                                               G_VARIANT_TYPE ("()"),
     112              :                                               G_DBUS_CALL_FLAGS_NO_AUTO_START,
     113              :                                               -1, NULL, &error);
     114            1 :         g_assert_no_error (error);
     115            1 :         g_variant_unref (retval);
     116              : 
     117              :         /* Check locked */
     118            1 :         g_assert (get_locked (test, "/org/freedesktop/secrets/collection/test", SECRET_COLLECTION_INTERFACE) == TRUE);
     119            1 : }
     120              : 
     121              : int
     122            1 : main (int argc, char **argv)
     123              : {
     124              : #if !GLIB_CHECK_VERSION(2,35,0)
     125              :         g_type_init ();
     126              : #endif
     127            1 :         g_test_init (&argc, &argv, NULL);
     128              : 
     129            1 :         g_test_add ("/secret-lock/service", Test, NULL,
     130              :                     setup, test_lock_service, teardown);
     131              : 
     132            1 :         return egg_tests_run_with_loop ();
     133              : }
        

Generated by: LCOV version 2.0-1