1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/*
ircdtorture: an IRC RFC compliancy tester
(c) 2007 Jelmer Vernooij <jelmer@nl.linux.org>
This program 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 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <check.h>
#include "ctrlproxy.h"
#include "torture.h"
#include "keyfile.h"
const char *nickserv_find_nick(struct irc_network *n, char *nick);
const char *nickserv_nick(struct irc_network *n);
void nickserv_identify_me(struct irc_network *network, char *nick);
static void strip_comments(char *str)
{
char *comment_start, *line_end;
do {
comment_start = strchr(str, '#');
if (comment_start == NULL)
return;
line_end = strchr(comment_start, '\n');
memmove(comment_start, line_end+1, strlen(line_end+1)+1);
} while(TRUE);
}
START_TEST(test_write_file_empty)
char *fn = torture_tempfile(__FUNCTION__);
char *contents;
fail_unless(keyfile_write_file(NULL, "", fn) == TRUE);
fail_unless(g_file_get_contents(fn, &contents, NULL, NULL));
strip_comments(contents);
fail_unless(!strcmp(contents, ""), "Excepted empty file, got: %s", contents);
END_TEST
START_TEST(test_write_file_simple_network)
char *fn = torture_tempfile(__FUNCTION__);
char *contents;
struct keyfile_entry n = {
.network = "bla",
.nick = "anick",
.pass = "somepw"
};
fail_unless(keyfile_write_file(g_list_append(NULL, &n), "", fn) == TRUE);
fail_unless(g_file_get_contents(fn, &contents, NULL, NULL));
strip_comments(contents);
fail_unless(!strcmp(contents, "anick\tsomepw\tbla\n"), "got: %s", contents);
END_TEST
START_TEST(test_write_file_simple_nonetwork)
char *fn = torture_tempfile(__FUNCTION__);
char *contents;
struct keyfile_entry n = {
.network = NULL,
.nick = "anick",
.pass = "somepw"
};
fail_unless(keyfile_write_file(g_list_append(NULL, &n), "", fn) == TRUE);
fail_unless(g_file_get_contents(fn, &contents, NULL, NULL));
strip_comments(contents);
fail_unless(!strcmp(contents, "anick\tsomepw\t*\n"), "got: %s", contents);
END_TEST
START_TEST(test_read_file_empty)
char *fn = torture_tempfile(__FUNCTION__);
GList *gl = NULL;
fail_unless(g_file_set_contents(fn, "", -1, NULL));
fail_unless(keyfile_read_file(fn, '#', &gl));
fail_unless(gl == NULL);
END_TEST
START_TEST(test_read_file_empty_lines)
char *fn = torture_tempfile(__FUNCTION__);
GList *gl = NULL;
fail_unless(g_file_set_contents(fn, "\n\n\n", -1, NULL));
fail_unless(keyfile_read_file(fn, '#', &gl));
fail_unless(gl == NULL);
END_TEST
START_TEST(test_read_file_almost_empty_lines)
char *fn = torture_tempfile(__FUNCTION__);
GList *gl = NULL;
fail_unless(g_file_set_contents(fn, "foo\nbar\nbla\n", -1, NULL));
fail_unless(keyfile_read_file(fn, '#', &gl));
fail_unless(gl == NULL);
END_TEST
START_TEST(test_read_file_simple_network)
char *fn = torture_tempfile(__FUNCTION__);
GList *gl = NULL;
struct keyfile_entry *e;
fail_unless(g_file_set_contents(fn, "bla\tbloe\tblie\n", -1, NULL));
fail_unless(keyfile_read_file(fn, '#', &gl));
e = gl->data;
fail_unless(!strcmp(e->nick, "bla"));
fail_unless(!strcmp(e->pass, "bloe"));
fail_unless(!strcmp(e->network, "blie"));
fail_unless(gl->next == NULL);
END_TEST
START_TEST(test_read_file_simple_nonetwork)
char *fn = torture_tempfile(__FUNCTION__);
GList *gl = NULL;
struct keyfile_entry *e;
fail_unless(g_file_set_contents(fn, "bla\tbloe\t*\n", -1, NULL));
fail_unless(keyfile_read_file(fn, '#', &gl));
e = gl->data;
fail_unless(!strcmp(e->nick, "bla"));
fail_unless(!strcmp(e->pass, "bloe"));
fail_unless(e->network == NULL);
fail_unless(gl->next == NULL);
END_TEST
Suite *nickserv_suite()
{
Suite *s = suite_create("nickserv");
TCase *tc_core = tcase_create("core");
suite_add_tcase(s, tc_core);
tcase_add_test(tc_core, test_write_file_empty);
tcase_add_test(tc_core, test_write_file_simple_network);
tcase_add_test(tc_core, test_write_file_simple_nonetwork);
tcase_add_test(tc_core, test_read_file_empty);
tcase_add_test(tc_core, test_read_file_empty_lines);
tcase_add_test(tc_core, test_read_file_almost_empty_lines);
tcase_add_test(tc_core, test_read_file_simple_network);
tcase_add_test(tc_core, test_read_file_simple_nonetwork);
return s;
}
|