Skip to content

Commit

Permalink
[test suite] add several fault injection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrash committed Jun 12, 2014
1 parent d8b2ae3 commit 06ce514
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/fko_client_timeout.c
Expand Up @@ -74,7 +74,7 @@ fko_set_spa_client_timeout(fko_ctx_t ctx, const int timeout)
break;
}
}
else /* Timeout is 0, which means no timeout. */
else /* Timeout is 0, which means ignore it. */
{
switch(ctx->message_type)
{
Expand Down
46 changes: 46 additions & 0 deletions lib/fko_digest.c
Expand Up @@ -79,11 +79,20 @@ fko_set_raw_spa_digest_type(fko_ctx_t ctx, const short raw_digest_type)
int
fko_get_spa_digest_type(fko_ctx_t ctx, short *digest_type)
{
#if HAVE_LIBFIU
fiu_return_on("fko_get_spa_digest_type_init",
FKO_ERROR_CTX_NOT_INITIALIZED);
#endif
/* Must be initialized
*/
if(!CTX_INITIALIZED(ctx))
return(FKO_ERROR_CTX_NOT_INITIALIZED);

#if HAVE_LIBFIU
fiu_return_on("fko_get_spa_digest_type_val",
FKO_ERROR_INVALID_DATA);
#endif

if(digest_type == NULL)
return(FKO_ERROR_INVALID_DATA);

Expand All @@ -97,6 +106,10 @@ fko_get_spa_digest_type(fko_ctx_t ctx, short *digest_type)
int
fko_get_raw_spa_digest_type(fko_ctx_t ctx, short *raw_digest_type)
{
#if HAVE_LIBFIU
fiu_return_on("fko_get_raw_spa_digest_type_init",
FKO_ERROR_CTX_NOT_INITIALIZED);
#endif
/* Must be initialized
*/
if(!CTX_INITIALIZED(ctx))
Expand All @@ -115,9 +128,19 @@ set_digest(char *data, char **digest, short digest_type, int *digest_len)

data_len = strnlen(data, MAX_SPA_ENCODED_MSG_SIZE);

#if HAVE_LIBFIU
fiu_return_on("set_digest_toobig",
FKO_ERROR_INVALID_DATA_ENCODE_DIGEST_TOOBIG);
#endif

if(data_len == MAX_SPA_ENCODED_MSG_SIZE)
return(FKO_ERROR_INVALID_DATA_ENCODE_DIGEST_TOOBIG);

#if HAVE_LIBFIU
fiu_return_on("set_digest_invalidtype", FKO_ERROR_INVALID_DIGEST_TYPE);
fiu_return_on("set_digest_calloc", FKO_ERROR_MEMORY_ALLOCATION);
#endif

switch(digest_type)
{
case FKO_DIGEST_MD5:
Expand Down Expand Up @@ -188,6 +211,9 @@ set_digest(char *data, char **digest, short digest_type, int *digest_len)
int
fko_set_spa_digest(fko_ctx_t ctx)
{
#if HAVE_LIBFIU
fiu_return_on("fko_set_spa_digest_init", FKO_ERROR_CTX_NOT_INITIALIZED);
#endif
/* Must be initialized
*/
if(!CTX_INITIALIZED(ctx))
Expand All @@ -198,13 +224,20 @@ fko_set_spa_digest(fko_ctx_t ctx)
if(ctx->encoded_msg == NULL)
return(FKO_ERROR_MISSING_ENCODED_DATA);

#if HAVE_LIBFIU
fiu_return_on("fko_set_spa_digest_encoded", FKO_ERROR_MISSING_ENCODED_DATA);
#endif

return set_digest(ctx->encoded_msg, &ctx->digest,
ctx->digest_type, &ctx->digest_len);
}

int
fko_set_raw_spa_digest(fko_ctx_t ctx)
{
#if HAVE_LIBFIU
fiu_return_on("fko_set_raw_spa_digest_init", FKO_ERROR_CTX_NOT_INITIALIZED);
#endif
/* Must be initialized
*/
if(!CTX_INITIALIZED(ctx))
Expand All @@ -215,18 +248,28 @@ fko_set_raw_spa_digest(fko_ctx_t ctx)
if(ctx->encrypted_msg == NULL)
return(FKO_ERROR_MISSING_ENCODED_DATA);

#if HAVE_LIBFIU
fiu_return_on("fko_set_raw_spa_digest_val", FKO_ERROR_MISSING_ENCODED_DATA);
#endif

return set_digest(ctx->encrypted_msg, &ctx->raw_digest,
ctx->raw_digest_type, &ctx->raw_digest_len);
}

int
fko_get_spa_digest(fko_ctx_t ctx, char **md)
{
#if HAVE_LIBFIU
fiu_return_on("fko_get_spa_digest_init", FKO_ERROR_CTX_NOT_INITIALIZED);
#endif
/* Must be initialized
*/
if(!CTX_INITIALIZED(ctx))
return(FKO_ERROR_CTX_NOT_INITIALIZED);

#if HAVE_LIBFIU
fiu_return_on("fko_get_spa_digest_val", FKO_ERROR_INVALID_DATA);
#endif
if(md == NULL)
return(FKO_ERROR_INVALID_DATA);

Expand All @@ -238,6 +281,9 @@ fko_get_spa_digest(fko_ctx_t ctx, char **md)
int
fko_get_raw_spa_digest(fko_ctx_t ctx, char **md)
{
#if HAVE_LIBFIU
fiu_return_on("fko_get_raw_spa_digest_init", FKO_ERROR_CTX_NOT_INITIALIZED);
#endif
/* Must be initialized
*/
if(!CTX_INITIALIZED(ctx))
Expand Down
4 changes: 4 additions & 0 deletions server/fw_util_iptables.c
Expand Up @@ -797,6 +797,10 @@ fw_config_init(fko_srv_options_t * const opts)
*/
strlcpy(fwc.fw_command, opts->config[CONF_FIREWALL_EXE], sizeof(fwc.fw_command));

#if HAVE_LIBFIU
fiu_return_on("fw_config_init", 0);
#endif

/* Pull the fwknop chain config info and setup our internal
* config struct. The IPT_INPUT is the only one that is
* required. The rest are optional.
Expand Down
8 changes: 4 additions & 4 deletions test/fko-wrapper/fko_wrapper.c
Expand Up @@ -220,16 +220,16 @@ test_loop_compounded(void)

fko_new(&ctx);

res = fko_set_spa_client_timeout(ctx, i);
if (res != FKO_SUCCESS)
printf("fko_set_spa_client_timeout(): %s\n", fko_errstr(res));

for (j=-1; j<FKO_LAST_MSG_TYPE+1; j++) {

res = fko_set_spa_message_type(ctx, j);
if (res != FKO_SUCCESS)
printf("fko_set_spa_message_type(): %s\n", fko_errstr(res));

res = fko_set_spa_client_timeout(ctx, i);
if (res != FKO_SUCCESS)
printf("fko_set_spa_client_timeout(): %s\n", fko_errstr(res));

res = fko_set_timestamp(ctx, 100);
if (res != FKO_SUCCESS)
printf("fko_set_timestamp(): %s\n", fko_errstr(res));
Expand Down

0 comments on commit 06ce514

Please sign in to comment.