|
Atrinik Server 2.5
|
00001 /************************************************************************ 00002 * Atrinik, a Multiplayer Online Role Playing Game * 00003 * * 00004 * Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team * 00005 * * 00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game) * 00007 * and Crossfire (Multiplayer game for X-windows). * 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 * This program is distributed in the hope that it will be useful, * 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00017 * GNU General Public License for more details. * 00018 * * 00019 * You should have received a copy of the GNU General Public License * 00020 * along with this program; if not, write to the Free Software * 00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00022 * * 00023 * The author can be reached at admin@atrinik.org * 00024 ************************************************************************/ 00025 00026 #include <global.h> 00027 #include <check.h> 00028 00029 START_TEST(test_add_ban) 00030 { 00031 fail_if(add_ban(strdup_local("Tester/")) == 1, "Successfully added a ban with add_ban() but no IP was entered."); 00032 remove_ban(strdup_local("Tester/")); 00033 00034 fail_if(add_ban(strdup_local("Tester/:")) == 1, "Successfully added a ban with add_ban() but no IP was entered except a colon."); 00035 remove_ban(strdup_local("Tester/:")); 00036 00037 fail_if(add_ban(strdup_local("Tester/:xxx.x.x.x")) == 0, "Failed to add a new ban with add_ban()."); 00038 remove_ban(strdup_local("Tester/:xxx.x.x.x")); 00039 00040 fail_if(add_ban(strdup_local("Tester/:xxx.x.x.x:11")) == 1, "Successfully added a new ban with add_ban(), but the IP had colons in it."); 00041 remove_ban(strdup_local("Tester/:xxx.x.x.x:11")); 00042 } 00043 END_TEST 00044 00045 START_TEST(test_checkbanned) 00046 { 00047 add_ban(strdup_local("Noob/:127.0.0.1")); 00048 fail_if(checkbanned(add_string("Noob/"), "127.0.0.1") == 0, "checkbanned() failed to match a previously banned name and IP."); 00049 remove_ban(strdup_local("Noob/:127.0.0.1")); 00050 00051 add_ban(strdup_local("Tester/:*")); 00052 fail_if(checkbanned(add_string("Tester/"), "127.2.0.1") == 0, "checkbanned() failed to match a previously banned name."); 00053 remove_ban(strdup_local("Tester/:*")); 00054 00055 add_ban(strdup_local("*:xxx.xxx.xxx")); 00056 fail_if(checkbanned(NULL, "xxx.xxx.xxx") == 0, "checkbanned() failed to match a previously banned IP."); 00057 remove_ban(strdup_local("*:xxx.xxx.xxx")); 00058 00059 fail_if(checkbanned(NULL, "10543./4t5vr.3546") == 1, "checkbanned() returned 1 for an IP that was not previously banned."); 00060 } 00061 END_TEST 00062 00063 START_TEST(test_remove_ban) 00064 { 00065 add_ban(strdup_local("Tester/:xxx.x.x.x")); 00066 fail_if(remove_ban(strdup_local("Tester/:xxx.x.x.x")) == 0, "remove_ban() failed to remove previously added ban."); 00067 00068 fail_if(remove_ban(strdup_local("Tester~$#@:127.0.0.1")) == 1, "remove_ban() managed to remove nonexistent ban."); 00069 } 00070 END_TEST 00071 00072 static Suite *ban_suite() 00073 { 00074 Suite *s = suite_create("ban"); 00075 TCase *tc_core = tcase_create("Core"); 00076 00077 tcase_add_checked_fixture(tc_core, NULL, NULL); 00078 00079 suite_add_tcase(s, tc_core); 00080 tcase_add_test(tc_core, test_add_ban); 00081 tcase_add_test(tc_core, test_remove_ban); 00082 tcase_add_test(tc_core, test_checkbanned); 00083 00084 return s; 00085 } 00086 00087 void check_server_ban() 00088 { 00089 Suite *s = ban_suite(); 00090 SRunner *sr = srunner_create(s); 00091 00092 srunner_set_xml(sr, "unit/server/ban.xml"); 00093 srunner_set_log(sr, "unit/server/ban.out"); 00094 srunner_run_all(sr, CK_ENV); 00095 srunner_ntests_failed(sr); 00096 srunner_free(sr); 00097 }
1.7.4