Provide test API for keys serialization.

This commit is contained in:
Marcello Stanisci 2018-12-21 14:04:43 +01:00
parent 7d8d8b2e8a
commit df6eda3994
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F
6 changed files with 233 additions and 9 deletions

View File

@ -58,6 +58,7 @@ libtalertesting_la_SOURCES = \
testing_api_cmd_signal.c \
testing_api_cmd_check_keys.c \
testing_api_cmd_batch.c \
testing_api_cmd_serialize_keys.c \
testing_api_helpers.c \
testing_api_loop.c \
testing_api_traits.c \

View File

@ -36,14 +36,15 @@
struct CheckKeysState
{
/**
* How many times the /keys response was received by the
* exchange under test.
* This number will instruct the CMD interpreter to
* make sure that /keys was downloaded `generation` times
* _before_ running the very CMD logic.
*/
unsigned int generation;
/**
* How many denomination keys the exchange is supposed to
* have.
* How many denomination keys the exchange is
* supposed to have.
*/
unsigned int num_denom_keys;
};
@ -67,9 +68,9 @@ check_keys_run (void *cls,
"cmd `%s', key generation: %d\n",
cmd->label,
is->key_generation);
if (is->key_generation < cks->generation)
{
/* Go back to waiting for /keys signal! */
is->working = GNUNET_NO;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Triggering /keys dl, cmd `%s'\n",
@ -129,8 +130,11 @@ check_keys_cleanup (void *cls,
* @a exchange matches @a num_denom_keys.
*
* @param label command label
* @param generation how many /keys responses are expected to
* have been returned when this CMD will be run.
* @param generation when this command is run, exactly @a
* generation /keys downloads took place. If the number
* of downloads is less than @a generation, the logic will
* first make sure that @a generation downloads are done,
* and _then_ execute the rest of the command.
* @param num_denom_keys expected number of denomination keys.
* @param exchange connection handle to the exchange to test.
*

View File

@ -0,0 +1,138 @@
/*
This file is part of TALER
(C) 2018 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 3, or
(at your option) any later version.
TALER is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with TALER; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>
*/
/**
* @file exchange-lib/testing_api_cmd_serialize_keys.c
* @brief Lets tests use the keys serialization API.
* @author Marcello Stanisci
*/
#include "platform.h"
#include <jansson.h>
#include "exchange_api_handle.h"
#include "taler_testing_lib.h"
/**
* Internal state for a serialize-keys CMD.
*/
struct SerializeKeysState
{
/**
* Serialized keys.
*/
json_t *keys;
};
/**
* Run the command.
*
* @param cls closure.
* @param cmd the command to execute.
* @param is the interpreter state.
*/
static void
serialize_keys_run (void *cls,
const struct TALER_TESTING_Command *cmd,
struct TALER_TESTING_Interpreter *is)
{
struct SerializeKeysState *sks = cls;
sks->keys = TALER_EXCHANGE_serialize_data (is->exchange);
if (NULL == sks->keys)
TALER_TESTING_interpreter_fail (is);
}
/**
* Cleanup the state of a "serialize keys" CMD.
*
* @param cls closure.
* @param cmd the command which is being cleaned up.
*/
void
serialize_keys_cleanup (void *cls,
const struct TALER_TESTING_Command *cmd)
{
struct SerializeKeysState *sks = cls;
if (NULL != sks->keys)
{
json_decref (sks->keys);
}
GNUNET_free (sks);
}
/**
* Offer serialized keys as trait.
*
* @param cls closure.
* @param ret[out] result.
* @param trait name of the trait.
* @param index index number of the object to offer.
*
* @return #GNUNET_OK on success.
*/
static int
serialize_keys_traits (void *cls,
const void **ret,
const char *trait,
unsigned int index)
{
struct SerializeKeysState *sks = cls;
struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_exchange_keys (0,
sks->keys),
TALER_TESTING_trait_end ()
};
return TALER_TESTING_get_trait (traits,
ret,
trait,
index);
}
/**
* Make a serialize-keys CMD.
*
* @param label CMD label
* @return the CMD.
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_serialize_keys (const char *label)
{
struct SerializeKeysState *sks;
sks = GNUNET_new (struct SerializeKeysState);
struct TALER_TESTING_Command cmd = {
.cls = sks,
.label = label,
.run = serialize_keys_run,
.cleanup = serialize_keys_cleanup,
.traits = serialize_keys_traits
};
return cmd;
}

View File

@ -159,7 +159,7 @@ wire_cb (void *cls,
* @param cmd the command to execute.
* @param is the interpreter state.
*/
void
static void
wire_run (void *cls,
const struct TALER_TESTING_Command *cmd,
struct TALER_TESTING_Interpreter *is)
@ -179,7 +179,7 @@ wire_run (void *cls,
* @param cls closure.
* @param cmd the command which is being cleaned up.
*/
void
static void
wire_cleanup (void *cls,
const struct TALER_TESTING_Command *cmd)
{

View File

@ -30,6 +30,49 @@
#include "taler_testing_lib.h"
#define TALER_TESTING_TRAIT_WIRE_DETAILS "wire-details"
#define TALER_TESTING_TRAIT_EXCHANGE_KEYS "exchange-keys"
/**
* Obtain serialized exchange keys from @a cmd.
*
* @param cmd command to extract the keys from.
* @param index index number associate with the keys on offer.
* @param keys[out] where to write the serialized keys.
* @return #GNUNET_OK on success.
*/
int
TALER_TESTING_get_trait_exchange_keys
(const struct TALER_TESTING_Command *cmd,
unsigned int index,
const json_t **keys)
{
return cmd->traits (cmd->cls,
(const void **) keys,
TALER_TESTING_TRAIT_EXCHANGE_KEYS,
index);
}
/**
* Offer serialized keys in a trait.
*
* @param index index number associate with the serial keys
* on offer.
* @param keys serialized keys to offer.
* @return the trait.
*/
struct TALER_TESTING_Trait
TALER_TESTING_make_trait_exchange_keys
(unsigned int index,
const json_t *keys)
{
struct TALER_TESTING_Trait ret = {
.index = index,
.trait_name = TALER_TESTING_TRAIT_EXCHANGE_KEYS,
.ptr = (const json_t *) keys
};
return ret;
}
/**
* Obtain wire details from @a cmd.

View File

@ -1436,6 +1436,14 @@ TALER_TESTING_cmd_is_batch (const struct TALER_TESTING_Command *cmd);
struct TALER_TESTING_Command *
TALER_TESTING_cmd_batch_get_current (const struct TALER_TESTING_Command *cmd);
/**
* Make a serialize-keys CMD.
*
* @param label CMD label
* @return the CMD.
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_serialize_keys (const char *label);
/* *** Generic trait logic for implementing traits ********* */
@ -1914,6 +1922,36 @@ TALER_TESTING_make_trait_wire_details
(unsigned int index,
const json_t *wire_details);
/**
* Obtain serialized exchange keys from @a cmd.
*
* @param cmd command to extract the keys from.
* @param index index number associate with the keys on offer.
* @param keys[out] where to write the serialized keys.
* @return #GNUNET_OK on success.
*/
int
TALER_TESTING_get_trait_exchange_keys
(const struct TALER_TESTING_Command *cmd,
unsigned int index,
const json_t **keys);
/**
* Offer serialized keys in a trait.
*
* @param index index number associate with the serial keys
* on offer.
* @param keys serialized keys to offer.
* @return the trait.
*/
struct TALER_TESTING_Trait
TALER_TESTING_make_trait_exchange_keys
(unsigned int index,
const json_t *keys);
/**
* Obtain a private key from a "peer". Used e.g. to obtain
* a merchant's priv to sign a /track request.