proposal: Make DH groups mandatory in IKE proposals parsed from strings
[strongswan.git] / src / libcharon / tests / suites / test_proposal.c
1 /*
2 * Copyright (C) 2016 Tobias Brunner
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "test_suite.h"
17
18 #include <config/proposal.h>
19
20 static struct {
21 protocol_id_t proto;
22 char *self;
23 char *other;
24 char *expected;
25 } select_data[] = {
26 { PROTO_ESP, "aes128", "aes128", "aes128" },
27 { PROTO_ESP, "aes128", "aes256", NULL },
28 { PROTO_ESP, "aes128-aes256", "aes256-aes128", "aes128" },
29 { PROTO_ESP, "aes256-aes128", "aes128-aes256", "aes256" },
30 { PROTO_ESP, "aes128-aes256-sha1-sha256", "aes256-aes128-sha256-sha1", "aes128-sha1" },
31 { PROTO_ESP, "aes256-aes128-sha256-sha1", "aes128-aes256-sha1-sha256", "aes256-sha256" },
32 { PROTO_ESP, "aes128-sha256-modp3072", "aes128-sha256", NULL },
33 { PROTO_ESP, "aes128-sha256", "aes128-sha256-modp3072", NULL },
34 { PROTO_ESP, "aes128-sha256-modp3072", "aes128-sha256-modpnone", NULL },
35 { PROTO_ESP, "aes128-sha256-modpnone", "aes128-sha256-modp3072", NULL },
36 { PROTO_ESP, "aes128-sha256-modp3072-modpnone", "aes128-sha256", "aes128-sha256" },
37 { PROTO_ESP, "aes128-sha256", "aes128-sha256-modp3072-modpnone", "aes128-sha256" },
38 { PROTO_ESP, "aes128-sha256-modp3072-modpnone", "aes128-sha256-modpnone-modp3072", "aes128-sha256-modp3072" },
39 { PROTO_ESP, "aes128-sha256-modpnone-modp3072", "aes128-sha256-modp3072-modpnone", "aes128-sha256-modpnone" },
40 { PROTO_IKE, "aes128", NULL, NULL },
41 { PROTO_IKE, "aes128-sha256", NULL, NULL },
42 { PROTO_IKE, "aes128-sha256-modpnone", NULL, NULL },
43 { PROTO_IKE, "aes128-sha256-modp3072", "aes128-sha256-modp3072", "aes128-sha256-modp3072" },
44 { PROTO_IKE, "aes128-sha256-modp3072", "aes128-sha256-modp3072-modpnone", "aes128-sha256-modp3072" },
45 { PROTO_IKE, "aes128-sha256-modp3072-modpnone", "aes128-sha256-modp3072", "aes128-sha256-modp3072" },
46 };
47
48 START_TEST(test_select)
49 {
50 proposal_t *self, *other, *selected, *expected;
51
52 self = proposal_create_from_string(select_data[_i].proto,
53 select_data[_i].self);
54 if (!select_data[_i].other)
55 {
56 ck_assert(!self);
57 return;
58 }
59 other = proposal_create_from_string(select_data[_i].proto,
60 select_data[_i].other);
61 selected = self->select(self, other, FALSE);
62 if (select_data[_i].expected)
63 {
64 expected = proposal_create_from_string(select_data[_i].proto,
65 select_data[_i].expected);
66 ck_assert(selected);
67 ck_assert_msg(expected->equals(expected, selected), "proposal %P does "
68 "not match expected %P", selected, expected);
69 expected->destroy(expected);
70 }
71 else
72 {
73 ck_assert(!selected);
74 }
75 DESTROY_IF(selected);
76 other->destroy(other);
77 self->destroy(self);
78 }
79 END_TEST
80
81 Suite *proposal_suite_create()
82 {
83 Suite *s;
84 TCase *tc;
85
86 s = suite_create("proposal");
87
88 tc = tcase_create("select");
89 tcase_add_loop_test(tc, test_select, 0, countof(select_data));
90 suite_add_tcase(s, tc);
91
92 return s;
93 }