pr_val_debug("AIA's URI didn't matched parent URI, trying to SYNC");
+ /* TODO (#78) RFC misunderstanding; do not rsync here. */
/* RSYNC is still the preferred access mechanism, force the sync */
do {
error = rsync_download_files(caIssuers, false, true);
struct tal *tal;
int error;
+ lfile = NULL; /* Warning shutupper */
error = lfile_open(file_name, &lfile);
if (error) {
pr_op_err("Error opening file '%s': %s", file_name,
rtr_primitive_reader_test_SOURCES = rtr/primitive_reader_test.c
rtr_primitive_reader_test_LDADD = ${MY_LDADD}
-EXTRA_DIST = impersonator.c
+EXTRA_DIST = mock.c
EXTRA_DIST += line_file/core.txt
EXTRA_DIST += line_file/empty.txt
EXTRA_DIST += line_file/error.txt
-EXTRA_DIST += rtr/db/rtr_db_impersonator.c
+EXTRA_DIST += rtr/db/rtr_db_mock.c
EXTRA_DIST += tal/lacnic.tal
EXTRA_DIST += xml/notification.xml
+++ /dev/null
-#include <arpa/inet.h>
-
-#include "config.h"
-#include "incidence/incidence.h"
-
-/**
- * Some core functions, as linked from unit testing code.
- */
-
-static char addr_buffer1[INET6_ADDRSTRLEN];
-static char addr_buffer2[INET6_ADDRSTRLEN];
-
-static unsigned int http_priority = 60;
-static unsigned int rsync_priority = 50;
-
-char const *
-v4addr2str(struct in_addr const *addr)
-{
- return inet_ntop(AF_INET, addr, addr_buffer1, sizeof(addr_buffer1));
-}
-
-char const *
-v4addr2str2(struct in_addr const *addr)
-{
- return inet_ntop(AF_INET, addr, addr_buffer2, sizeof(addr_buffer2));
-}
-
-char const *
-v6addr2str(struct in6_addr const *addr)
-{
- return inet_ntop(AF_INET6, addr, addr_buffer1, sizeof(addr_buffer1));
-}
-
-char const *
-v6addr2str2(struct in6_addr const *addr)
-{
- return inet_ntop(AF_INET6, addr, addr_buffer2, sizeof(addr_buffer2));
-}
-
-char const *
-fnstack_peek(void)
-{
- return NULL;
-}
-
-void
-reqs_errors_log_summary(void)
-{
- /* Nothing here */
-}
-
-char const *
-config_get_tal(void)
-{
- return "tal/";
-}
-
-bool
-config_get_shuffle_tal_uris(void)
-{
- return false;
-}
-
-char const *
-config_get_local_repository(void)
-{
- return "repository/";
-}
-
-enum rsync_strategy
-config_get_rsync_strategy(void)
-{
- return RSYNC_ROOT;
-}
-
-bool
-config_get_rsync_enabled(void)
-{
- return true;
-}
-
-unsigned int
-config_get_rsync_priority(void)
-{
- return rsync_priority;
-}
-
-unsigned int
-config_get_http_priority(void)
-{
- return http_priority;
-}
-
-char const *
-config_get_slurm(void)
-{
- return NULL;
-}
-
-enum mode
-config_get_mode(void)
-{
- return STANDALONE;
-}
-
-char const *
-config_get_output_roa(void)
-{
- return NULL;
-}
-
-char const *
-config_get_output_bgpsec(void)
-{
- return NULL;
-}
-
-bool
-config_get_op_log_enabled(void)
-{
- return true;
-}
-
-char const *
-config_get_op_log_tag(void)
-{
- return NULL;
-}
-
-bool
-config_get_op_log_color_output(void)
-{
- return false;
-}
-
-enum filename_format
-config_get_op_log_filename_format(void)
-{
- return FNF_NAME;
-}
-
-uint8_t
-config_get_op_log_level(void)
-{
- return 3; /* LOG_ERR */
-}
-
-enum log_output
-config_get_op_log_output(void)
-{
- return CONSOLE;
-}
-
-uint32_t
-config_get_op_log_facility(void)
-{
- return (3<<3); /* LOG_DAEMON */
-}
-
-bool
-config_get_val_log_enabled(void)
-{
- return true;
-}
-
-char const *
-config_get_val_log_tag(void)
-{
- return "VALIDATION";
-}
-
-bool
-config_get_val_log_color_output(void)
-{
- return false;
-}
-
-enum filename_format
-config_get_val_log_filename_format(void)
-{
- return FNF_NAME;
-}
-
-uint8_t
-config_get_val_log_level(void)
-{
- return 3; /* LOG_ERR */
-}
-
-enum log_output
-config_get_val_log_output(void)
-{
- return CONSOLE;
-}
-
-uint32_t
-config_get_val_log_facility(void)
-{
- return (3<<3); /* LOG_DAEMON */
-}
-
-enum incidence_action
-incidence_get_action(enum incidence_id id)
-{
- return INAC_ERROR;
-}
-
-void
-config_set_rsync_priority(unsigned int value)
-{
- rsync_priority = value;
-}
-
-void
-config_set_http_priority(unsigned int value)
-{
- http_priority = value;
-}
-
-unsigned int
-config_get_thread_pool_validation_max(void)
-{
- return 10;
-}
-
-unsigned int
-config_get_max_asn_per_pfx(void)
-{
- return 10;
-}
-
-unsigned int
-config_get_max_pfx_per_asn(void)
-{
- return 10;
-}
-
#include "alloc.c"
#include "file.c"
-#include "impersonator.c"
#include "line_file.c"
-#include "log.c"
+#include "mock.c"
START_TEST(file_line_normal)
{
--- /dev/null
+#include "mock.h"
+
+#include <arpa/inet.h>
+#include "state.h"
+
+/**
+ * Some core functions, as linked from unit tests.
+ */
+
+MOCK_TRUE(log_val_enabled, unsigned int l)
+MOCK_TRUE(log_op_enabled, unsigned int l)
+
+#define MOCK_PRINT \
+ do { \
+ va_list args; \
+ va_start(args, format); \
+ vfprintf(stdout, format, args); \
+ va_end(args); \
+ } while (0)
+
+#define MOCK_VOID_PRINT(name) \
+ void \
+ name(const char *format, ...) \
+ { \
+ MOCK_PRINT; \
+ }
+
+#define MOCK_INT_PRINT(name, result) \
+ int \
+ name(const char *format, ...) \
+ { \
+ MOCK_PRINT; \
+ return result; \
+ }
+
+MOCK_VOID_PRINT(pr_op_debug)
+MOCK_VOID_PRINT(pr_op_info)
+MOCK_INT_PRINT(pr_op_warn, 0)
+MOCK_INT_PRINT(pr_op_err, -EINVAL)
+MOCK_INT_PRINT(pr_op_err_st, -EINVAL)
+MOCK_INT_PRINT(op_crypto_err, -EINVAL)
+
+MOCK_VOID_PRINT(pr_val_debug)
+MOCK_VOID_PRINT(pr_val_info)
+MOCK_INT_PRINT(pr_val_warn, 0)
+MOCK_INT_PRINT(pr_val_err, -EINVAL)
+MOCK_INT_PRINT(val_crypto_err, -EINVAL)
+
+int
+incidence(enum incidence_id id, const char *format, ...)
+{
+ MOCK_PRINT;
+ return -EINVAL;
+}
+
+void
+enomem_panic(void)
+{
+ ck_abort_msg("Out of memory.");
+}
+
+void
+pr_crit(const char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ vfprintf(stdout, format, args);
+ va_end(args);
+ ck_abort();
+}
+
+static char addr_buffer1[INET6_ADDRSTRLEN];
+static char addr_buffer2[INET6_ADDRSTRLEN];
+
+char const *
+v4addr2str(struct in_addr const *addr)
+{
+ return inet_ntop(AF_INET, addr, addr_buffer1, sizeof(addr_buffer1));
+}
+
+char const *
+v4addr2str2(struct in_addr const *addr)
+{
+ return inet_ntop(AF_INET, addr, addr_buffer2, sizeof(addr_buffer2));
+}
+
+char const *
+v6addr2str(struct in6_addr const *addr)
+{
+ return inet_ntop(AF_INET6, addr, addr_buffer1, sizeof(addr_buffer1));
+}
+
+char const *
+v6addr2str2(struct in6_addr const *addr)
+{
+ return inet_ntop(AF_INET6, addr, addr_buffer2, sizeof(addr_buffer2));
+}
+
+MOCK_NULL(config_get_slurm, char const *, void)
+MOCK(config_get_tal, char const *, "tal/", void)
+MOCK(config_get_local_repository, char const *, "repository/", void)
+MOCK_FALSE(config_get_shuffle_tal_uris, void)
+MOCK(config_get_mode, enum mode, STANDALONE, void)
+MOCK_TRUE(config_get_rsync_enabled, void)
+MOCK(config_get_rsync_strategy, enum rsync_strategy, RSYNC_ROOT, void)
+MOCK_ABORT_PTR(config_get_rsync_args, string_array const, bool t)
+MOCK_NULL(config_get_output_roa, char const *, void)
+MOCK_NULL(config_get_output_bgpsec, char const *, void)
+MOCK_UINT(config_get_thread_pool_validation_max, 10, void)
+MOCK(config_get_op_log_filename_format, enum filename_format, FNF_NAME, void)
+MOCK(config_get_val_log_filename_format, enum filename_format, FNF_NAME, void)
--- /dev/null
+#ifndef TEST_MOCK_H_
+#define TEST_MOCK_H_
+
+#define MOCK(name, type, result, ...) \
+ type name(__VA_ARGS__) { return result; }
+#define MOCK_TRUE(name, ...) \
+ MOCK(name, bool, true, __VA_ARGS__)
+#define MOCK_FALSE(name, ...) \
+ MOCK(name, bool, false, __VA_ARGS__)
+#define MOCK_INT(name, result, ...) \
+ MOCK(name, int, result, __VA_ARGS__)
+#define MOCK_UINT(name, result, ...) \
+ MOCK(name, unsigned int, result, __VA_ARGS__)
+#define MOCK_NULL(name, type, ...) \
+ MOCK(name, type, NULL, __VA_ARGS__)
+#define MOCK_VOID(name, ...) \
+ void name(__VA_ARGS__) {}
+
+#define __MOCK_ABORT(name, type, result, ...) \
+ type name(__VA_ARGS__) { ck_abort(); return result; }
+#define MOCK_ABORT_INT(name, ...) \
+ __MOCK_ABORT(name, int, 0, __VA_ARGS__)
+#define MOCK_ABORT_ENUM(name, type, ...) \
+ __MOCK_ABORT(name, enum type, 0, __VA_ARGS__)
+#define MOCK_ABORT_PTR(name, type, ...) \
+ __MOCK_ABORT(name, struct type *, NULL, __VA_ARGS__)
+#define MOCK_ABORT_VOID(name, ...) \
+ void name(__VA_ARGS__) { ck_abort(); }
+
+#endif /* TEST_MOCK_H_ */
#include <stdlib.h>
#include "alloc.c"
-#include "impersonator.c"
-#include "log.c"
+#include "mock.c"
#include "rrdp/rrdp_objects.c"
#define END 0xFFFF
SRunner *runner;
int tests_failed;
- log_setup(true);
-
suite = xml_load_suite();
runner = srunner_create(suite);
#include "alloc.c"
#include "common.c"
-#include "log.c"
-#include "impersonator.c"
+#include "mock.c"
#include "str_token.c"
#include "types/uri.c"
#include "rsync/rsync.c"
+/* Mocks */
-struct validation *
-state_retrieve(void)
-{
- return NULL;
-}
+MOCK_NULL(state_retrieve, struct validation *, void)
+MOCK_ABORT_PTR(validation_rsync_visited_uris, uri_list, struct validation *s)
+
+/* Tests */
static void
assert_descendant(bool expected, char *ancestor, char *descendant)
#include "alloc.c"
#include "common.c"
-#include "log.c"
-#include "impersonator.c"
+#include "mock.c"
#include "types/address.c"
#include "types/delta.c"
#include "types/router_key.c"
#include <stdlib.h>
#include "alloc.c"
-#include "log.c"
-#include "impersonator.c"
+#include "mock.c"
#include "types/address.c"
#include "types/delta.c"
#include "types/router_key.c"
#include "alloc.c"
#include "common.c"
#include "file.c"
-#include "impersonator.c"
#include "json_parser.c"
-#include "log.c"
+#include "mock.c"
#include "output_printer.c"
#include "types/delta.c"
#include "types/router_key.c"
#include "rtr/db/delta.c"
#include "rtr/db/deltas_array.c"
#include "rtr/db/db_table.c"
-#include "rtr/db/rtr_db_impersonator.c"
+#include "rtr/db/rtr_db_mock.c"
#include "rtr/db/vrps.c"
#include "slurm/db_slurm.c"
#include "slurm/slurm_loader.c"
static const bool deltas_3to4[] = { 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, };
static const bool deltas_4to4[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
-/* Impersonator functions */
+/* Mocks */
unsigned int deltas_lifetime = 5;
-unsigned int
-config_get_deltas_lifetime(void)
-{
- return deltas_lifetime;
-}
+MOCK_UINT(config_get_deltas_lifetime, deltas_lifetime, void)
/* Test functions */
#include "alloc.c"
#include "common.c"
#include "file.c"
-#include "impersonator.c"
#include "json_parser.c"
-#include "log.c"
+#include "mock.c"
#include "output_printer.c"
#include "crypto/base64.c"
#include "types/delta.c"
#include "rtr/db/delta.c"
#include "rtr/db/deltas_array.c"
#include "rtr/db/db_table.c"
-#include "rtr/db/rtr_db_impersonator.c"
+#include "rtr/db/rtr_db_mock.c"
#include "rtr/db/vrps.c"
#include "slurm/db_slurm.c"
#include "slurm/slurm_loader.c"
#include "slurm/slurm_parser.c"
#include "thread/thread_pool.c"
-/* Helper functions */
-
struct expected_pdu {
uint8_t pdu_type;
STAILQ_ENTRY(expected_pdu) list_hook;
/*
* This initializes the database using the test values from
- * db/rtr_db_impersonator.c.
+ * db/rtr_db_mock.c.
*/
static void
init_db_full(void)
query->serial_number = serial;
}
-/* Impersonator functions */
+/* Mocks */
-unsigned int
-config_get_deltas_lifetime(void)
-{
- return 5;
-}
-
-int
-clients_set_rtr_version(int fd, uint8_t rtr_version)
-{
- return 0;
-}
+MOCK_UINT(config_get_deltas_lifetime, 5, void)
+MOCK_INT(clients_set_rtr_version, 0, int f, uint8_t v)
int
clients_get_rtr_version_set(int fd, bool *is_set, uint8_t *rtr_version)
SRunner *runner;
int tests_failed;
- log_setup(true);
-
suite = pdu_suite();
runner = srunner_create(suite);
#include "alloc.c"
#include "common.c"
-#include "log.c"
-#include "impersonator.c"
+#include "mock.c"
#include "rtr/err_pdu.c"
#include "rtr/pdu.c"
#include "rtr/primitive_reader.c"
-#include "rtr/db/rtr_db_impersonator.c"
+#include "rtr/db/rtr_db_mock.c"
-/*
- * Used to be a wrapper for `buffer2fd()`, but that's no longer necessary.
- *
- * Converts the @buffer buffer into PDU @obj, using the @cb function.
- * Also takes care of the header validation.
- */
-#define BUFFER2FD(buffer, cb, obj) { \
- struct pdu_header header; \
- struct pdu_reader reader; \
- \
- pdu_reader_init(&reader, buffer, sizeof(buffer)); \
- init_pdu_header(&header); \
- ck_assert_int_eq(0, cb(&header, &reader, obj)); \
- assert_pdu_header(&(obj)->header); \
-}
-
-/* Impersonator functions */
+/* Mocks */
-#define IMPERSONATE_HANDLER(name) \
- int \
- handle_## name ##_pdu(int fd, struct rtr_request const *req) { \
- return 0; \
- }
-
-uint16_t
-get_current_session_id(uint8_t rtr_version)
-{
- return 12345;
-}
-
-int
-clients_set_rtr_version(int fd, uint8_t rtr_version)
-{
- return 0;
-}
+MOCK(get_current_session_id, uint16_t, 12345, uint8_t v)
+MOCK_INT(clients_set_rtr_version, 0, int f, uint8_t v)
int
clients_get_rtr_version_set(int fd, bool *is_set, uint8_t *rtr_version)
return 0;
}
-IMPERSONATE_HANDLER(serial_notify)
-IMPERSONATE_HANDLER(serial_query)
-IMPERSONATE_HANDLER(reset_query)
-IMPERSONATE_HANDLER(cache_response)
-IMPERSONATE_HANDLER(ipv4_prefix)
-IMPERSONATE_HANDLER(ipv6_prefix)
-IMPERSONATE_HANDLER(end_of_data)
-IMPERSONATE_HANDLER(cache_reset)
-IMPERSONATE_HANDLER(router_key)
-IMPERSONATE_HANDLER(error_report)
+#define MOCK_HANDLER(n) MOCK(n, int, 0, int f, struct rtr_request const *r)
+
+MOCK_HANDLER(handle_serial_notify_pdu)
+MOCK_HANDLER(handle_serial_query_pdu)
+MOCK_HANDLER(handle_reset_query_pdu)
+MOCK_HANDLER(handle_cache_response_pdu)
+MOCK_HANDLER(handle_ipv4_prefix_pdu)
+MOCK_HANDLER(handle_ipv6_prefix_pdu)
+MOCK_HANDLER(handle_end_of_data_pdu)
+MOCK_HANDLER(handle_cache_reset_pdu)
+MOCK_HANDLER(handle_router_key_pdu)
+MOCK_HANDLER(handle_error_report_pdu)
int
send_error_report_pdu(int fd, uint8_t version, uint16_t code,
return 0;
}
-int
-rtrhandler_handle_roa_v4(struct db_table *table, uint32_t asn,
+MOCK_INT(rtrhandler_handle_roa_v4, 0, struct db_table *table, uint32_t asn,
struct ipv4_prefix const *prefix4, uint8_t max_length)
-{
- return 0;
-}
-
-int
-rtrhandler_handle_roa_v6(struct db_table *table, uint32_t asn,
+MOCK_INT(rtrhandler_handle_roa_v6, 0, struct db_table *table, uint32_t asn,
struct ipv6_prefix const *prefix6, uint8_t max_length)
-{
- return 0;
-}
-
-int
-rtrhandler_handle_router_key(struct db_table *table,
+MOCK_INT(rtrhandler_handle_router_key, 0, struct db_table *table,
unsigned char const *ski, uint32_t as, unsigned char const *spk)
-{
- return 0;
-}
-/* End of impersonator */
+/* End of mocks */
+
+/*
+* Used to be a wrapper for `buffer2fd()`, but that's no longer necessary.
+*
+* Converts the @buffer buffer into PDU @obj, using the @cb function.
+* Also takes care of the header validation.
+*/
+#define BUFFER2FD(buffer, cb, obj) { \
+ struct pdu_header header; \
+ struct pdu_reader reader; \
+ \
+ pdu_reader_init(&reader, buffer, sizeof(buffer)); \
+ init_pdu_header(&header); \
+ ck_assert_int_eq(0, cb(&header, &reader, obj)); \
+ assert_pdu_header(&(obj)->header); \
+}
static void
init_pdu_header(struct pdu_header *header)
#include <string.h>
#include "alloc.c"
-#include "impersonator.c"
-#include "log.c"
+#include "mock.c"
#include "rtr/primitive_reader.c"
/*
#include "object/tal.c"
#include <check.h>
-#include <errno.h>
-#include <stdlib.h>
-#include "common.h"
#include "alloc.c"
#include "file.c"
-#include "impersonator.c"
#include "line_file.c"
-#include "log.c"
-#include "state.h"
-#include "str_token.c"
-#include "random.c"
+#include "mock.c"
#include "types/uri.c"
#include "crypto/base64.c"
-#include "rsync/rsync.c"
-#include "thread/thread_pool.c"
-/* Impersonate functions that won't be utilized by tests */
+/* Mocks */
-int
-validation_prepare(struct validation **out, struct tal *tal,
- struct validation_handler *validation_handler)
-{
- return 0;
-}
-
-int
-certificate_traverse(struct rpp *rpp_parent, struct rpki_uri *cert_uri)
-{
- return -EINVAL;
-}
-
-enum pubkey_state
-validation_pubkey_state(struct validation *state)
-{
- return PKS_INVALID;
-}
-
-void
-validation_destroy(struct validation *state)
-{
- /* Nothing to destroy */
-}
-
-int
-process_file_or_dir(char const *location, char const *file_ext, bool empty_err,
- process_file_cb cb, void *arg)
-{
- return 0;
-}
-
-void
-close_thread(pthread_t thread, char const *what)
-{
- /* Nothing to close */
-}
-
-char *
-map_uri_to_local(char const *uri, char const *uri_prefix, char const *workspace)
-{
- char *result;
-
- /* These tests focus on global URIs, so set a dummy value */
- result = strdup("dummy");
- if (result == NULL)
- enomem_panic();
-
- return result;
-}
-
-void
-fnstack_init(void)
-{
- /* Empty */
-}
+static unsigned int rsync_priority;
+static unsigned int http_priority;
-void
-fnstack_cleanup(void)
-{
- /* Empty */
-}
+MOCK_UINT(config_get_rsync_priority, rsync_priority, void)
+MOCK_UINT(config_get_http_priority, http_priority, void)
+/* These tests focus on global URIs, so set a dummy value */
+MOCK(map_uri_to_local, char *, pstrdup("dummy"), char const *u, char const *p)
+MOCK_ABORT_VOID(db_rrdp_reset_visited_tals, void)
-void
-fnstack_pop(void)
-{
- /* Empty */
-}
-
-void
-fnstack_push(char const *file)
-{
- /* Empty */
-}
-
-struct validation *
-state_retrieve(void)
-{
- return NULL;
-}
-
-void
-db_rrdp_reset_visited_tals(void)
-{
- /* Empty */
-}
-
-void
-db_rrdp_rem_nonvisited_tals(void)
-{
- /* Empty */
-}
-
-void
-panic_on_fail(int error, char const *function_name)
-{
- if (error)
- ck_abort_msg("%s() returned errcode %d", function_name, error);
-}
-
-void
-mutex_lock(pthread_mutex_t *lock)
-{
- /* Empty */
-}
-
-void
-mutex_unlock(pthread_mutex_t *lock)
-{
- /* Empty */
-}
+/* Tests */
START_TEST(tal_load_normal)
{
ck_assert_int_eq(tal_load("tal/lacnic.tal", &tal), 0);
- config_set_http_priority(60);
- config_set_rsync_priority(50);
+ http_priority = 60;
+ rsync_priority = 50;
tal_order_uris(tal);
ck_assert_str_eq(tal->uris.array[0]->global, "https://potato");
ck_assert_int_eq(tal_load("tal/lacnic.tal", &tal), 0);
- config_set_http_priority(50);
- config_set_rsync_priority(60);
+ http_priority = 50;
+ rsync_priority = 60;
tal_order_uris(tal);
ck_assert_str_eq(tal->uris.array[0]->global,
#include "alloc.c"
#include "common.c"
-#include "log.c"
-#include "impersonator.c"
+#include "mock.c"
#include "thread/thread_pool.c"
static void
#include "alloc.c"
#include "common.c"
-#include "log.c"
-#include "impersonator.c"
+#include "mock.c"
#include "types/address.c"
+/* Tests */
+
static void
test_range4(uint32_t min, uint32_t max, bool valid)
{
#include "alloc.c"
#include "common.c"
-#include "log.c"
-#include "impersonator.c"
+#include "mock.c"
#include "types/uri.c"
#define BUFFER_LEN 128
#include <check.h>
#include "alloc.c"
-#include "log.c"
-#include "impersonator.c"
+#include "mock.c"
#include "object/vcard.c"
#define VC_BEGIN "BEGIN:VCARD\r\n"
#include <check.h>
#include <errno.h>
#include <stdlib.h>
-
#include <libxml/xmlreader.h>
-#include "impersonator.c"
-#include "log.c"
+
+#include "mock.c"
#include "xml/relax_ng.c"
struct reader_ctx {