LCOV - code coverage report
Current view: top level - gcr - test-ssh-agent-service.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 309 311 99.4 %
Date: 2022-09-04 10:20:22 Functions: 38 38 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 46 96 47.9 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * gnome-keyring
       3                 :            :  *
       4                 :            :  * Copyright (C) 2018 Red Hat, Inc.
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU Lesser General Public License as
       8                 :            :  * published by the Free Software Foundation; either version 2.1 of
       9                 :            :  * the License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful, but
      12                 :            :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14                 :            :  * Lesser General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU Lesser General Public
      17                 :            :  * License along with this program; if not, see
      18                 :            :  * <http://www.gnu.org/licenses/>.
      19                 :            :  *
      20                 :            :  * Author: Daiki Ueno
      21                 :            :  */
      22                 :            : 
      23                 :            : #include "config.h"
      24                 :            : 
      25                 :            : #include "gcr-ssh-agent-service.h"
      26                 :            : #include "gcr-ssh-agent-private.h"
      27                 :            : #include "gcr-ssh-agent-util.h"
      28                 :            : #include "gcr-ssh-agent-test.h"
      29                 :            : #include "egg/egg-testing.h"
      30                 :            : #include "egg/mock-interaction.h"
      31                 :            : 
      32                 :            : #include <glib.h>
      33                 :            : #include <glib/gstdio.h>
      34                 :            : #include <gio/gunixsocketaddress.h>
      35                 :            : 
      36                 :            : typedef struct {
      37                 :            :         gchar *directory;
      38                 :            :         EggBuffer req;
      39                 :            :         EggBuffer resp;
      40                 :            :         GcrSshAgentService *service;
      41                 :            :         GMainContext *server_thread_context;
      42                 :            :         volatile gint server_thread_stop;
      43                 :            :         GSocketConnection *connection;
      44                 :            :         GThread *thread;
      45                 :            :         GMutex lock;
      46                 :            :         GCond cond;
      47                 :            : } Test;
      48                 :            : 
      49                 :            : static gpointer
      50                 :         15 : server_thread (gpointer data)
      51                 :            : {
      52                 :         15 :         Test *test = data;
      53                 :            :         gboolean ret;
      54                 :            : 
      55                 :         15 :         g_main_context_push_thread_default (test->server_thread_context);
      56                 :            : 
      57                 :         15 :         ret = gcr_ssh_agent_service_start (test->service);
      58         [ -  + ]:         15 :         g_assert_true (ret);
      59                 :            : 
      60                 :         15 :         g_mutex_lock (&test->lock);
      61                 :         15 :         g_cond_signal (&test->cond);
      62                 :         15 :         g_mutex_unlock (&test->lock);
      63                 :            : 
      64         [ +  + ]:         75 :         while (g_atomic_int_get (&test->server_thread_stop) == 0)
      65                 :         60 :                 g_main_context_iteration (test->server_thread_context, TRUE);
      66                 :            : 
      67                 :         15 :         g_main_context_pop_thread_default (test->server_thread_context);
      68                 :            : 
      69                 :         15 :         return NULL;
      70                 :            : }
      71                 :            : 
      72                 :            : static void
      73                 :         14 : connect_to_server (Test *test)
      74                 :            : {
      75                 :            :         const gchar *envvar;
      76                 :            :         GSocketClient *client;
      77                 :            :         GSocketAddress *address;
      78                 :            :         GError *error;
      79                 :            : 
      80                 :         14 :         envvar = g_getenv ("SSH_AUTH_SOCK");
      81         [ -  + ]:         14 :         g_assert_nonnull (envvar);
      82                 :         14 :         address = g_unix_socket_address_new (envvar);
      83                 :            : 
      84                 :         14 :         client = g_socket_client_new ();
      85                 :            : 
      86                 :         14 :         error = NULL;
      87                 :         14 :         test->connection = g_socket_client_connect (client,
      88                 :         14 :                                                     G_SOCKET_CONNECTABLE (address),
      89                 :            :                                                     NULL,
      90                 :            :                                                     &error);
      91         [ -  + ]:         14 :         g_assert_nonnull (test->connection);
      92         [ -  + ]:         14 :         g_assert_no_error (error);
      93                 :            : 
      94                 :         14 :         g_object_unref (address);
      95                 :         14 :         g_object_unref (client);
      96                 :         14 : }
      97                 :            : 
      98                 :            : static void
      99                 :         15 : setup (Test *test, gconstpointer unused)
     100                 :            : {
     101                 :            :         GTlsInteraction *interaction;
     102                 :            :         GcrSshAgentPreload *preload;
     103                 :            :         gchar *sockets_path;
     104                 :            :         gchar *preload_path;
     105                 :            :         gchar *path;
     106                 :            : 
     107                 :         15 :         test->directory = egg_tests_create_scratch_directory (NULL, NULL);
     108                 :            : 
     109                 :         15 :         sockets_path = g_build_filename (test->directory, "sockets", NULL);
     110                 :         15 :         g_mkdir (sockets_path, 0700);
     111                 :            : 
     112                 :         15 :         preload_path = g_build_filename (test->directory, "preload", NULL);
     113                 :         15 :         g_mkdir (preload_path, 0700);
     114                 :            : 
     115                 :         15 :         egg_tests_copy_scratch_file (preload_path, SRCDIR "/gcr/fixtures/ssh-agent/id_rsa_plain");
     116                 :         15 :         egg_tests_copy_scratch_file (preload_path, SRCDIR "/gcr/fixtures/ssh-agent/id_rsa_plain.pub");
     117                 :            : 
     118                 :         15 :         path = g_build_filename (preload_path, "id_rsa_plain", NULL);
     119                 :         15 :         g_chmod (path, 0600);
     120                 :         15 :         g_free (path);
     121                 :            : 
     122                 :         15 :         egg_buffer_init_full (&test->req, 128, (EggBufferAllocator)g_realloc);
     123                 :         15 :         egg_buffer_init_full (&test->resp, 128, (EggBufferAllocator)g_realloc);
     124                 :            : 
     125                 :         15 :         preload = gcr_ssh_agent_preload_new (preload_path);
     126                 :         15 :         g_free (preload_path);
     127                 :            : 
     128                 :         15 :         test->service = gcr_ssh_agent_service_new (sockets_path, preload);
     129                 :         15 :         g_free (sockets_path);
     130                 :            : 
     131                 :         15 :         interaction = mock_interaction_new ("password");
     132                 :         15 :         g_object_set (test->service, "interaction", interaction, NULL);
     133                 :            : 
     134                 :         15 :         g_object_unref (interaction);
     135                 :         15 :         g_object_unref (preload);
     136                 :            : 
     137                 :         15 :         g_mutex_init (&test->lock);
     138                 :         15 :         g_cond_init (&test->cond);
     139                 :         15 :         test->server_thread_context = g_main_context_new ();
     140                 :            : 
     141                 :         15 :         test->thread = g_thread_new ("ssh-agent", server_thread, test);
     142                 :            : 
     143                 :            :         /* Wait until the server is up */
     144                 :         15 :         g_mutex_lock (&test->lock);
     145                 :         15 :         g_cond_wait (&test->cond, &test->lock);
     146                 :         15 :         g_mutex_unlock (&test->lock);
     147                 :         15 : }
     148                 :            : 
     149                 :            : static void
     150                 :         15 : teardown (Test *test, gconstpointer unused)
     151                 :            : {
     152                 :         15 :         g_atomic_int_set (&test->server_thread_stop, 1);
     153                 :         15 :         g_main_context_wakeup (test->server_thread_context);
     154                 :         15 :         g_thread_join (test->thread);
     155                 :            : 
     156                 :         15 :         g_main_context_unref (test->server_thread_context);
     157                 :            : 
     158         [ +  + ]:         15 :         g_clear_object (&test->connection);
     159                 :            : 
     160                 :         15 :         gcr_ssh_agent_service_stop (test->service);
     161                 :         15 :         g_object_unref (test->service);
     162                 :            : 
     163                 :         15 :         egg_buffer_uninit (&test->req);
     164                 :         15 :         egg_buffer_uninit (&test->resp);
     165                 :            : 
     166                 :         15 :         egg_tests_remove_scratch_directory (test->directory);
     167                 :         15 :         g_free (test->directory);
     168                 :            : 
     169                 :         15 :         g_cond_clear (&test->cond);
     170                 :         15 :         g_mutex_clear (&test->lock);
     171                 :         15 : }
     172                 :            : 
     173                 :            : static void
     174                 :         22 : call (Test *test)
     175                 :            : {
     176                 :            :         GError *error;
     177                 :            :         gboolean ret;
     178                 :            : 
     179                 :         22 :         error = NULL;
     180                 :         22 :         ret = _gcr_ssh_agent_write_packet (test->connection, &test->req, NULL, &error);
     181         [ -  + ]:         22 :         g_assert_true (ret);
     182         [ -  + ]:         22 :         g_assert_no_error (error);
     183                 :            : 
     184                 :         22 :         error = NULL;
     185                 :         22 :         ret = _gcr_ssh_agent_read_packet (test->connection, &test->resp, NULL, &error);
     186         [ -  + ]:         22 :         g_assert_true (ret);
     187         [ -  + ]:         22 :         g_assert_no_error (error);
     188                 :         22 : }
     189                 :            : 
     190                 :            : static void
     191                 :          3 : call_error_or_failure (Test *test, gint dom, gint code)
     192                 :            : {
     193                 :            :         GError *error;
     194                 :            :         gboolean ret;
     195                 :            : 
     196                 :          3 :         error = NULL;
     197                 :          3 :         ret = _gcr_ssh_agent_write_packet (test->connection, &test->req, NULL, &error);
     198         [ -  + ]:          3 :         g_assert_true (ret);
     199         [ -  + ]:          3 :         g_assert_no_error (error);
     200                 :            : 
     201                 :          3 :         error = NULL;
     202                 :          3 :         ret = _gcr_ssh_agent_read_packet (test->connection, &test->resp, NULL, &error);
     203         [ +  - ]:          3 :         if (ret)
     204                 :          3 :                 check_failure (&test->resp);
     205                 :            :         else {
     206         [ #  # ]:          0 :                 g_assert_false (ret);
     207   [ #  #  #  #  :          0 :                 g_assert_error (error, dom, code);
                   #  # ]
     208                 :            :         }
     209                 :          3 : }
     210                 :            : 
     211                 :         19 : DEFINE_CALL_FUNCS(Test, call)
     212                 :            : 
     213                 :            : static void
     214                 :          1 : call_unparseable_add (Test *test)
     215                 :            : {
     216                 :          1 :         egg_buffer_reset (&test->req);
     217                 :          1 :         egg_buffer_reset (&test->resp);
     218                 :            : 
     219                 :          1 :         prepare_add_identity (&test->req);
     220                 :          1 :         egg_buffer_set_uint32 (&test->req, 5, 0x80000000);
     221                 :          1 :         call_error_or_failure (test, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED);
     222                 :          1 : }
     223                 :            : 
     224                 :            : static void
     225                 :          1 : call_unparseable_remove (Test *test)
     226                 :            : {
     227                 :          1 :         egg_buffer_reset (&test->req);
     228                 :          1 :         egg_buffer_reset (&test->resp);
     229                 :            : 
     230                 :          1 :         prepare_remove_identity (&test->req);
     231                 :          1 :         egg_buffer_set_uint32 (&test->req, 5, 0x80000000);
     232                 :          1 :         call_error_or_failure (test, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED);
     233                 :          1 : }
     234                 :            : 
     235                 :            : static void
     236                 :          1 : call_unparseable_sign (Test *test)
     237                 :            : {
     238                 :          1 :         egg_buffer_reset (&test->req);
     239                 :          1 :         egg_buffer_reset (&test->resp);
     240                 :            : 
     241                 :          1 :         prepare_sign_request (&test->req);
     242                 :          1 :         egg_buffer_set_uint32 (&test->req, 5, 0x80000000);
     243                 :          1 :         call_error_or_failure (test, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED);
     244                 :          1 : }
     245                 :            : 
     246                 :            : static void
     247                 :          1 : prepare_sign_request_unknown (EggBuffer *req)
     248                 :            : {
     249                 :            :         GBytes *public_key;
     250                 :            :         gchar *comment;
     251                 :            :         gsize length;
     252                 :            :         const guchar *blob;
     253                 :            :         gboolean ret;
     254                 :            : 
     255                 :          1 :         public_key = public_key_from_file (SRCDIR "/gcr/fixtures/ssh-agent/id_ecdsa_plain.pub", &comment);
     256                 :          1 :         g_free (comment);
     257                 :          1 :         blob = g_bytes_get_data (public_key, &length);
     258                 :            : 
     259                 :          1 :         egg_buffer_reset (req);
     260                 :          1 :         ret = egg_buffer_add_uint32 (req, 0);
     261         [ -  + ]:          1 :         g_assert_true (ret);
     262                 :            : 
     263                 :          1 :         ret = egg_buffer_add_byte (req, GCR_SSH_OP_SIGN_REQUEST);
     264         [ -  + ]:          1 :         g_assert_true (ret);
     265                 :            : 
     266                 :          1 :         ret = egg_buffer_add_byte_array (req, blob, length);
     267         [ -  + ]:          1 :         g_assert_true (ret);
     268                 :            : 
     269                 :          1 :         ret = egg_buffer_add_string (req, "data");
     270         [ -  + ]:          1 :         g_assert_true (ret);
     271                 :            : 
     272                 :          1 :         ret = egg_buffer_add_uint32 (req, 0);
     273         [ -  + ]:          1 :         g_assert_true (ret);
     274                 :            : 
     275                 :          1 :         ret = egg_buffer_set_uint32 (req, 0, req->len - 4);
     276         [ -  + ]:          1 :         g_assert_true (ret);
     277                 :            : 
     278                 :          1 :         g_bytes_unref (public_key);
     279                 :          1 : }
     280                 :            : 
     281                 :            : static void
     282                 :          1 : call_sign_unknown (Test *test)
     283                 :            : {
     284                 :          1 :         egg_buffer_reset (&test->req);
     285                 :          1 :         egg_buffer_reset (&test->resp);
     286                 :            : 
     287                 :          1 :         prepare_sign_request_unknown (&test->req);
     288                 :          1 :         call (test);
     289                 :          1 :         check_failure (&test->resp);
     290                 :          1 : }
     291                 :            : 
     292                 :            : static void
     293                 :          1 : call_empty (Test *test)
     294                 :            : {
     295                 :            :         GError *error;
     296                 :            :         gboolean ret;
     297                 :            : 
     298                 :          1 :         egg_buffer_reset (&test->req);
     299                 :          1 :         egg_buffer_reset (&test->resp);
     300                 :            : 
     301                 :          1 :         ret = egg_buffer_add_uint32 (&test->req, 0);
     302         [ -  + ]:          1 :         g_assert_true (ret);
     303                 :            : 
     304                 :          1 :         error = NULL;
     305                 :          1 :         ret = _gcr_ssh_agent_write_packet (test->connection, &test->req, NULL, &error);
     306         [ -  + ]:          1 :         g_assert_true (ret);
     307         [ -  + ]:          1 :         g_assert_no_error (error);
     308                 :            : 
     309                 :          1 :         error = NULL;
     310                 :          1 :         ret = _gcr_ssh_agent_read_packet (test->connection, &test->resp, NULL, &error);
     311         [ -  + ]:          1 :         g_assert_false (ret);
     312   [ +  -  +  -  :          1 :         g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED);
                   -  + ]
     313                 :          1 : }
     314                 :            : 
     315                 :            : static void
     316                 :          1 : call_unknown (Test *test)
     317                 :            : {
     318                 :            :         GError *error;
     319                 :            :         gboolean ret;
     320                 :            : 
     321                 :          1 :         egg_buffer_reset (&test->req);
     322                 :          1 :         egg_buffer_reset (&test->resp);
     323                 :            : 
     324                 :          1 :         ret = egg_buffer_add_uint32 (&test->req, 0);
     325         [ -  + ]:          1 :         g_assert_true (ret);
     326                 :            : 
     327                 :          1 :         ret = egg_buffer_add_byte (&test->req, 255);
     328         [ -  + ]:          1 :         g_assert_true (ret);
     329                 :            : 
     330                 :          1 :         error = NULL;
     331                 :          1 :         ret = _gcr_ssh_agent_write_packet (test->connection, &test->req, NULL, &error);
     332         [ -  + ]:          1 :         g_assert_true (ret);
     333         [ -  + ]:          1 :         g_assert_no_error (error);
     334                 :            : 
     335                 :          1 :         error = NULL;
     336                 :          1 :         ret = _gcr_ssh_agent_read_packet (test->connection, &test->resp, NULL, &error);
     337         [ -  + ]:          1 :         g_assert_true (ret);
     338         [ -  + ]:          1 :         g_assert_no_error (error);
     339                 :            : 
     340                 :          1 :         check_failure (&test->resp);
     341                 :          1 : }
     342                 :            : 
     343                 :            : static void
     344                 :          1 : call_lock (Test *test)
     345                 :            : {
     346                 :            :         gboolean ret;
     347                 :            : 
     348                 :          1 :         egg_buffer_reset (&test->req);
     349                 :          1 :         egg_buffer_reset (&test->resp);
     350                 :            : 
     351                 :          1 :         ret = egg_buffer_add_uint32 (&test->req, 0);
     352         [ -  + ]:          1 :         g_assert_true (ret);
     353                 :            : 
     354                 :          1 :         ret = egg_buffer_add_byte (&test->req, GCR_SSH_OP_LOCK);
     355         [ -  + ]:          1 :         g_assert_true (ret);
     356                 :            : 
     357                 :          1 :         ret = egg_buffer_add_string (&test->req, "password");
     358         [ -  + ]:          1 :         g_assert_true (ret);
     359                 :            : 
     360                 :          1 :         ret = egg_buffer_set_uint32 (&test->req, 0, test->req.len - 4);
     361         [ -  + ]:          1 :         g_assert_true (ret);
     362                 :            : 
     363                 :          1 :         call (test);
     364                 :            : 
     365                 :          1 :         check_success (&test->resp);
     366                 :          1 : }
     367                 :            : 
     368                 :            : static void
     369                 :          1 : call_unlock (Test *test)
     370                 :            : {
     371                 :            :         gboolean ret;
     372                 :            : 
     373                 :          1 :         egg_buffer_reset (&test->req);
     374                 :          1 :         egg_buffer_reset (&test->resp);
     375                 :            : 
     376                 :          1 :         ret = egg_buffer_add_uint32 (&test->req, 0);
     377         [ -  + ]:          1 :         g_assert_true (ret);
     378                 :            : 
     379                 :          1 :         ret = egg_buffer_add_byte (&test->req, GCR_SSH_OP_UNLOCK);
     380         [ -  + ]:          1 :         g_assert_true (ret);
     381                 :            : 
     382                 :          1 :         ret = egg_buffer_add_string (&test->req, "password");
     383         [ -  + ]:          1 :         g_assert_true (ret);
     384                 :            : 
     385                 :          1 :         ret = egg_buffer_set_uint32 (&test->req, 0, test->req.len - 4);
     386         [ -  + ]:          1 :         g_assert_true (ret);
     387                 :            : 
     388                 :          1 :         call (test);
     389                 :            : 
     390                 :          1 :         check_success (&test->resp);
     391                 :          1 : }
     392                 :            : 
     393                 :            : static void
     394                 :          1 : test_startup_shutdown (Test *test, gconstpointer unused)
     395                 :            : {
     396                 :          1 : }
     397                 :            : 
     398                 :            : static void
     399                 :          1 : test_list (Test *test, gconstpointer unused)
     400                 :            : {
     401                 :          1 :         connect_to_server (test);
     402                 :            : 
     403                 :          1 :         call_request_identities (test, 1);
     404                 :          1 : }
     405                 :            : 
     406                 :            : static void
     407                 :          1 : test_add (Test *test, gconstpointer unused)
     408                 :            : {
     409                 :          1 :         connect_to_server (test);
     410                 :            : 
     411                 :            :         /* Adding an identity from the preloaded location doesn't
     412                 :            :          * change the total number of keys returned from
     413                 :            :          * GCR_SSH_OP_REQUEST_IDENTITIES */
     414                 :          1 :         call_add_identity (test);
     415                 :          1 :         call_request_identities (test, 1);
     416                 :          1 : }
     417                 :            : 
     418                 :            : static void
     419                 :          1 : test_unparseable_add (Test *test, gconstpointer unused)
     420                 :            : {
     421                 :          1 :         connect_to_server (test);
     422                 :            : 
     423                 :          1 :         call_unparseable_add (test);
     424                 :          1 : }
     425                 :            : 
     426                 :            : static void
     427                 :          1 : test_unparseable_remove (Test *test, gconstpointer unused)
     428                 :            : {
     429                 :          1 :         connect_to_server (test);
     430                 :            : 
     431                 :          1 :         call_unparseable_remove (test); /* This closes the connection */
     432                 :          1 : }
     433                 :            : 
     434                 :            : static void
     435                 :          1 : test_unparseable_sign (Test *test, gconstpointer unused)
     436                 :            : {
     437                 :          1 :         connect_to_server (test);
     438                 :            : 
     439                 :          1 :         call_unparseable_sign (test); /* This closes the connection */
     440                 :          1 : }
     441                 :            : 
     442                 :            : static void
     443                 :          1 : test_remove (Test *test, gconstpointer unused)
     444                 :            : {
     445                 :          1 :         connect_to_server (test);
     446                 :            : 
     447                 :            :         /* Adding an identity from the preloaded location doesn't
     448                 :            :          * change the total number of keys returned from
     449                 :            :          * GCR_SSH_OP_REQUEST_IDENTITIES */
     450                 :          1 :         call_add_identity (test);
     451                 :          1 :         call_request_identities (test, 1);
     452                 :            : 
     453                 :            :         /* Removing an identity from the preloaded location doesn't
     454                 :            :          * change the total number of keys returned from
     455                 :            :          * GCR_SSH_OP_REQUEST_IDENTITIES */
     456                 :          1 :         call_remove_identity (test);
     457                 :          1 :         call_request_identities (test, 1);
     458                 :          1 : }
     459                 :            : 
     460                 :            : static void
     461                 :          1 : test_remove_all (Test *test, gconstpointer unused)
     462                 :            : {
     463                 :          1 :         connect_to_server (test);
     464                 :            : 
     465                 :            :         /* Adding an identity from the preloaded location doesn't
     466                 :            :          * change the total number of keys returned from
     467                 :            :          * GCR_SSH_OP_REQUEST_IDENTITIES */
     468                 :          1 :         call_add_identity (test);
     469                 :          1 :         call_request_identities (test, 1);
     470                 :            : 
     471                 :            :         /* Removing an identity from the preloaded location doesn't
     472                 :            :          * change the total number of keys returned from
     473                 :            :          * GCR_SSH_OP_REQUEST_IDENTITIES */
     474                 :          1 :         call_remove_all_identities (test);
     475                 :          1 :         call_request_identities (test, 1);
     476                 :          1 : }
     477                 :            : 
     478                 :            : static void
     479                 :          1 : test_sign_loaded (Test *test, gconstpointer unused)
     480                 :            : {
     481                 :          1 :         connect_to_server (test);
     482                 :            : 
     483                 :            :         /* Adding an identity from the preloaded location doesn't
     484                 :            :          * change the total number of keys returned from
     485                 :            :          * GCR_SSH_OP_REQUEST_IDENTITIES */
     486                 :          1 :         call_add_identity (test);
     487                 :          1 :         call_request_identities (test, 1);
     488                 :            : 
     489                 :          1 :         call_sign (test);
     490                 :          1 : }
     491                 :            : 
     492                 :            : static void
     493                 :          1 : test_sign (Test *test, gconstpointer unused)
     494                 :            : {
     495                 :          1 :         connect_to_server (test);
     496                 :            : 
     497                 :          1 :         call_sign (test);
     498                 :          1 : }
     499                 :            : 
     500                 :            : static void
     501                 :          1 : test_sign_unknown (Test *test, gconstpointer unused)
     502                 :            : {
     503                 :          1 :         connect_to_server (test);
     504                 :            : 
     505                 :          1 :         call_sign_unknown (test);
     506                 :          1 : }
     507                 :            : 
     508                 :            : static gpointer
     509                 :          1 : kill_thread (gpointer data)
     510                 :            : {
     511                 :          1 :         Test *test = data;
     512                 :            :         GcrSshAgentProcess *process;
     513                 :            :         GPid pid;
     514                 :            : 
     515                 :          1 :         process = gcr_ssh_agent_service_get_process (test->service);
     516                 :          1 :         pid = gcr_ssh_agent_process_get_pid (process);
     517         [ -  + ]:          1 :         g_assert_cmpint (-1, !=, pid);
     518                 :            : 
     519                 :          1 :         kill (pid, SIGTERM);
     520                 :            : 
     521                 :          1 :         return NULL;
     522                 :            : }
     523                 :            : 
     524                 :            : static void
     525                 :          1 : on_closed (GcrSshAgentProcess *self, gpointer data)
     526                 :            : {
     527                 :          1 :         GMainLoop *loop = data;
     528                 :            : 
     529                 :          1 :         g_main_loop_quit (loop);
     530                 :          1 :         g_main_loop_unref (loop);
     531                 :          1 : }
     532                 :            : 
     533                 :            : static void
     534                 :          1 : test_restart (Test *test, gconstpointer unused)
     535                 :            : {
     536                 :            :         GcrSshAgentProcess *process;
     537                 :            :         GThread *thread;
     538                 :            :         GMainLoop *loop;
     539                 :            :         GBytes *public_key;
     540                 :            :         gchar *comment;
     541                 :            : 
     542                 :          1 :         connect_to_server (test);
     543                 :            : 
     544                 :          1 :         public_key = public_key_from_file (SRCDIR "/gcr/fixtures/ssh-agent/id_rsa_plain.pub", &comment);
     545                 :          1 :         g_free (comment);
     546                 :            : 
     547                 :          1 :         call_add_identity (test);
     548                 :          1 :         call_request_identities (test, 1);
     549                 :            : 
     550         [ -  + ]:          1 :         g_assert_true (gcr_ssh_agent_service_lookup_key (test->service, public_key));
     551                 :            : 
     552                 :          1 :         thread = g_thread_new ("kill", kill_thread, test);
     553                 :            : 
     554                 :          1 :         loop = g_main_loop_new (NULL, FALSE);
     555                 :            : 
     556                 :          1 :         process = gcr_ssh_agent_service_get_process (test->service);
     557                 :          1 :         g_signal_connect (process, "closed", G_CALLBACK (on_closed), loop);
     558                 :          1 :         g_main_loop_run (loop);
     559                 :            : 
     560                 :          1 :         g_thread_join (thread);
     561                 :            : 
     562         [ -  + ]:          1 :         g_assert_false (gcr_ssh_agent_service_lookup_key (test->service, public_key));
     563                 :            : 
     564                 :          1 :         call_add_identity (test);
     565                 :          1 :         call_request_identities (test, 1);
     566                 :            : 
     567         [ -  + ]:          1 :         g_assert_true (gcr_ssh_agent_service_lookup_key (test->service, public_key));
     568                 :          1 :         g_bytes_unref (public_key);
     569                 :          1 : }
     570                 :            : 
     571                 :            : static void
     572                 :          1 : test_empty (Test *test, gconstpointer unused)
     573                 :            : {
     574                 :          1 :         connect_to_server (test);
     575                 :            : 
     576                 :          1 :         call_empty (test);
     577                 :          1 : }
     578                 :            : 
     579                 :            : static void
     580                 :          1 : test_unknown (Test *test, gconstpointer unused)
     581                 :            : {
     582                 :          1 :         connect_to_server (test);
     583                 :            : 
     584                 :          1 :         call_unknown (test);
     585                 :          1 : }
     586                 :            : 
     587                 :            : static void
     588                 :          1 : test_lock (Test *test, gconstpointer unused)
     589                 :            : {
     590                 :          1 :         connect_to_server (test);
     591                 :            : 
     592                 :          1 :         call_lock (test);
     593                 :          1 :         call_unlock (test);
     594                 :          1 : }
     595                 :            : 
     596                 :            : int
     597                 :          1 : main (int argc, char **argv)
     598                 :            : {
     599                 :          1 :         g_test_init (&argc, &argv, NULL);
     600                 :            : 
     601                 :          1 :         g_test_add ("/ssh-agent/service/startup_shutdown", Test, NULL, setup, test_startup_shutdown, teardown);
     602                 :          1 :         g_test_add ("/ssh-agent/service/list", Test, NULL, setup, test_list, teardown);
     603                 :          1 :         g_test_add ("/ssh-agent/service/add", Test, NULL, setup, test_add, teardown);
     604                 :          1 :         g_test_add ("/ssh-agent/service/remove", Test, NULL, setup, test_remove, teardown);
     605                 :          1 :         g_test_add ("/ssh-agent/service/remove_all", Test, NULL, setup, test_remove_all, teardown);
     606                 :          1 :         g_test_add ("/ssh-agent/service/sign_loaded", Test, NULL, setup, test_sign_loaded, teardown);
     607                 :          1 :         g_test_add ("/ssh-agent/service/sign", Test, NULL, setup, test_sign, teardown);
     608                 :          1 :         g_test_add ("/ssh-agent/service/sign_unknown", Test, NULL, setup, test_sign_unknown, teardown);
     609                 :          1 :         g_test_add ("/ssh-agent/service/empty", Test, NULL, setup, test_empty, teardown);
     610                 :          1 :         g_test_add ("/ssh-agent/service/unknown", Test, NULL, setup, test_unknown, teardown);
     611                 :          1 :         g_test_add ("/ssh-agent/service/unparseable_add", Test, NULL, setup, test_unparseable_add, teardown);
     612                 :          1 :         g_test_add ("/ssh-agent/service/unparseable_remove", Test, NULL, setup, test_unparseable_remove, teardown);
     613                 :          1 :         g_test_add ("/ssh-agent/service/unparseable_sign", Test, NULL, setup, test_unparseable_sign, teardown);
     614                 :          1 :         g_test_add ("/ssh-agent/service/restart", Test, NULL, setup, test_restart, teardown);
     615                 :          1 :         g_test_add ("/ssh-agent/service/lock", Test, NULL, setup, test_lock, teardown);
     616                 :            : 
     617                 :          1 :         return g_test_run ();
     618                 :            : }

Generated by: LCOV version 1.14