challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

test_challenger_db.c (3521B)


      1 /*
      2   This file is part of
      3   (C) 2023 Taler Systems SA
      4 
      5   Challenger is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Lesser General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   Challenger is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13   You should have received a copy of the GNU General Public License along with
     14   Challenger; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file sync/test_sync_db.c
     18  * @brief testcase for sync postgres db plugin
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include <gnunet/gnunet_util_lib.h>
     23 #include <taler/taler_util.h>
     24 #include "challenger_database_lib.h"
     25 #include "challenger-database/drop_tables.h"
     26 #include "challenger-database/create_tables.h"
     27 #include "challenger-database/preflight.h"
     28 #include "challenger-database/gc.h"
     29 #include "challenger_util.h"
     30 
     31 
     32 #define FAILIF(cond)                            \
     33         do {                                          \
     34           if (! (cond)) { break;}                       \
     35           GNUNET_break (0);                           \
     36           goto drop;                                     \
     37         } while (0)
     38 
     39 #define RND_BLK(ptr)                                                    \
     40         GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (* \
     41                                                                              ptr))
     42 
     43 /**
     44  * Global return value for the test.  Initially -1, set to 0 upon
     45  * completion.   Other values indicate some kind of error.
     46  */
     47 static int result;
     48 
     49 /**
     50  * Handle to the database we are testing.
     51  */
     52 static struct CHALLENGERDB_PostgresContext *pg;
     53 
     54 
     55 /**
     56  * Main function that will be run by the scheduler.
     57  *
     58  * @param cls closure with config
     59  */
     60 static void
     61 run (void *cls)
     62 {
     63   struct GNUNET_CONFIGURATION_Handle *cfg = cls;
     64 
     65   if (NULL == (pg = CHALLENGERDB_connect (cfg,
     66                                           true)))
     67   {
     68     result = 77;
     69     return;
     70   }
     71   if (GNUNET_OK !=
     72       CHALLENGERDB_drop_tables (pg))
     73   {
     74     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     75                 "Dropping tables failed\n");
     76   }
     77   if (GNUNET_OK !=
     78       CHALLENGERDB_create_tables (pg))
     79   {
     80     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     81                 "Creating tables failed\n");
     82   }
     83   GNUNET_assert (GNUNET_OK ==
     84                  CHALLENGERDB_preflight (pg));
     85   {
     86     struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get ();
     87 
     88     FAILIF (0 >
     89             CHALLENGERDB_gc (pg,
     90                              ts));
     91   }
     92   result = 0;
     93 drop:
     94   GNUNET_break (GNUNET_OK ==
     95                 CHALLENGERDB_drop_tables (pg));
     96   CHALLENGERDB_disconnect (pg);
     97   pg = NULL;
     98 }
     99 
    100 
    101 int
    102 main (int argc,
    103       char *const argv[])
    104 {
    105   struct GNUNET_CONFIGURATION_Handle *cfg;
    106 
    107   (void) argc;
    108   result = EXIT_FAILURE;
    109   GNUNET_log_setup (argv[0],
    110                     "DEBUG",
    111                     NULL);
    112   cfg = GNUNET_CONFIGURATION_create (CHALLENGER_project_data ());
    113   if (GNUNET_OK !=
    114       GNUNET_CONFIGURATION_parse (cfg,
    115                                   "test_challenger_db_postgres.conf"))
    116   {
    117     GNUNET_break (0);
    118     return EXIT_NOTCONFIGURED;
    119   }
    120   GNUNET_SCHEDULER_run (&run, cfg);
    121   GNUNET_CONFIGURATION_destroy (cfg);
    122   return result;
    123 }
    124 
    125 
    126 /* end of test_challenger_db.c */