OpenDNSSEC-enforcer  1.3.14
test_ksm_update.c
Go to the documentation of this file.
1 /*
2  * $Id: test_ksm_update.c 5838 2011-11-08 14:28:05Z sion $
3  *
4  * Copyright (c) 2008-2009 Nominet UK. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 /*+
30  * Filename: test_ksm_update.c - Test Key update Module
31  *
32  * Description:
33  * This is a short test module to check the functions in the Ksm update
34  * module.
35  *
36  * The test program makes use of the CUnit framework, as described in
37  * http://cunit.sourceforge.net
38 -*/
39 
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <time.h>
44 
45 #include "CUnit/Basic.h"
46 
47 #include "ksm/ksm.h"
48 #include "ksm/datetime.h"
49 #include "test_routines.h"
50 
51 
52 /*+
53  * TestKsmUpdateInternal - Test Update code
54  *
55  * Description:
56  * Tests that keys times can be updated
57 -*/
58 
59 static void TestKsmUpdateInternal(void)
60 {
61  int status; /* Status return */
62  int policy_id = 2;
63  int zone_id = 1;
64  DB_ID dnsseckey_id; /* Created key ID */
65  char* datetime = DtParseDateTimeString("now");
66 
67  /* Create a new dnsseckeys entry (use our previously tested routines)
68  * keys 3 - 15 are unallocated */
69 
70  status = KsmDnssecKeyCreate(zone_id, 3, KSM_TYPE_ZSK, KSM_STATE_GENERATE, datetime, NULL, &dnsseckey_id);
71  CU_ASSERT_EQUAL(status, 0);
72 
73  /* push a key into some state that update can operate on */
74  status = KsmRequestChangeStateN( KSM_TYPE_ZSK, datetime, 1,
76 
77  CU_ASSERT_EQUAL(status, 0);
78 
79  /* Check that the call works? We get no feedback */
80  status = KsmUpdate(policy_id, zone_id);
81  CU_ASSERT_EQUAL(status, 0); /* not that it can be anything else */
82 
83  /* TODO check the keys have updated */
84 }
85 
86 /*
87  * TestKsmUpdate - Create Test Suite
88  *
89  * Description:
90  * Adds the test suite to the CUnit test registry and adds all the tests
91  * to it.
92  *
93  * Arguments:
94  * None.
95  *
96  * Returns:
97  * int
98  * Return status. 0 => Success.
99  */
100 
101 int TestKsmUpdate(void); /* Declaration */
102 int TestKsmUpdate(void)
103 {
104  struct test_testdef tests[] = {
105  {"KsmUpdate", TestKsmUpdateInternal},
106  {NULL, NULL}
107  };
108 
109  /* TODO
110  * have been a bit lazy here and reuse TdbSetup etc...
111  * this has the consequence of all the setups running for each suite
112  * if this gets too slow then we will need to separate them out
113  * */
114  return TcuCreateSuite("KsmUpdate", TdbSetup, TdbTeardown, tests);
115 }