]> git.ipfire.org Git - thirdparty/strongswan.git/blame - src/libcharon/tests/suites/test_proposal.c
ikev2: Respond with NO_PROPOSAL_CHOSEN if proposal without DH group was selected
[thirdparty/strongswan.git] / src / libcharon / tests / suites / test_proposal.c
CommitLineData
aae95101
TB
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
20static struct {
21 char *self;
22 char *other;
23 char *expected;
24} select_data[] = {
25 { "aes128", "aes128", "aes128" },
26 { "aes128", "aes256", NULL },
27 { "aes128-aes256", "aes256-aes128", "aes128" },
28 { "aes256-aes128", "aes128-aes256", "aes256" },
29 { "aes128-aes256-sha1-sha256", "aes256-aes128-sha256-sha1", "aes128-sha1" },
30 { "aes256-aes128-sha256-sha1", "aes128-aes256-sha1-sha256", "aes256-sha256" },
31 { "aes128-sha256-modp3072", "aes128-sha256", NULL },
32 { "aes128-sha256", "aes128-sha256-modp3072", NULL },
33 { "aes128-sha256-modp3072", "aes128-sha256-modpnone", NULL },
34 { "aes128-sha256-modpnone", "aes128-sha256-modp3072", NULL },
35 { "aes128-sha256-modp3072-modpnone", "aes128-sha256", "aes128-sha256" },
36 { "aes128-sha256", "aes128-sha256-modp3072-modpnone", "aes128-sha256" },
37 { "aes128-sha256-modp3072-modpnone", "aes128-sha256-modpnone-modp3072", "aes128-sha256-modp3072" },
38 { "aes128-sha256-modpnone-modp3072", "aes128-sha256-modp3072-modpnone", "aes128-sha256-modpnone" },
39};
40
41START_TEST(test_select)
42{
43 proposal_t *self, *other, *selected, *expected;
44
45 self = proposal_create_from_string(PROTO_ESP,
46 select_data[_i].self);
47 other = proposal_create_from_string(PROTO_ESP,
48 select_data[_i].other);
49 selected = self->select(self, other, FALSE);
50 if (select_data[_i].expected)
51 {
52 expected = proposal_create_from_string(PROTO_ESP,
53 select_data[_i].expected);
54 ck_assert(selected);
55 ck_assert_msg(expected->equals(expected, selected), "proposal %P does "
56 "not match expected %P", selected, expected);
57 expected->destroy(expected);
58 }
59 else
60 {
61 ck_assert(!selected);
62 }
63 DESTROY_IF(selected);
64 other->destroy(other);
65 self->destroy(self);
66}
67END_TEST
68
69Suite *proposal_suite_create()
70{
71 Suite *s;
72 TCase *tc;
73
74 s = suite_create("proposal");
75
76 tc = tcase_create("select");
77 tcase_add_loop_test(tc, test_select, 0, countof(select_data));
78 suite_add_tcase(s, tc);
79
80 return s;
81}