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