OpenDNSSEC-enforcer  1.4.5
test_ksm_request.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_parameter.c - Test Key Parameter Module
29  *
30  * Description:
31  * This is a short test module to check the functions in the Ksm Parameter
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 int l_keytype = -1;
50 int no_keys = 0;
51 
52 /*
53  * TestCallback Function
54  */
55 static int TestCallbackFn(void* context, KSM_KEYDATA* data)
56 {
57  fprintf(stderr, "\n");
58  fprintf(stderr, "\t\t\t<Key>\n");
59  fprintf(stderr, "\t\t\t\t<Flags>%d</Flags>\n", data->keytype);
60  fprintf(stderr, "\t\t\t\t<Algorithm>%d</Algorithm>\n", data->algorithm);
61  fprintf(stderr, "\t\t\t\t<Locator>%s</Locator>\n", data->location);
62  if (data->keytype == KSM_TYPE_KSK)
63  {
64  fprintf(stderr, "\t\t\t\t<KSK />\n");
65  }
66  else
67  {
68  fprintf(stderr, "\t\t\t\t<ZSK />\n");
69  }
70  fprintf(stderr, "\t\t\t\t<%s />\n", KsmKeywordStateValueToName(data->state));
71  fprintf(stderr, "\t\t\t</Key>\n");
72  fprintf(stderr, "\n");
73 
74  /*printf("%s %lu %d %d %s\n", KsmKeywordStateValueToName(data->state),
75  data->keypair_id, data->keytype, data->algorithm, data->location); */
76 
77  no_keys++;
78 
79  return 0;
80 }
81 
82 
83 /*+
84  * TestKsmRequestKeys - Test Request code
85  *
86  * Description:
87  * Tests that a parameter can be set
88 -*/
89 
90 static void TestKsmRequestKeys(void)
91 {
92  int keytype = 0; /*KSM_TYPE_ZSK;*/ /* Type of key */
93  int rollover = 0; /* Set 1 to roll over the current key */
94  int status = 0;
95  int zone_id = 1; /* opendnssec.org */
96  int newDS = 0;
97  int policy_id = 2;
98  int sm = 1; /* count over all security modules */
99  int bits = 1024; /* count over all sizes */
100  int algorithm = KSM_ALGORITHM_RSASHA1; /* count over all algorithms */
101  int keypair_id;
102  DB_ID dnsseckey_id;
103 
104  char* datetime = DtParseDateTimeString("now");
105 
106  /* Allocate a key to the zone (routines previously tested) */
107  status = KsmKeyGetUnallocated(policy_id, sm, bits, algorithm, zone_id, 1, &keypair_id);
108  CU_ASSERT_EQUAL(status, 0);
109 
110  status = KsmDnssecKeyCreate(zone_id, keypair_id, KSM_TYPE_ZSK, KSM_STATE_GENERATE, datetime, NULL, &dnsseckey_id);
111  CU_ASSERT_EQUAL(status, 0);
112 
113  /* push the key into some state that update can operate on */
114  status = KsmRequestChangeStateN( KSM_TYPE_ZSK, datetime, 1,
116 
117  CU_ASSERT_EQUAL(status, 0);
118 
119  /* Check that keys of a particular type can be requested */
120  KsmRequestKeys(keytype, rollover, datetime, TestCallbackFn, NULL, policy_id, zone_id, 0, &newDS);
121 
122  /*CU_ASSERT_EQUAL(status, 1);*/ /* just make sure that something flags this as needing more work */
123  CU_ASSERT_EQUAL(no_keys, 2);
124 
125  /* TODO work out some test scenarios here and use Callback to check */
126 }
127 
128 /*
129  * TestKsmRequest - Create Test Suite
130  *
131  * Description:
132  * Adds the test suite to the CUnit test registry and adds all the tests
133  * to it.
134  *
135  * Arguments:
136  * None.
137  *
138  * Returns:
139  * int
140  * Return status. 0 => Success.
141  */
142 
143 int TestKsmRequest(void); /* Declaration */
144 int TestKsmRequest(void)
145 {
146  struct test_testdef tests[] = {
147  {"KsmRequest", TestKsmRequestKeys},
148  {NULL, NULL}
149  };
150 
151  /* TODO
152  * have been a bit lazy here and reuse TdbSetup etc...
153  * this has the consequence of all the setups running for each suite
154  * if this gets too slow then we will need to separate them out
155  * */
156  return TcuCreateSuite("KsmRequest", TdbSetup, TdbTeardown, tests);
157 }