00001 /* 00002 * $Id: test_ksm_request.c 4168 2010-11-04 14:19:59Z sion $ 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_parameter.c - Test Key Parameter Module 00031 * 00032 * Description: 00033 * This is a short test module to check the functions in the Ksm Parameter 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/datetime.h" 00049 #include "test_routines.h" 00050 00051 int l_keytype = -1; 00052 int no_keys = 0; 00053 00054 /* 00055 * TestCallback Function 00056 */ 00057 static int TestCallbackFn(void* context, KSM_KEYDATA* data) 00058 { 00059 fprintf(stderr, "\n"); 00060 fprintf(stderr, "\t\t\t<Key>\n"); 00061 fprintf(stderr, "\t\t\t\t<Flags>%d</Flags>\n", data->keytype); 00062 fprintf(stderr, "\t\t\t\t<Algorithm>%d</Algorithm>\n", data->algorithm); 00063 fprintf(stderr, "\t\t\t\t<Locator>%s</Locator>\n", data->location); 00064 if (data->keytype == KSM_TYPE_KSK) 00065 { 00066 fprintf(stderr, "\t\t\t\t<KSK />\n"); 00067 } 00068 else 00069 { 00070 fprintf(stderr, "\t\t\t\t<ZSK />\n"); 00071 } 00072 fprintf(stderr, "\t\t\t\t<%s />\n", KsmKeywordStateValueToName(data->state)); 00073 fprintf(stderr, "\t\t\t</Key>\n"); 00074 fprintf(stderr, "\n"); 00075 00076 /*printf("%s %lu %d %d %s\n", KsmKeywordStateValueToName(data->state), 00077 data->keypair_id, data->keytype, data->algorithm, data->location); */ 00078 00079 no_keys++; 00080 00081 return 0; 00082 } 00083 00084 00085 /*+ 00086 * TestKsmRequestKeys - Test Request code 00087 * 00088 * Description: 00089 * Tests that a parameter can be set 00090 -*/ 00091 00092 static void TestKsmRequestKeys(void) 00093 { 00094 int keytype = 0; /*KSM_TYPE_ZSK;*/ /* Type of key */ 00095 int rollover = 0; /* Set 1 to roll over the current key */ 00096 int status = 0; 00097 int zone_id = 1; /* opendnssec.org */ 00098 int newDS = 0; 00099 int policy_id = 2; 00100 int sm = 1; /* count over all security modules */ 00101 int bits = 1024; /* count over all sizes */ 00102 int algorithm = KSM_ALGORITHM_RSASHA1; /* count over all algorithms */ 00103 int keypair_id; 00104 DB_ID dnsseckey_id; 00105 00106 char* datetime = DtParseDateTimeString("now"); 00107 00108 /* Allocate a key to the zone (routines previously tested) */ 00109 status = KsmKeyGetUnallocated(policy_id, sm, bits, algorithm, zone_id, 1, &keypair_id); 00110 CU_ASSERT_EQUAL(status, 0); 00111 00112 status = KsmDnssecKeyCreate(zone_id, keypair_id, KSM_TYPE_ZSK, KSM_STATE_GENERATE, datetime, &dnsseckey_id); 00113 CU_ASSERT_EQUAL(status, 0); 00114 00115 /* push the key into some state that update can operate on */ 00116 status = KsmRequestChangeStateN( KSM_TYPE_ZSK, datetime, 1, 00117 KSM_STATE_GENERATE, KSM_STATE_PUBLISH, zone_id); 00118 00119 CU_ASSERT_EQUAL(status, 0); 00120 00121 /* Check that keys of a particular type can be requested */ 00122 KsmRequestKeys(keytype, rollover, datetime, TestCallbackFn, NULL, policy_id, zone_id, 0, &newDS); 00123 00124 /*CU_ASSERT_EQUAL(status, 1);*/ /* just make sure that something flags this as needing more work */ 00125 CU_ASSERT_EQUAL(no_keys, 2); 00126 00127 /* TODO work out some test scenarios here and use Callback to check */ 00128 } 00129 00130 /* 00131 * TestKsmRequest - Create Test Suite 00132 * 00133 * Description: 00134 * Adds the test suite to the CUnit test registry and adds all the tests 00135 * to it. 00136 * 00137 * Arguments: 00138 * None. 00139 * 00140 * Returns: 00141 * int 00142 * Return status. 0 => Success. 00143 */ 00144 00145 int TestKsmRequest(void); /* Declaration */ 00146 int TestKsmRequest(void) 00147 { 00148 struct test_testdef tests[] = { 00149 {"KsmRequest", TestKsmRequestKeys}, 00150 {NULL, NULL} 00151 }; 00152 00153 /* TODO 00154 * have been a bit lazy here and reuse TdbSetup etc... 00155 * this has the consequence of all the setups running for each suite 00156 * if this gets too slow then we will need to separate them out 00157 * */ 00158 return TcuCreateSuite("KsmRequest", TdbSetup, TdbTeardown, tests); 00159 }