OpenDNSSEC-enforcer
1.3.8
|
00001 /* 00002 * $Id$ 00003 * 00004 * Copyright (c) 2008-2009 Nominet UK. All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 00015 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00016 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00017 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00018 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 00019 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00020 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00021 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00023 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00024 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 00025 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 * 00027 */ 00028 00029 /*+ 00030 * Filename: test_ksm_import.c - Test ksm_import Module 00031 * 00032 * Description: 00033 * This is a short test module to check the function in the Ksm Import 00034 * module. 00035 * 00036 * The test program makes use of the CUnit framework, as described in 00037 * http://cunit.sourceforge.net 00038 -*/ 00039 00040 #include <stdlib.h> 00041 #include <stdio.h> 00042 #include <string.h> 00043 #include <time.h> 00044 00045 #include "CUnit/Basic.h" 00046 00047 #include "ksm/ksm.h" 00048 #include "ksm/db_fields.h" 00049 #include "test_routines.h" 00050 00051 00052 /*+ 00053 * TestKsmImportRepository - Test 00054 * 00055 * Description: 00056 * Tests that a) we can create a new repository, and 00057 * b) we can update an existing repository 00058 -*/ 00059 00060 static void TestKsmImportRepository(void) 00061 { 00062 char* sql = NULL; /* SQL query */ 00063 int status = 0; /* Status return */ 00064 int count = 0; /* Do we already have a repository with this name? */ 00065 00066 char* repo_name = "myNewRepo"; 00067 char* repo_capacity = "500"; 00068 00069 /* Show that the repository X doesn't exist */ 00070 sql = DqsCountInit(DB_SECURITY_MODULE_TABLE); 00071 DqsConditionString(&sql, "NAME", DQS_COMPARE_EQ, repo_name, 0); 00072 DqsEnd(&sql); 00073 00074 /* Execute query and free up the query string */ 00075 status = DbIntQuery(DbHandle(), &count, sql); 00076 CU_ASSERT_EQUAL(status, 0); 00077 CU_ASSERT_EQUAL(count, 0); 00078 00079 /* Create X */ 00080 status = KsmImportRepository(repo_name, repo_capacity, 0); 00081 CU_ASSERT_EQUAL(status, 0); 00082 00083 /* Show that the repository X does now exist */ 00084 status = DbIntQuery(DbHandle(), &count, sql); 00085 DqsFree(sql); 00086 CU_ASSERT_EQUAL(status, 0); 00087 CU_ASSERT_EQUAL(count, 1); 00088 00089 /* Get the capacity of X */ 00090 sql = DqsSpecifyInit(DB_SECURITY_MODULE_TABLE,"capacity"); 00091 DqsConditionString(&sql, "name", DQS_COMPARE_EQ, repo_name, 0); 00092 DqsEnd(&sql); 00093 00094 status = DbIntQuery(DbHandle(), &count, sql); 00095 CU_ASSERT_EQUAL(status, 0); 00096 CU_ASSERT_EQUAL(count, 500); 00097 00098 /* update X */ 00099 status = KsmImportRepository(repo_name, "5000", 0); 00100 CU_ASSERT_EQUAL(status, 0); 00101 00102 /* Get the new capacity */ 00103 status = DbIntQuery(DbHandle(), &count, sql); 00104 DqsFree(sql); 00105 CU_ASSERT_EQUAL(status, 0); 00106 CU_ASSERT_EQUAL(count, 5000); 00107 00108 00109 } 00110 00111 /*+ 00112 * TestKsmImportPolicy - Test 00113 * 00114 * Description: 00115 * Tests that we can create a new policy 00116 -*/ 00117 static void TestKsmImportPolicy(void) 00118 { 00119 char* sql = NULL; /* SQL query */ 00120 int status = 0; /* Status return */ 00121 int count = 0; /* Do we already have a repository with this name? */ 00122 00123 char* policy_name = "myNewPolicy"; 00124 char* policy_desc = "Pretty policy"; 00125 00126 /* Show that the policy X doesn't exist */ 00127 sql = DqsCountInit("policies"); 00128 DqsConditionString(&sql, "NAME", DQS_COMPARE_EQ, policy_name, 0); 00129 DqsEnd(&sql); 00130 00131 /* Execute query and free up the query string */ 00132 status = DbIntQuery(DbHandle(), &count, sql); 00133 CU_ASSERT_EQUAL(status, 0); 00134 CU_ASSERT_EQUAL(count, 0); 00135 00136 /* Create X */ 00137 status = KsmImportPolicy(policy_name, policy_desc); 00138 CU_ASSERT_EQUAL(status, 0); 00139 00140 /* Show that the policy X does now exist */ 00141 status = DbIntQuery(DbHandle(), &count, sql); 00142 DqsFree(sql); 00143 CU_ASSERT_EQUAL(status, 0); 00144 CU_ASSERT_EQUAL(count, 1); 00145 } 00146 00147 /*+ 00148 * TestKsmImportZone - Test 00149 * 00150 * Description: 00151 * Tests that a) we can create a new Zone, and 00152 * b) we can update an existing Zone 00153 -*/ 00154 00155 static void TestKsmImportZone(void) 00156 { 00157 char* sql = NULL; /* SQL query */ 00158 int status = 0; /* Status return */ 00159 int count = 0; /* Do we already have a repository with this name? */ 00160 00161 char* zone_name = "myNewZone.test"; 00162 int policy_id = 1; 00163 int new_zone = 0; 00164 00165 /* Show that the Zone X doesn't exist */ 00166 sql = DqsCountInit(DB_ZONE_TABLE); 00167 DqsConditionString(&sql, "NAME", DQS_COMPARE_EQ, zone_name, 0); 00168 DqsEnd(&sql); 00169 00170 /* Execute query and free up the query string */ 00171 status = DbIntQuery(DbHandle(), &count, sql); 00172 CU_ASSERT_EQUAL(status, 0); 00173 CU_ASSERT_EQUAL(count, 0); 00174 00175 /* Create X */ 00176 status = KsmImportZone(zone_name, policy_id, 1, &new_zone, "signconf", "input", "output"); 00177 CU_ASSERT_EQUAL(status, 0); 00178 CU_ASSERT_EQUAL(new_zone, 1); 00179 00180 /* Show that the Zone X does now exist */ 00181 status = DbIntQuery(DbHandle(), &count, sql); 00182 DqsFree(sql); 00183 CU_ASSERT_EQUAL(status, 0); 00184 CU_ASSERT_EQUAL(count, 1); 00185 00186 /* Get the policy of X */ 00187 sql = DqsSpecifyInit(DB_ZONE_TABLE,"policy_id"); 00188 DqsConditionString(&sql, "name", DQS_COMPARE_EQ, zone_name, 0); 00189 DqsEnd(&sql); 00190 00191 status = DbIntQuery(DbHandle(), &count, sql); 00192 CU_ASSERT_EQUAL(status, 0); 00193 CU_ASSERT_EQUAL(count, 1); 00194 00195 /* update X */ 00196 status = KsmImportZone(zone_name, 2, 0, &new_zone, "signconf", "input", "output"); 00197 CU_ASSERT_EQUAL(status, 0); 00198 CU_ASSERT_EQUAL(new_zone, 0); 00199 00200 /* Get the new policy */ 00201 status = DbIntQuery(DbHandle(), &count, sql); 00202 DqsFree(sql); 00203 CU_ASSERT_EQUAL(status, 0); 00204 CU_ASSERT_EQUAL(count, 2); 00205 00206 00207 } 00208 00209 /*+ 00210 * TestKsmSerialIdFromName - Test 00211 * 00212 * Description: 00213 * Tests that a serial id can be returned 00214 -*/ 00215 00216 static void TestKsmSerialIdFromName(void) 00217 { 00218 int status; /* Status return */ 00219 int serial_id; /* returned id */ 00220 00221 char* serial1 = "unixtime"; 00222 char* serial2 = "somethingElse"; 00223 00224 /* get the first repo */ 00225 status = KsmSerialIdFromName(serial1, &serial_id); 00226 CU_ASSERT_EQUAL(status, 0); 00227 CU_ASSERT_EQUAL(serial_id, 1); 00228 00229 /* get the second repo */ 00230 status = KsmSerialIdFromName(serial2, &serial_id); 00231 CU_ASSERT_EQUAL(status, 65557); /* doesn't exist */ 00232 00233 } 00234 00235 /* 00236 * TestKsmImport - Create Test Suite 00237 * 00238 * Description: 00239 * Adds the test suite to the CUnit test registry and adds all the tests 00240 * to it. 00241 * 00242 * Arguments: 00243 * None. 00244 * 00245 * Returns: 00246 * int 00247 * Return status. 0 => Success. 00248 */ 00249 00250 int TestKsmImport(void); /* Declaration */ 00251 int TestKsmImport(void) 00252 { 00253 struct test_testdef tests[] = { 00254 {"KsmImportRepository", TestKsmImportRepository}, 00255 {"KsmImportPolicy", TestKsmImportPolicy}, 00256 {"KsmImportZone", TestKsmImportZone}, 00257 {"KsmSerialIdFromName", TestKsmSerialIdFromName}, 00258 {NULL, NULL} 00259 }; 00260 00261 /* TODO 00262 * have been a bit lazy here and reuse TdbSetup etc... 00263 * this has the consequence of all the setups running for each suite 00264 * if this gets too slow then we will need to separate them out 00265 * */ 00266 return TcuCreateSuite("KsmImport", TdbSetup, TdbTeardown, tests); 00267 }