created class init_config_t encapsulating configuration issues of
[strongswan.git] / Source / charon / testcases / init_config_test.c
1 /**
2 * @file init_config_test.c
3 *
4 * @brief Tests for the init_config_t class.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include "init_config_test.h"
24
25 #include <config/init_config.h>
26 #include <utils/allocator.h>
27
28
29 /**
30 * Described in header.
31 */
32 void test_init_config(tester_t *tester)
33 {
34 init_config_t *init_config = init_config_create("192.168.0.1","192.168.0.2",500,500);
35 ike_proposal_t prop1, prop2, prop3, prop4, selected_one;
36 ike_proposal_t *proposal_list;
37 size_t proposal_count;
38 status_t status;
39
40 prop1.encryption_algorithm = ENCR_AES_CBC;
41 prop1.encryption_algorithm_key_length = 20;
42 prop1.integrity_algorithm = AUTH_HMAC_SHA1_96;
43 prop1.integrity_algorithm_key_length = 20;
44 prop1.pseudo_random_function = PRF_HMAC_SHA1;
45 prop1.pseudo_random_function_key_length = 20;
46 prop1.diffie_hellman_group = MODP_2048_BIT;
47
48 prop2 = prop1;
49 prop2.pseudo_random_function = PRF_HMAC_MD5;
50 prop2.diffie_hellman_group = MODP_1024_BIT;
51
52 prop3 = prop1;
53 prop3.encryption_algorithm = ENCR_DES;
54 prop3.diffie_hellman_group = MODP_768_BIT;
55
56 prop4 = prop1;
57
58 prop4.encryption_algorithm = ENCR_3DES;
59 prop4.pseudo_random_function = PRF_HMAC_TIGER;
60
61 init_config->add_proposal(init_config,1,prop1);
62 init_config->add_proposal(init_config,1,prop2);
63 init_config->add_proposal(init_config,3,prop3);
64 init_config->add_proposal(init_config,2,prop4);
65
66 proposal_count = init_config->get_proposals(init_config,&proposal_list);
67
68 tester->assert_true(tester,(proposal_count == 4), "proposal count check ");
69
70 tester->assert_true(tester,(proposal_list[0].encryption_algorithm == ENCR_AES_CBC), "encryption algorithm check 1");
71 tester->assert_true(tester,(proposal_list[0].pseudo_random_function == PRF_HMAC_MD5), "prf check 1");
72
73 tester->assert_true(tester,(proposal_list[1].encryption_algorithm == ENCR_3DES), "encryption algorithm check 2");
74 tester->assert_true(tester,(proposal_list[1].pseudo_random_function == PRF_HMAC_TIGER), "prf check 2");
75
76 tester->assert_true(tester,(proposal_list[2].encryption_algorithm == ENCR_AES_CBC), "encryption algorithm check 3");
77 tester->assert_true(tester,(proposal_list[2].pseudo_random_function == PRF_HMAC_SHA1), "prf check 3");
78
79 tester->assert_true(tester,(proposal_list[3].encryption_algorithm == ENCR_DES), "encryption algorithm check 4");
80 tester->assert_true(tester,(proposal_list[3].pseudo_random_function == PRF_HMAC_SHA1), "prf check 4");
81
82
83
84 /* going to check proposals */
85 status = init_config->select_proposal(init_config,proposal_list,proposal_count,&selected_one);
86 tester->assert_true(tester,(status == SUCCESS), "select proposal call check 1");
87
88 tester->assert_true(tester,(selected_one.encryption_algorithm == ENCR_AES_CBC), "encryption algorithm check");
89 tester->assert_true(tester,(selected_one.pseudo_random_function == PRF_HMAC_MD5), "prf check");
90
91 proposal_list[0].encryption_algorithm = ENCR_DES_IV32;
92
93 status = init_config->select_proposal(init_config,proposal_list,proposal_count,&selected_one);
94 tester->assert_true(tester,(status == SUCCESS), "select proposal call check 2");
95
96 tester->assert_true(tester,(selected_one.encryption_algorithm == ENCR_3DES), "encryption algorithm check");
97 tester->assert_true(tester,(selected_one.pseudo_random_function == PRF_HMAC_TIGER), "prf check");
98
99 proposal_list[1].pseudo_random_function = PRF_AES128_CBC;
100
101 status = init_config->select_proposal(init_config,proposal_list,proposal_count,&selected_one);
102 tester->assert_true(tester,(status == SUCCESS), "select proposal call check 3");
103
104 tester->assert_true(tester,(selected_one.encryption_algorithm == ENCR_AES_CBC), "encryption algorithm check");
105 tester->assert_true(tester,(selected_one.pseudo_random_function == PRF_HMAC_SHA1), "prf check");
106
107 proposal_list[2].pseudo_random_function = PRF_AES128_CBC;
108
109 status = init_config->select_proposal(init_config,proposal_list,proposal_count,&selected_one);
110 tester->assert_true(tester,(status == SUCCESS), "select proposal call check 4");
111
112 tester->assert_true(tester,(selected_one.encryption_algorithm == ENCR_DES), "encryption algorithm check");
113 tester->assert_true(tester,(selected_one.pseudo_random_function == PRF_HMAC_SHA1), "prf check");
114
115 proposal_list[3].pseudo_random_function = PRF_AES128_CBC;
116
117 status = init_config->select_proposal(init_config,proposal_list,proposal_count,&selected_one);
118 tester->assert_true(tester,(status == NOT_FOUND), "select proposal call check 5");
119
120 tester->assert_true(tester,(init_config->get_dh_group_number(init_config,1) == MODP_1024_BIT), "get DH group number call check 1");
121 tester->assert_true(tester,(init_config->get_dh_group_number(init_config,2) == MODP_2048_BIT), "get DH group number call check 2");
122 tester->assert_true(tester,(init_config->get_dh_group_number(init_config,3) == MODP_2048_BIT), "get DH group number call check 3");
123 tester->assert_true(tester,(init_config->get_dh_group_number(init_config,4) == MODP_768_BIT), "get DH group number call check 4");
124
125 allocator_free(proposal_list);
126
127 init_config->destroy(init_config);
128 }