void
test_already_launched (void)
{
    const gchar *packet;
    gsize packet_size;
    GString *output;
    GString *expected_packet;
    const gchar command_line[] = "/bin/cat";
    const gchar *user_name;

    user_name = g_get_user_name();
    milter_manager_launch_command_encoder_encode_launch(command_encoder,
                                                        &packet, &packet_size,
                                                        command_line, user_name);
    cut_trace(write_packet(packet, packet_size));
    cut_trace(write_packet(packet, packet_size));
    pump_all_events();

    milter_manager_reply_encoder_encode_success(reply_encoder,
                                                &packet, &packet_size);
    expected_packet = g_string_new_len(packet, packet_size);
    milter_manager_reply_encoder_encode_error(reply_encoder,
                                              &packet, &packet_size,
                                              "already launched: </bin/cat>");
    g_string_append_len(expected_packet, packet, packet_size);
    output = gcut_string_io_channel_get_string(output_channel);
    cut_assert_equal_memory(expected_packet->str, expected_packet->len,
                            output->str, output->len);
}
예제 #2
0
void
test_not_remove_unix_socket_on_create (void)
{
    const gchar *path;
    GError *error = NULL;

    path = cut_take_printf("%s/milter.sock", tmp_dir);
    spec = cut_take_printf("unix:%s", path);

    g_file_set_contents(path, "", 0, &error);
    gcut_assert_error(error);

    milter_client_set_remove_unix_socket_on_create(client, FALSE);

    cut_trace(setup_client());
    cut_assert_false(milter_client_run(client, &error));
    gcut_assert_error(actual_error);

    actual_error = error;
    expected_error = g_error_new(MILTER_CONNECTION_ERROR,
                                 MILTER_CONNECTION_ERROR_BIND_FAILURE,
                                 "failed to bind(): %s: %s",
                                 spec, g_strerror(EADDRINUSE));
    gcut_assert_equal_error(expected_error, actual_error);
}
예제 #3
0
void
test_extract_attachments (const void *data)
{
    ExtractTestData *test_data = (ExtractTestData*)data;

    const char *body;
    MzAttachment expected = { NULL, NULL, NULL, 0 };
    const char *expected_data;
    unsigned int expected_size = 0;
    MzAttachment *actual;

    expected_data = mz_test_utils_load_data(test_data->expected_attachment_filename,
                                            &expected_size);
    expected.data = expected_data;
    expected.data_length = expected_size;
    expected.filename = (char*)test_data->expected_attachment_filename;

    body = cut_get_fixture_data_string(test_data->fixture_filename, NULL);
    cut_assert_not_null(body);

    actual_attachments = mz_utils_extract_attachments(body, test_data->boundary_string);
    cut_assert_not_null(actual_attachments);

    actual = actual_attachments->data;

    cut_trace(assert_equal_attachment(&expected, actual));
}
void
test_launch_error (gconstpointer data)
{
    const gchar *packet;
    gsize packet_size;
    GString *output;
    const gchar *command;
    const gchar *user_name;
    const gchar *expected_error_message;

    command = gcut_data_get_string(data, "command");
    user_name = gcut_data_get_string(data, "user-name");
    expected_error_message = gcut_data_get_string(data,
                                                  "expected-error-message");

    milter_manager_launch_command_encoder_encode_launch(command_encoder,
                                                        &packet, &packet_size,
                                                        command, user_name);
    cut_trace(write_packet(packet, packet_size));
    pump_all_events();

    milter_manager_reply_encoder_encode_error(reply_encoder,
                                              &packet, &packet_size,
                                              expected_error_message);
    output = gcut_string_io_channel_get_string(output_channel);
    cut_assert_equal_memory(packet, packet_size,
                            output->str, output->len);
}
예제 #5
0
void
test_get_string (void)
{
    cut_trace(test_load());

    cut_assert_equal_string("/XXX/SENDMAIL",
                            mz_config_get_string(config, "sendmail_path"));
}
예제 #6
0
void
test_set_string (void)
{
    cut_trace(test_load());

    cut_assert_null(mz_config_get_string(config, "new_value"));
    mz_config_set_string(config, "new_value", "12345678X");
    cut_assert_equal_string("12345678X",
                            mz_config_get_string(config, "new_value"));
}
예제 #7
0
static gboolean
cb_idle_helo (gpointer user_data)
{
    const gchar *packet;
    gsize packet_size;

    cut_trace(setup_test_server());
    milter_command_encoder_encode_helo(encoder, &packet, &packet_size, fqdn);
    milter_test_server_write(server, packet, packet_size);

    return FALSE;
}
예제 #8
0
void
test_change_unix_socket_group (void)
{
    const gchar *path;
    struct stat stat_buffer;
    gint i, n_groups, max_n_groups;
    gid_t *groups;
    struct group *group = NULL;
    GError *error = NULL;

    path = cut_take_printf("%s/milter.sock", tmp_dir);
    spec = cut_take_printf("unix:%s", path);

    max_n_groups = getgroups(0, NULL);
    if (max_n_groups < 0)
        max_n_groups = 5;

    groups = g_new0(gid_t, max_n_groups);
    cut_take_memory(groups);

    n_groups = getgroups(max_n_groups, groups);
    if (n_groups == -1)
        cut_assert_errno();

    for (i = 0; i < n_groups; i++) {
        if (groups[i] == getegid())
            continue;

        errno = 0;
        group = getgrgid(groups[i]);
        if (!group) {
            if (errno == 0)
                cut_omit("can't find supplementary group: %u", groups[i]);
            else
                cut_assert_errno();
        }
    }

    if (!group)
        cut_omit("no supplementary group");

    milter_client_set_default_unix_socket_group(client, group->gr_name);
    milter_client_set_default_remove_unix_socket_on_close(client, FALSE);

    cut_trace(setup_client());
    milter_client_run(client, &error);
    gcut_assert_error(error);

    if (stat(path, &stat_buffer) == -1)
        cut_assert_errno();

    cut_assert_equal_uint(group->gr_gid, stat_buffer.st_gid);
}
예제 #9
0
void
test_remove_unix_socket_on_close (void)
{
    const gchar *path;

    path = cut_take_printf("%s/milter.sock", tmp_dir);
    spec = cut_take_printf("unix:%s", path);

    cut_trace(setup_client());
    cut_assert_true(milter_client_run(client, &actual_error));
    gcut_assert_error(actual_error);

    cut_assert_false(g_file_test(path, G_FILE_TEST_EXISTS));
}
예제 #10
0
void
test_remove_unix_socket_on_create (void)
{
    const gchar *path;
    GError *error = NULL;

    path = cut_take_printf("%s/milter.sock", tmp_dir);
    spec = cut_take_printf("unix:%s", path);

    g_file_set_contents(path, "", 0, &error);
    gcut_assert_error(error);

    cut_trace(setup_client());
    cut_assert_true(milter_client_run(client, &error));
    gcut_assert_error(error);
    gcut_assert_error(actual_error);
}
예제 #11
0
void
test_helo (void)
{
    GError *error = NULL;

    if (n_workers > 0)
        cut_omit("can't obtain the result from callbacks in child process");

    idle_id = milter_event_loop_add_idle(loop, cb_idle_helo, NULL);

    cut_trace(setup_client());
    milter_client_run(client, &error);
    gcut_assert_error(error);

    cut_assert_equal_string(fqdn, helo_fqdn);
    cut_assert_true(loop_run_count > 0);
}
예제 #12
0
void
test_remove_pid_file_on_exit (void)
{
    gboolean pid_file_exist = FALSE;

    cut_trace(setup_client());
    milter_client_set_pid_file(client, pid_file_path());
    milter_event_loop_add_idle_full(loop,
                                    G_PRIORITY_HIGH,
                                    cb_idle_check_pid_file_existence,
                                    &pid_file_exist,
                                    NULL);
    cut_assert_true(milter_client_run(client, &actual_error));
    gcut_assert_error(actual_error);
    cut_assert_true(pid_file_exist);

    cut_assert_false(g_file_test(pid_file_path(), G_FILE_TEST_EXISTS));
}
예제 #13
0
파일: test-string.c 프로젝트: mooz/groonga
void
test_text_otoj(gconstpointer data)
{
  grn_obj object, json;
  grn_builtin_type type;
  const gchar *expected, *actual;

  GRN_TEXT_INIT(&json, 0);

  expected = gcut_data_get_string(data, "expected");
  type = gcut_data_get_int(data, "type");
  cut_trace(construct_object(data, type, &object));
  grn_text_otoj(&context, &json, &object, NULL);
  grn_obj_unlink(&context, &object);
  actual = cut_take_printf("%.*s",
                           (int)GRN_TEXT_LEN(&json), GRN_TEXT_VALUE(&json));
  grn_obj_unlink(&context, &json);
  cut_assert_equal_string(expected, actual);
}
예제 #14
0
void
test_negotiate (void)
{
    guint32 version;
    MilterActionFlags action;
    MilterStepFlags step;
    GError *error = NULL;

    if (n_workers > 0)
        cut_omit("can't obtain the result from callbacks in child process");

    version = 2;
    action = MILTER_ACTION_ADD_HEADERS |
        MILTER_ACTION_CHANGE_BODY |
        MILTER_ACTION_ADD_ENVELOPE_RECIPIENT |
        MILTER_ACTION_DELETE_ENVELOPE_RECIPIENT |
        MILTER_ACTION_CHANGE_HEADERS |
        MILTER_ACTION_QUARANTINE |
        MILTER_ACTION_SET_SYMBOL_LIST;
    step = MILTER_STEP_NO_CONNECT |
        MILTER_STEP_NO_HELO |
        MILTER_STEP_NO_ENVELOPE_FROM |
        MILTER_STEP_NO_ENVELOPE_RECIPIENT |
        MILTER_STEP_NO_BODY |
        MILTER_STEP_NO_HEADERS |
        MILTER_STEP_NO_END_OF_HEADER;
    option = milter_option_new(version, action, step);

    idle_id = milter_event_loop_add_idle(loop, cb_idle_negotiate, NULL);

    cut_trace(setup_client());
    milter_client_run(client, &error);
    gcut_assert_error(error);

    milter_assert_equal_option(option, negotiate_option);

    macros_requests = milter_macros_requests_new();
    milter_assert_equal_macros_requests(macros_requests,
                                        negotiate_macros_requests);
    cut_assert_true(loop_run_count > 0);
}
void
test_launch (void)
{
    const gchar *packet;
    gsize packet_size;
    GString *output;
    const gchar command_line[] = "/bin/echo -n";
    const gchar *user_name;

    user_name = g_get_user_name();
    milter_manager_launch_command_encoder_encode_launch(command_encoder,
                                                        &packet, &packet_size,
                                                        command_line, user_name);
    cut_trace(write_packet(packet, packet_size));
    pump_all_events();

    milter_manager_reply_encoder_encode_success(reply_encoder,
                                                &packet, &packet_size);
    output = gcut_string_io_channel_get_string(output_channel);
    cut_assert_equal_memory(packet, packet_size,
                            output->str, output->len);
}
예제 #16
0
void
test_listen_started (void)
{
    struct sockaddr_in *address_inet;
    gchar actual_address_string[INET6_ADDRSTRLEN];
    GError *error = NULL;

    cut_trace(setup_client());
    milter_client_run(client, &error);
    gcut_assert_error(error);

    cut_assert_not_null(actual_address);

    address_inet = (struct sockaddr_in *)actual_address;
    cut_assert_equal_uint(AF_INET, address_inet->sin_family);
    cut_assert_equal_uint(9999, g_ntohs(address_inet->sin_port));
    cut_assert_equal_string("127.0.0.1",
                            inet_ntop(AF_INET, &(address_inet->sin_addr),
                                      actual_address_string,
                                      sizeof(actual_address_string)));
    cut_assert_equal_uint(sizeof(*address_inet), actual_address_size);
}
예제 #17
0
void
test_change_unix_socket_mode (void)
{
    const gchar *path;
    struct stat stat_buffer;
    GError *error = NULL;

    path = cut_take_printf("%s/milter.sock", tmp_dir);
    spec = cut_take_printf("unix:%s", path);

    milter_client_set_default_unix_socket_mode(client, 0666);
    milter_client_set_default_remove_unix_socket_on_close(client, FALSE);

    cut_trace(setup_client());
    milter_client_run(client, &error);
    gcut_assert_error(error);

    if (stat(path, &stat_buffer) == -1)
        cut_assert_errno();

    cut_assert_equal_uint(S_IFSOCK | 0666, stat_buffer.st_mode);
}
예제 #18
0
void
test_fail (void)
{
    cut_trace(cut_assert_always_fail());
}
예제 #19
0
static void
setup_test_server (void)
{
    cut_trace(server = milter_test_server_new(spec, decoder, loop));
}