1 /* Test getaddrinfo and getnameinfo without usable libidn2.
2 Copyright (C) 2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #define TEST_USE_UTF8 1
20 #include "tst-resolv-ai_idn-common.c"
23 #include <support/xdlfcn.h>
25 /* Tests for getaddrinfo. */
30 check_ai ("non-idn.example", 0,
31 "address: STREAM/TCP 192.0.2.110 80\n");
32 check_ai ("non-idn.example", AI_IDN
,
34 "address: STREAM/TCP 192.0.2.110 80\n");
35 check_ai ("non-idn.example", AI_IDN
| AI_CANONNAME
| AI_CANONIDN
,
36 "flags: AI_CANONNAME AI_IDN AI_CANONIDN\n"
37 "canonname: non-idn.example\n"
38 "address: STREAM/TCP 192.0.2.110 80\n");
40 /* This gets passed over the network to the server, so it will
41 result in an NXDOMAIN error. */
42 check_ai (NAEMCHEN
".example", 0,
43 "error: Name or service not known\n");
44 /* Due to missing libidn2, this fails inside getaddrinfo. */
45 check_ai (NAEMCHEN
".example", AI_IDN
,
46 "error: Parameter string not correctly encoded\n");
47 check_ai (NAEMCHEN
".example", AI_IDN
| AI_CANONNAME
| AI_CANONIDN
,
48 "error: Parameter string not correctly encoded\n");
51 check_ai ("with.cname.example", 0,
52 "address: STREAM/TCP 192.0.2.119 80\n");
53 check_ai ("with.cname.example", AI_IDN
,
55 "address: STREAM/TCP 192.0.2.119 80\n");
56 check_ai ("with.cname.example", AI_IDN
| AI_CANONNAME
| AI_CANONIDN
,
57 "flags: AI_CANONNAME AI_IDN AI_CANONIDN\n"
58 "canonname: non-idn-cname.example\n"
59 "address: STREAM/TCP 192.0.2.119 80\n");
62 check_ai ("With.idn-cname.example", 0,
63 "address: STREAM/TCP 192.0.2.87 80\n");
64 check_ai ("With.idn-cname.example", AI_IDN
,
66 "address: STREAM/TCP 192.0.2.87 80\n");
67 check_ai ("With.idn-cname.example", AI_IDN
| AI_CANONNAME
,
68 "flags: AI_CANONNAME AI_IDN\n"
69 "canonname: " ANDERES_NAEMCHEN_IDNA
".example\n"
70 "address: STREAM/TCP 192.0.2.87 80\n");
71 check_ai ("With.idn-cname.example",
72 AI_IDN
| AI_CANONNAME
| AI_CANONIDN
,
73 "flags: AI_CANONNAME AI_IDN AI_CANONIDN\n"
74 "canonname: " ANDERES_NAEMCHEN_IDNA
".example\n"
75 "address: STREAM/TCP 192.0.2.87 80\n");
77 /* Non-IDN to IDN CNAME chain. */
78 check_ai ("both.cname.idn-cname.example", 0,
79 "address: STREAM/TCP 192.0.2.98 80\n");
80 check_ai ("both.cname.idn-cname.example", AI_IDN
,
82 "address: STREAM/TCP 192.0.2.98 80\n");
83 check_ai ("both.cname.idn-cname.example", AI_IDN
| AI_CANONNAME
,
84 "flags: AI_CANONNAME AI_IDN\n"
85 "canonname: " ANDERES_NAEMCHEN_IDNA
".example\n"
86 "address: STREAM/TCP 192.0.2.98 80\n");
87 check_ai ("both.cname.idn-cname.example",
88 AI_IDN
| AI_CANONNAME
| AI_CANONIDN
,
89 "flags: AI_CANONNAME AI_IDN AI_CANONIDN\n"
90 "canonname: " ANDERES_NAEMCHEN_IDNA
".example\n"
91 "address: STREAM/TCP 192.0.2.98 80\n");
94 /* Tests for getnameinfo. */
98 /* All non-IDN an IDN results are the same due to lack of libidn2
100 for (int do_ni_idn
= 0; do_ni_idn
< 2; ++do_ni_idn
)
106 gni_test (gni_non_idn_name
, flags
, "non-idn.example");
107 gni_test (gni_non_idn_name
, flags
| NI_NUMERICHOST
, "192.0.2.0");
108 gni_test (gni_non_idn_cname_to_non_idn_name
, flags
,
109 "non-idn-name.example");
110 gni_test (gni_non_idn_cname_to_idn_name
, flags
,
111 NAEMCHEN_IDNA
".example");
112 gni_test (gni_idn_name
, flags
, NAEMCHEN_IDNA
".example");
113 gni_test (gni_idn_cname_to_non_idn_name
, flags
, "non-idn-name.example");
114 gni_test (gni_idn_cname_to_idn_name
, flags
,
115 ANDERES_NAEMCHEN_IDNA
".example");
117 /* Test encoding errors. */
118 gni_test (gni_invalid_idn_1
, flags
, "xn---.example");
119 gni_test (gni_invalid_idn_2
, flags
, "xn--x.example");
126 void *handle
= xdlopen ("tst-no-libidn2.so", RTLD_LAZY
);
128 /* Verify that this replaced libidn2. */
129 void *handle2
= xdlopen (LIBIDN2_SONAME
, RTLD_LAZY
| RTLD_NOLOAD
);
130 TEST_VERIFY (handle2
== handle
);
134 if (setlocale (LC_CTYPE
, "en_US.UTF-8") == NULL
)
135 FAIL_EXIT1 ("setlocale: %m");
137 struct resolv_test
*aux
= resolv_test_start
138 ((struct resolv_redirect_config
)
140 .response_callback
= response
,
146 resolv_test_end (aux
);
151 #include <support/test-driver.c>