test_hsm_key.c
Go to the documentation of this file.
/*
* Copyright (c) 2014 Jerry Lundström <lundstrom.jerry@gmail.com>
* Copyright (c) 2014 .SE (The Internet Infrastructure Foundation).
* Copyright (c) 2014 OpenDNSSEC AB (svb)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "CUnit/Basic.h"
#include "../db_configuration.h"
#include "../db_connection.h"
#include "../hsm_key.h"
#include <string.h>
static db_configuration_list_t* configuration_list = NULL;
static db_configuration_t* configuration = NULL;
static db_connection_t* connection = NULL;
static hsm_key_t* object = NULL;
static hsm_key_list_t* object_list = NULL;
static db_value_t id = DB_VALUE_EMPTY;
static db_clause_list_t* clause_list = NULL;
static int db_sqlite = 0;
static int db_mysql = 0;
#if defined(ENFORCER_DATABASE_SQLITE3)
int test_hsm_key_init_suite_sqlite(void) {
if (configuration_list) {
return 1;
}
if (configuration) {
return 1;
}
if (connection) {
return 1;
}
/*
* Setup the configuration for the connection
*/
if (!(configuration_list = db_configuration_list_new())) {
return 1;
}
if (!(configuration = db_configuration_new())
|| db_configuration_set_name(configuration, "backend")
|| db_configuration_set_value(configuration, "sqlite")
|| db_configuration_list_add(configuration_list, configuration))
{
db_configuration_free(configuration);
configuration = NULL;
db_configuration_list_free(configuration_list);
configuration_list = NULL;
return 1;
}
configuration = NULL;
if (!(configuration = db_configuration_new())
|| db_configuration_set_name(configuration, "file")
|| db_configuration_set_value(configuration, "test.db")
|| db_configuration_list_add(configuration_list, configuration))
{
db_configuration_free(configuration);
configuration = NULL;
db_configuration_list_free(configuration_list);
configuration_list = NULL;
return 1;
}
configuration = NULL;
/*
* Connect to the database
*/
if (!(connection = db_connection_new())
|| db_connection_set_configuration_list(connection, configuration_list))
{
db_connection_free(connection);
connection = NULL;
db_configuration_list_free(configuration_list);
configuration_list = NULL;
return 1;
}
configuration_list = NULL;
if (db_connection_setup(connection)
|| db_connection_connect(connection))
{
db_connection_free(connection);
connection = NULL;
return 1;
}
db_sqlite = 1;
db_mysql = 0;
return 0;
}
#endif
#if defined(ENFORCER_DATABASE_MYSQL)
int test_hsm_key_init_suite_mysql(void) {
if (configuration_list) {
return 1;
}
if (configuration) {
return 1;
}
if (connection) {
return 1;
}
/*
* Setup the configuration for the connection
*/
if (!(configuration_list = db_configuration_list_new())) {
return 1;
}
if (!(configuration = db_configuration_new())
|| db_configuration_set_name(configuration, "backend")
|| db_configuration_set_value(configuration, "mysql")
|| db_configuration_list_add(configuration_list, configuration))
{
db_configuration_free(configuration);
configuration = NULL;
db_configuration_list_free(configuration_list);
configuration_list = NULL;
return 1;
}
configuration = NULL;
if (!(configuration = db_configuration_new())
|| db_configuration_set_name(configuration, "host")
|| db_configuration_set_value(configuration, ENFORCER_DB_HOST)
|| db_configuration_list_add(configuration_list, configuration))
{
db_configuration_free(configuration);
configuration = NULL;
db_configuration_list_free(configuration_list);
configuration_list = NULL;
return 1;
}
configuration = NULL;
if (!(configuration = db_configuration_new())
|| db_configuration_set_name(configuration, "port")
|| db_configuration_set_value(configuration, ENFORCER_DB_PORT_TEXT)
|| db_configuration_list_add(configuration_list, configuration))
{
db_configuration_free(configuration);
configuration = NULL;
db_configuration_list_free(configuration_list);
configuration_list = NULL;
return 1;
}
configuration = NULL;
if (!(configuration = db_configuration_new())
|| db_configuration_set_name(configuration, "user")
|| db_configuration_set_value(configuration, ENFORCER_DB_USERNAME)
|| db_configuration_list_add(configuration_list, configuration))
{
db_configuration_free(configuration);
configuration = NULL;
db_configuration_list_free(configuration_list);
configuration_list = NULL;
return 1;
}
configuration = NULL;
if (!(configuration = db_configuration_new())
|| db_configuration_set_name(configuration, "pass")
|| db_configuration_set_value(configuration, ENFORCER_DB_PASSWORD)
|| db_configuration_list_add(configuration_list, configuration))
{
db_configuration_free(configuration);
configuration = NULL;
db_configuration_list_free(configuration_list);
configuration_list = NULL;
return 1;
}
configuration = NULL;
if (!(configuration = db_configuration_new())
|| db_configuration_set_name(configuration, "db")
|| db_configuration_set_value(configuration, ENFORCER_DB_DATABASE)
|| db_configuration_list_add(configuration_list, configuration))
{
db_configuration_free(configuration);
configuration = NULL;
db_configuration_list_free(configuration_list);
configuration_list = NULL;
return 1;
}
configuration = NULL;
/*
* Connect to the database
*/
if (!(connection = db_connection_new())
|| db_connection_set_configuration_list(connection, configuration_list))
{
db_connection_free(connection);
connection = NULL;
db_configuration_list_free(configuration_list);
configuration_list = NULL;
return 1;
}
configuration_list = NULL;
if (db_connection_setup(connection)
|| db_connection_connect(connection))
{
db_connection_free(connection);
connection = NULL;
return 1;
}
db_sqlite = 0;
db_mysql = 1;
return 0;
}
#endif
static int test_hsm_key_clean_suite(void) {
db_connection_free(connection);
connection = NULL;
db_configuration_free(configuration);
configuration = NULL;
db_configuration_list_free(configuration_list);
configuration_list = NULL;
db_value_reset(&id);
db_clause_list_free(clause_list);
clause_list = NULL;
return 0;
}
static void test_hsm_key_new(void) {
CU_ASSERT_PTR_NOT_NULL_FATAL((object = hsm_key_new(connection)));
CU_ASSERT_PTR_NOT_NULL_FATAL((object_list = hsm_key_list_new(connection)));
}
static void test_hsm_key_set(void) {
db_value_t policy_id = DB_VALUE_EMPTY;
if (db_sqlite) {
CU_ASSERT(!db_value_from_int32(&policy_id, 1));
}
if (db_mysql) {
CU_ASSERT(!db_value_from_uint64(&policy_id, 1));
}
CU_ASSERT(!hsm_key_set_policy_id(object, &policy_id));
CU_ASSERT(!hsm_key_set_locator(object, "locator 1"));
CU_ASSERT(!hsm_key_set_state(object, HSM_KEY_STATE_UNUSED));
CU_ASSERT(!hsm_key_set_state(object, HSM_KEY_STATE_PRIVATE));
CU_ASSERT(!hsm_key_set_state(object, HSM_KEY_STATE_SHARED));
CU_ASSERT(!hsm_key_set_state(object, HSM_KEY_STATE_DELETE));
CU_ASSERT(!hsm_key_set_bits(object, 1));
CU_ASSERT(!hsm_key_set_algorithm(object, 1));
CU_ASSERT(!hsm_key_set_role(object, HSM_KEY_ROLE_KSK));
CU_ASSERT(!hsm_key_set_role(object, HSM_KEY_ROLE_ZSK));
CU_ASSERT(!hsm_key_set_role(object, HSM_KEY_ROLE_CSK));
CU_ASSERT(!hsm_key_set_inception(object, 1));
CU_ASSERT(!hsm_key_set_key_type(object, HSM_KEY_KEY_TYPE_RSA));
CU_ASSERT(!hsm_key_set_repository(object, "repository 1"));
CU_ASSERT(!hsm_key_set_backup(object, HSM_KEY_BACKUP_NO_BACKUP));
CU_ASSERT(!hsm_key_set_backup(object, HSM_KEY_BACKUP_BACKUP_REQUIRED));
CU_ASSERT(!hsm_key_set_backup(object, HSM_KEY_BACKUP_BACKUP_REQUESTED));
CU_ASSERT(!hsm_key_set_backup(object, HSM_KEY_BACKUP_BACKUP_DONE));
db_value_reset(&policy_id);
}
static void test_hsm_key_get(void) {
int ret;
db_value_t policy_id = DB_VALUE_EMPTY;
if (db_sqlite) {
CU_ASSERT(!db_value_from_int32(&policy_id, 1));
}
if (db_mysql) {
CU_ASSERT(!db_value_from_uint64(&policy_id, 1));
}
CU_ASSERT(!db_value_cmp(hsm_key_policy_id(object), &policy_id, &ret));
CU_ASSERT(!ret);
CU_ASSERT_PTR_NOT_NULL_FATAL(hsm_key_locator(object));
CU_ASSERT(!strcmp(hsm_key_locator(object), "locator 1"));
CU_ASSERT(hsm_key_state(object) == HSM_KEY_STATE_DELETE);
CU_ASSERT(hsm_key_bits(object) == 1);
CU_ASSERT(hsm_key_algorithm(object) == 1);
CU_ASSERT(hsm_key_role(object) == HSM_KEY_ROLE_CSK);
CU_ASSERT(hsm_key_inception(object) == 1);
CU_ASSERT_PTR_NOT_NULL_FATAL(hsm_key_repository(object));
CU_ASSERT(!strcmp(hsm_key_repository(object), "repository 1"));
CU_ASSERT(hsm_key_backup(object) == HSM_KEY_BACKUP_BACKUP_DONE);
db_value_reset(&policy_id);
}
static void test_hsm_key_create(void) {
CU_ASSERT_FATAL(!hsm_key_create(object));
}
static void test_hsm_key_clauses(void) {
hsm_key_list_t* new_list;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT_PTR_NOT_NULL(hsm_key_policy_id_clause(clause_list, hsm_key_policy_id(object)));
CU_ASSERT(!hsm_key_list_get_by_clauses(object_list, clause_list));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(object_list));
CU_ASSERT_PTR_NOT_NULL((new_list = hsm_key_list_new_get_by_clauses(connection, clause_list)));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(new_list));
hsm_key_list_free(new_list);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT(!hsm_key_list_get_by_clauses(object_list, clause_list));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(object_list));
CU_ASSERT_PTR_NOT_NULL((new_list = hsm_key_list_new_get_by_clauses(connection, clause_list)));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(new_list));
hsm_key_list_free(new_list);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT_PTR_NOT_NULL(hsm_key_state_clause(clause_list, hsm_key_state(object)));
CU_ASSERT(!hsm_key_list_get_by_clauses(object_list, clause_list));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(object_list));
CU_ASSERT_PTR_NOT_NULL((new_list = hsm_key_list_new_get_by_clauses(connection, clause_list)));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(new_list));
hsm_key_list_free(new_list);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT_PTR_NOT_NULL(hsm_key_bits_clause(clause_list, hsm_key_bits(object)));
CU_ASSERT(!hsm_key_list_get_by_clauses(object_list, clause_list));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(object_list));
CU_ASSERT_PTR_NOT_NULL((new_list = hsm_key_list_new_get_by_clauses(connection, clause_list)));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(new_list));
hsm_key_list_free(new_list);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT_PTR_NOT_NULL(hsm_key_algorithm_clause(clause_list, hsm_key_algorithm(object)));
CU_ASSERT(!hsm_key_list_get_by_clauses(object_list, clause_list));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(object_list));
CU_ASSERT_PTR_NOT_NULL((new_list = hsm_key_list_new_get_by_clauses(connection, clause_list)));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(new_list));
hsm_key_list_free(new_list);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT_PTR_NOT_NULL(hsm_key_role_clause(clause_list, hsm_key_role(object)));
CU_ASSERT(!hsm_key_list_get_by_clauses(object_list, clause_list));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(object_list));
CU_ASSERT_PTR_NOT_NULL((new_list = hsm_key_list_new_get_by_clauses(connection, clause_list)));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(new_list));
hsm_key_list_free(new_list);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT(!hsm_key_list_get_by_clauses(object_list, clause_list));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(object_list));
CU_ASSERT_PTR_NOT_NULL((new_list = hsm_key_list_new_get_by_clauses(connection, clause_list)));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(new_list));
hsm_key_list_free(new_list);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT(!hsm_key_list_get_by_clauses(object_list, clause_list));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(object_list));
CU_ASSERT_PTR_NOT_NULL((new_list = hsm_key_list_new_get_by_clauses(connection, clause_list)));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(new_list));
hsm_key_list_free(new_list);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT(!hsm_key_list_get_by_clauses(object_list, clause_list));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(object_list));
CU_ASSERT_PTR_NOT_NULL((new_list = hsm_key_list_new_get_by_clauses(connection, clause_list)));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(new_list));
hsm_key_list_free(new_list);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT_PTR_NOT_NULL(hsm_key_repository_clause(clause_list, hsm_key_repository(object)));
CU_ASSERT(!hsm_key_list_get_by_clauses(object_list, clause_list));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(object_list));
CU_ASSERT_PTR_NOT_NULL((new_list = hsm_key_list_new_get_by_clauses(connection, clause_list)));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(new_list));
hsm_key_list_free(new_list);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT_PTR_NOT_NULL(hsm_key_backup_clause(clause_list, hsm_key_backup(object)));
CU_ASSERT(!hsm_key_list_get_by_clauses(object_list, clause_list));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(object_list));
CU_ASSERT_PTR_NOT_NULL((new_list = hsm_key_list_new_get_by_clauses(connection, clause_list)));
CU_ASSERT_PTR_NOT_NULL(hsm_key_list_next(new_list));
hsm_key_list_free(new_list);
db_clause_list_free(clause_list);
clause_list = NULL;
}
static void test_hsm_key_count(void) {
size_t count;
CU_ASSERT(!hsm_key_count(object, NULL, &count));
CU_ASSERT(count == 1);
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT_PTR_NOT_NULL(hsm_key_policy_id_clause(clause_list, hsm_key_policy_id(object)));
CU_ASSERT(!hsm_key_count(object, clause_list, &count));
CU_ASSERT(count == 1);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT(!hsm_key_count(object, clause_list, &count));
CU_ASSERT(count == 1);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT_PTR_NOT_NULL(hsm_key_state_clause(clause_list, hsm_key_state(object)));
CU_ASSERT(!hsm_key_count(object, clause_list, &count));
CU_ASSERT(count == 1);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT_PTR_NOT_NULL(hsm_key_bits_clause(clause_list, hsm_key_bits(object)));
CU_ASSERT(!hsm_key_count(object, clause_list, &count));
CU_ASSERT(count == 1);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT_PTR_NOT_NULL(hsm_key_algorithm_clause(clause_list, hsm_key_algorithm(object)));
CU_ASSERT(!hsm_key_count(object, clause_list, &count));
CU_ASSERT(count == 1);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT_PTR_NOT_NULL(hsm_key_role_clause(clause_list, hsm_key_role(object)));
CU_ASSERT(!hsm_key_count(object, clause_list, &count));
CU_ASSERT(count == 1);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT(!hsm_key_count(object, clause_list, &count));
CU_ASSERT(count == 1);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT(!hsm_key_count(object, clause_list, &count));
CU_ASSERT(count == 1);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT(!hsm_key_count(object, clause_list, &count));
CU_ASSERT(count == 1);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT_PTR_NOT_NULL(hsm_key_repository_clause(clause_list, hsm_key_repository(object)));
CU_ASSERT(!hsm_key_count(object, clause_list, &count));
CU_ASSERT(count == 1);
db_clause_list_free(clause_list);
clause_list = NULL;
CU_ASSERT_PTR_NOT_NULL_FATAL((clause_list = db_clause_list_new()));
CU_ASSERT_PTR_NOT_NULL(hsm_key_backup_clause(clause_list, hsm_key_backup(object)));
CU_ASSERT(!hsm_key_count(object, clause_list, &count));
CU_ASSERT(count == 1);
db_clause_list_free(clause_list);
clause_list = NULL;
}
static void test_hsm_key_verify(void) {
int ret;
db_value_t policy_id = DB_VALUE_EMPTY;
if (db_sqlite) {
CU_ASSERT(!db_value_from_int32(&policy_id, 1));
}
if (db_mysql) {
CU_ASSERT(!db_value_from_uint64(&policy_id, 1));
}
CU_ASSERT(!db_value_cmp(hsm_key_policy_id(object), &policy_id, &ret));
CU_ASSERT(!ret);
CU_ASSERT_PTR_NOT_NULL_FATAL(hsm_key_locator(object));
CU_ASSERT(!strcmp(hsm_key_locator(object), "locator 1"));
CU_ASSERT(hsm_key_state(object) == HSM_KEY_STATE_DELETE);
CU_ASSERT(hsm_key_bits(object) == 1);
CU_ASSERT(hsm_key_algorithm(object) == 1);
CU_ASSERT(hsm_key_role(object) == HSM_KEY_ROLE_CSK);
CU_ASSERT(hsm_key_inception(object) == 1);
CU_ASSERT_PTR_NOT_NULL_FATAL(hsm_key_repository(object));
CU_ASSERT(!strcmp(hsm_key_repository(object), "repository 1"));
CU_ASSERT(hsm_key_backup(object) == HSM_KEY_BACKUP_BACKUP_DONE);
db_value_reset(&policy_id);
}
static void test_hsm_key_read_by_locator(void) {
CU_ASSERT_FATAL(!hsm_key_get_by_locator(object, "locator 1"));
}
static void test_hsm_key_verify_locator(void) {
int ret;
db_value_t policy_id = DB_VALUE_EMPTY;
if (db_sqlite) {
CU_ASSERT(!db_value_from_int32(&policy_id, 1));
}
if (db_mysql) {
CU_ASSERT(!db_value_from_uint64(&policy_id, 1));
}
CU_ASSERT(!db_value_cmp(hsm_key_policy_id(object), &policy_id, &ret));
CU_ASSERT(!ret);
CU_ASSERT_PTR_NOT_NULL_FATAL(hsm_key_locator(object));
CU_ASSERT(!strcmp(hsm_key_locator(object), "locator 1"));
CU_ASSERT(hsm_key_state(object) == HSM_KEY_STATE_DELETE);
CU_ASSERT(hsm_key_bits(object) == 1);
CU_ASSERT(hsm_key_algorithm(object) == 1);
CU_ASSERT(hsm_key_role(object) == HSM_KEY_ROLE_CSK);
CU_ASSERT(hsm_key_inception(object) == 1);
CU_ASSERT_PTR_NOT_NULL_FATAL(hsm_key_repository(object));
CU_ASSERT(!strcmp(hsm_key_repository(object), "repository 1"));
CU_ASSERT(hsm_key_backup(object) == HSM_KEY_BACKUP_BACKUP_DONE);
db_value_reset(&policy_id);
}
static void test_hsm_key_change(void) {
db_value_t policy_id = DB_VALUE_EMPTY;
if (db_sqlite) {
CU_ASSERT(!db_value_from_int32(&policy_id, 1));
}
if (db_mysql) {
CU_ASSERT(!db_value_from_uint64(&policy_id, 1));
}
CU_ASSERT(!hsm_key_set_policy_id(object, &policy_id));
CU_ASSERT(!hsm_key_set_locator(object, "locator 2"));
CU_ASSERT(!hsm_key_set_state(object, HSM_KEY_STATE_UNUSED));
CU_ASSERT(!hsm_key_set_bits(object, 2));
CU_ASSERT(!hsm_key_set_algorithm(object, 2));
CU_ASSERT(!hsm_key_set_role(object, HSM_KEY_ROLE_KSK));
CU_ASSERT(!hsm_key_set_inception(object, 2));
CU_ASSERT(!hsm_key_set_key_type(object, HSM_KEY_KEY_TYPE_RSA));
CU_ASSERT(!hsm_key_set_repository(object, "repository 2"));
CU_ASSERT(!hsm_key_set_backup(object, HSM_KEY_BACKUP_NO_BACKUP));
db_value_reset(&policy_id);
}
static void test_hsm_key_update(void) {
CU_ASSERT_FATAL(!hsm_key_update(object));
}
static void test_hsm_key_verify2(void) {
int ret;
db_value_t policy_id = DB_VALUE_EMPTY;
if (db_sqlite) {
CU_ASSERT(!db_value_from_int32(&policy_id, 1));
}
if (db_mysql) {
CU_ASSERT(!db_value_from_uint64(&policy_id, 1));
}
CU_ASSERT(!db_value_cmp(hsm_key_policy_id(object), &policy_id, &ret));
CU_ASSERT(!ret);
CU_ASSERT_PTR_NOT_NULL_FATAL(hsm_key_locator(object));
CU_ASSERT(!strcmp(hsm_key_locator(object), "locator 2"));
CU_ASSERT(hsm_key_state(object) == HSM_KEY_STATE_UNUSED);
CU_ASSERT(hsm_key_bits(object) == 2);
CU_ASSERT(hsm_key_algorithm(object) == 2);
CU_ASSERT(hsm_key_role(object) == HSM_KEY_ROLE_KSK);
CU_ASSERT(hsm_key_inception(object) == 2);
CU_ASSERT_PTR_NOT_NULL_FATAL(hsm_key_repository(object));
CU_ASSERT(!strcmp(hsm_key_repository(object), "repository 2"));
CU_ASSERT(hsm_key_backup(object) == HSM_KEY_BACKUP_NO_BACKUP);
db_value_reset(&policy_id);
}
static void test_hsm_key_cmp(void) {
hsm_key_t* local_object;
CU_ASSERT_PTR_NOT_NULL_FATAL((local_object = hsm_key_new(connection)));
}
static void test_hsm_key_read_by_locator2(void) {
CU_ASSERT_FATAL(!hsm_key_get_by_locator(object, "locator 2"));
}
static void test_hsm_key_verify_locator2(void) {
int ret;
db_value_t policy_id = DB_VALUE_EMPTY;
if (db_sqlite) {
CU_ASSERT(!db_value_from_int32(&policy_id, 1));
}
if (db_mysql) {
CU_ASSERT(!db_value_from_uint64(&policy_id, 1));
}
CU_ASSERT(!db_value_cmp(hsm_key_policy_id(object), &policy_id, &ret));
CU_ASSERT(!ret);
CU_ASSERT_PTR_NOT_NULL_FATAL(hsm_key_locator(object));
CU_ASSERT(!strcmp(hsm_key_locator(object), "locator 2"));
CU_ASSERT(hsm_key_state(object) == HSM_KEY_STATE_UNUSED);
CU_ASSERT(hsm_key_bits(object) == 2);
CU_ASSERT(hsm_key_algorithm(object) == 2);
CU_ASSERT(hsm_key_role(object) == HSM_KEY_ROLE_KSK);
CU_ASSERT(hsm_key_inception(object) == 2);
CU_ASSERT_PTR_NOT_NULL_FATAL(hsm_key_repository(object));
CU_ASSERT(!strcmp(hsm_key_repository(object), "repository 2"));
CU_ASSERT(hsm_key_backup(object) == HSM_KEY_BACKUP_NO_BACKUP);
db_value_reset(&policy_id);
}
static void test_hsm_key_delete(void) {
}
static void test_hsm_key_list2(void) {
CU_ASSERT_PTR_NULL(hsm_key_list_next(object_list));
}
static void test_hsm_key_end(void) {
if (object) {
hsm_key_free(object);
CU_PASS("hsm_key_free");
}
if (object_list) {
hsm_key_list_free(object_list);
CU_PASS("hsm_key_list_free");
}
}
static int test_hsm_key_add_tests(CU_pSuite pSuite) {
if (!CU_add_test(pSuite, "new object", test_hsm_key_new)
|| !CU_add_test(pSuite, "set fields", test_hsm_key_set)
|| !CU_add_test(pSuite, "get fields", test_hsm_key_get)
|| !CU_add_test(pSuite, "create object", test_hsm_key_create)
|| !CU_add_test(pSuite, "object clauses", test_hsm_key_clauses)
|| !CU_add_test(pSuite, "object count", test_hsm_key_count)
|| !CU_add_test(pSuite, "verify fields", test_hsm_key_verify)
|| !CU_add_test(pSuite, "read object by locator", test_hsm_key_read_by_locator)
|| !CU_add_test(pSuite, "verify fields (locator)", test_hsm_key_verify_locator)
|| !CU_add_test(pSuite, "change object", test_hsm_key_change)
|| !CU_add_test(pSuite, "update object", test_hsm_key_update)
|| !CU_add_test(pSuite, "verify fields after update", test_hsm_key_verify2)
|| !CU_add_test(pSuite, "compare objects", test_hsm_key_cmp)
|| !CU_add_test(pSuite, "reread object by locator", test_hsm_key_read_by_locator2)
|| !CU_add_test(pSuite, "verify fields after update (locator)", test_hsm_key_verify_locator2)
|| !CU_add_test(pSuite, "delete object", test_hsm_key_delete)
|| !CU_add_test(pSuite, "list objects to verify delete", test_hsm_key_list2)
|| !CU_add_test(pSuite, "end test", test_hsm_key_end))
{
return CU_get_error();
}
return 0;
}
int test_hsm_key_add_suite(void) {
CU_pSuite pSuite = NULL;
int ret;
#if defined(ENFORCER_DATABASE_SQLITE3)
pSuite = CU_add_suite("Test of hsm key (SQLite)", test_hsm_key_init_suite_sqlite, test_hsm_key_clean_suite);
if (!pSuite) {
return CU_get_error();
}
ret = test_hsm_key_add_tests(pSuite);
if (ret) {
return ret;
}
#endif
#if defined(ENFORCER_DATABASE_MYSQL)
pSuite = CU_add_suite("Test of hsm key (MySQL)", test_hsm_key_init_suite_mysql, test_hsm_key_clean_suite);
if (!pSuite) {
return CU_get_error();
}
ret = test_hsm_key_add_tests(pSuite);
if (ret) {
return ret;
}
#endif
return 0;
}
db_configuration_list
Definition: db_configuration.h:93
hsm_key_set_locator
int hsm_key_set_locator(hsm_key_t *hsm_key, const char *locator_text)
Definition: hsm_key.c:603
hsm_key_set_role
int hsm_key_set_role(hsm_key_t *hsm_key, hsm_key_role_t role)
Definition: hsm_key.c:658
hsm_key_list_get_by_clauses
int hsm_key_list_get_by_clauses(hsm_key_list_t *hsm_key_list, const db_clause_list_t *clause_list)
Definition: hsm_key.c:1684
db_connection_setup
int db_connection_setup(db_connection_t *connection)
Definition: db_connection.c:66
db_configuration_new
db_configuration_t * db_configuration_new(void)
Definition: db_configuration.c:41
db_clause_list_new
db_clause_list_t * db_clause_list_new(void)
Definition: db_clause.c:202
hsm_key_set_key_type
int hsm_key_set_key_type(hsm_key_t *hsm_key, hsm_key_key_type_t key_type)
Definition: hsm_key.c:681
db_value_from_uint64
int db_value_from_uint64(db_value_t *value, db_type_uint64_t from_uint64)
Definition: db_value.c:518
DB_VALUE_EMPTY
#define DB_VALUE_EMPTY
Definition: db_value.h:60
db_configuration
Definition: db_configuration.h:41
db_clause_list
Definition: db_clause.h:226
hsm_key_policy_id
const db_value_t * hsm_key_policy_id(const hsm_key_t *hsm_key)
Definition: hsm_key.c:512
hsm_key_set_policy_id
int hsm_key_set_policy_id(hsm_key_t *hsm_key, const db_value_t *policy_id)
Definition: hsm_key.c:584
db_configuration_set_name
int db_configuration_set_name(db_configuration_t *configuration, const char *name)
Definition: db_configuration.c:68
hsm_key_set_bits
int hsm_key_set_bits(hsm_key_t *hsm_key, unsigned int bits)
Definition: hsm_key.c:638
hsm_key_set_repository
int hsm_key_set_repository(hsm_key_t *hsm_key, const char *repository_text)
Definition: hsm_key.c:694
hsm_key_set_inception
int hsm_key_set_inception(hsm_key_t *hsm_key, unsigned int inception)
Definition: hsm_key.c:671
hsm_key_set_algorithm
int hsm_key_set_algorithm(hsm_key_t *hsm_key, unsigned int algorithm)
Definition: hsm_key.c:648
HSM_KEY_STATE_PRIVATE
Definition: hsm_key.h:43
hsm_key_list_next
const hsm_key_t * hsm_key_list_next(hsm_key_list_t *hsm_key_list)
Definition: hsm_key.c:1924
hsm_key_set_backup
int hsm_key_set_backup(hsm_key_t *hsm_key, hsm_key_backup_t backup)
Definition: hsm_key.c:716
HSM_KEY_KEY_TYPE_RSA
Definition: hsm_key.h:59
db_value
Definition: db_value.h:48
hsm_key_repository
const char * hsm_key_repository(const hsm_key_t *hsm_key)
Definition: hsm_key.c:568
hsm_key
Definition: hsm_key.h:77
HSM_KEY_STATE_UNUSED
Definition: hsm_key.h:42
hsm_key_state
hsm_key_state
Definition: hsm_key.h:40
db_clause_list_free
void db_clause_list_free(db_clause_list_t *clause_list)
Definition: db_clause.c:209
hsm_key_backup_clause
db_clause_t * hsm_key_backup_clause(db_clause_list_t *clause_list, hsm_key_backup_t backup)
Definition: hsm_key.c:906
db_configuration_list_add
int db_configuration_list_add(db_configuration_list_t *configuration_list, db_configuration_t *configuration)
Definition: db_configuration.c:150
hsm_key_update
int hsm_key_update(hsm_key_t *hsm_key)
Definition: hsm_key.c:1225
hsm_key_get_by_locator
int hsm_key_get_by_locator(hsm_key_t *hsm_key, const char *locator)
Definition: hsm_key.c:1155
db_value_cmp
int db_value_cmp(const db_value_t *value_a, const db_value_t *value_b, int *result)
Definition: db_value.c:102
db_configuration_free
void db_configuration_free(db_configuration_t *configuration)
Definition: db_configuration.c:48
hsm_key_count
int hsm_key_count(hsm_key_t *hsm_key, db_clause_list_t *clause_list, size_t *count)
Definition: hsm_key.c:1435
hsm_key_inception
unsigned int hsm_key_inception(const hsm_key_t *hsm_key)
Definition: hsm_key.c:560
db_value_reset
void db_value_reset(db_value_t *value)
Definition: db_value.c:60
hsm_key_list
Definition: hsm_key.h:434
HSM_KEY_ROLE_CSK
Definition: hsm_key.h:53
hsm_key_locator
const char * hsm_key_locator(const hsm_key_t *hsm_key)
Definition: hsm_key.c:520
HSM_KEY_BACKUP_BACKUP_REQUIRED
Definition: hsm_key.h:65
HSM_KEY_ROLE_KSK
Definition: hsm_key.h:51
hsm_key_policy_id_clause
db_clause_t * hsm_key_policy_id_clause(db_clause_list_t *clause_list, const db_value_t *policy_id)
Definition: hsm_key.c:729
hsm_key_repository_clause
db_clause_t * hsm_key_repository_clause(db_clause_list_t *clause_list, const char *repository_text)
Definition: hsm_key.c:882
test_hsm_key_add_suite
int test_hsm_key_add_suite(void)
Definition: test_hsm_key.c:685
hsm_key_create
int hsm_key_create(hsm_key_t *hsm_key)
Definition: hsm_key.c:927
db_configuration_list_new
db_configuration_list_t * db_configuration_list_new(void)
Definition: db_configuration.c:127
HSM_KEY_ROLE_ZSK
Definition: hsm_key.h:52
HSM_KEY_BACKUP_BACKUP_REQUESTED
Definition: hsm_key.h:66
hsm_key_role
hsm_key_role
Definition: hsm_key.h:49
hsm_key_algorithm
unsigned int hsm_key_algorithm(const hsm_key_t *hsm_key)
Definition: hsm_key.c:544
db_connection_set_configuration_list
int db_connection_set_configuration_list(db_connection_t *connection, const db_configuration_list_t *configuration_list)
Definition: db_connection.c:54
HSM_KEY_BACKUP_BACKUP_DONE
Definition: hsm_key.h:67
hsm_key_list_new
hsm_key_list_t * hsm_key_list_new(const db_connection_t *connection)
Definition: hsm_key.c:1453
hsm_key_backup
hsm_key_backup
Definition: hsm_key.h:62
hsm_key_free
void hsm_key_free(hsm_key_t *hsm_key)
Definition: hsm_key.c:286
db_value_from_int32
int db_value_from_int32(db_value_t *value, db_type_int32_t from_int32)
Definition: db_value.c:479
db_connection_free
void db_connection_free(db_connection_t *connection)
Definition: db_connection.c:45
hsm_key_list_new_get_by_clauses
hsm_key_list_t * hsm_key_list_new_get_by_clauses(const db_connection_t *connection, const db_clause_list_t *clause_list)
Definition: hsm_key.c:1726
HSM_KEY_BACKUP_NO_BACKUP
Definition: hsm_key.h:64
db_connection
Definition: db_connection.h:46
hsm_key_set_state
int hsm_key_set_state(hsm_key_t *hsm_key, hsm_key_state_t state)
Definition: hsm_key.c:625
hsm_key_algorithm_clause
db_clause_t * hsm_key_algorithm_clause(db_clause_list_t *clause_list, unsigned int algorithm)
Definition: hsm_key.c:798
db_configuration_set_value
int db_configuration_set_value(db_configuration_t *configuration, const char *value)
Definition: db_configuration.c:89
hsm_key_bits_clause
db_clause_t * hsm_key_bits_clause(db_clause_list_t *clause_list, unsigned int bits)
Definition: hsm_key.c:777
hsm_key_list_free
void hsm_key_list_free(hsm_key_list_t *hsm_key_list)
Definition: hsm_key.c:1496
hsm_key_bits
unsigned int hsm_key_bits(const hsm_key_t *hsm_key)
Definition: hsm_key.c:536
policy_id
const db_value_t * policy_id(const policy_t *policy)
Definition: policy.c:805
HSM_KEY_STATE_SHARED
Definition: hsm_key.h:44
db_connection_connect
int db_connection_connect(const db_connection_t *connection)
Definition: db_connection.c:88
HSM_KEY_STATE_DELETE
Definition: hsm_key.h:45
db_connection_new
db_connection_t * db_connection_new(void)
Definition: db_connection.c:38
hsm_key_role_clause
db_clause_t * hsm_key_role_clause(db_clause_list_t *clause_list, hsm_key_role_t role)
Definition: hsm_key.c:819
hsm_key_new
hsm_key_t * hsm_key_new(const db_connection_t *connection)
Definition: hsm_key.c:244
hsm_key_state_clause
db_clause_t * hsm_key_state_clause(db_clause_list_t *clause_list, hsm_key_state_t state)
Definition: hsm_key.c:756
db_configuration_list_free
void db_configuration_list_free(db_configuration_list_t *configuration_list)
Definition: db_configuration.c:134