Skip to content

Commit e762fd2

Browse files
authored
Adds Host Resolver IPv6 variations test (#639)
1 parent 4e0b2e2 commit e762fd2

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ add_test_case(channel_duplicate_shutdown)
9494
add_net_test_case(channel_connect_some_hosts_timeout)
9595

9696
add_net_test_case(test_default_with_ipv6_lookup)
97+
add_net_test_case(test_default_host_resolver_ipv6_address_variations)
9798
add_test_case(test_resolver_ipv6_address_lookup)
9899
add_net_test_case(test_default_with_multiple_lookups)
99100
add_test_case(test_resolver_ipv4_address_lookup)

tests/default_host_resolver_test.c

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,103 @@ static int s_test_default_with_ipv6_lookup_fn(struct aws_allocator *allocator, v
160160

161161
AWS_TEST_CASE(test_default_with_ipv6_lookup, s_test_default_with_ipv6_lookup_fn)
162162

163+
static int s_test_default_host_resolver_ipv6_address_variations_fn(struct aws_allocator *allocator, void *ctx) {
164+
(void)ctx;
165+
166+
aws_io_library_init(allocator);
167+
168+
const struct test_case {
169+
const char *ip_address;
170+
const char *expected_resolved_ip_address;
171+
} test_cases[] = {
172+
/* simple full uri*/
173+
{
174+
.ip_address = "0:0::1",
175+
.expected_resolved_ip_address = "::1",
176+
},
177+
{
178+
.ip_address = "::1",
179+
.expected_resolved_ip_address = "::1",
180+
},
181+
{
182+
.ip_address = "0:0:0:0:0:0:0:1",
183+
.expected_resolved_ip_address = "::1",
184+
},
185+
{
186+
.ip_address = "fd00:ec2:0:0:0:0:0:23",
187+
.expected_resolved_ip_address = "fd00:ec2::23",
188+
},
189+
190+
};
191+
192+
struct aws_event_loop_group *el_group = aws_event_loop_group_new_default(allocator, 1, NULL);
193+
194+
struct aws_host_resolver_default_options resolver_options = {
195+
.el_group = el_group,
196+
.max_entries = 10,
197+
};
198+
struct aws_host_resolver *resolver = aws_host_resolver_new_default(allocator, &resolver_options);
199+
200+
struct aws_host_resolution_config config = {
201+
.max_ttl = 10,
202+
.impl = aws_default_dns_resolve,
203+
.impl_data = NULL,
204+
};
205+
206+
struct aws_mutex mutex = AWS_MUTEX_INIT;
207+
struct default_host_callback_data callback_data = {
208+
.condition_variable = AWS_CONDITION_VARIABLE_INIT,
209+
.invoked = false,
210+
.has_aaaa_address = false,
211+
.has_a_address = false,
212+
.mutex = &mutex,
213+
};
214+
215+
for (size_t case_idx = 0; case_idx < AWS_ARRAY_SIZE(test_cases); ++case_idx) {
216+
struct test_case case_i = test_cases[case_idx];
217+
printf(
218+
"CASE[%zu]: ip_address=%s expected_resolved_ip_address=%s\n, ",
219+
case_idx,
220+
case_i.ip_address,
221+
case_i.expected_resolved_ip_address);
222+
struct aws_string *address = aws_string_new_from_c_str(allocator, case_i.ip_address);
223+
struct aws_string *expected_address = aws_string_new_from_c_str(allocator, case_i.expected_resolved_ip_address);
224+
225+
ASSERT_SUCCESS(aws_host_resolver_resolve_host(
226+
resolver, address, s_default_host_resolved_test_callback, &config, &callback_data));
227+
228+
ASSERT_SUCCESS(aws_mutex_lock(&mutex));
229+
aws_condition_variable_wait_pred(
230+
&callback_data.condition_variable, &mutex, s_default_host_resolved_predicate, &callback_data);
231+
232+
callback_data.invoked = false;
233+
ASSERT_TRUE(callback_data.has_aaaa_address);
234+
ASSERT_INT_EQUALS(AWS_ADDRESS_RECORD_TYPE_AAAA, callback_data.aaaa_address.record_type);
235+
ASSERT_BIN_ARRAYS_EQUALS(
236+
aws_string_bytes(expected_address),
237+
expected_address->len,
238+
aws_string_bytes(callback_data.aaaa_address.address),
239+
callback_data.aaaa_address.address->len);
240+
241+
aws_host_address_clean_up(&callback_data.aaaa_address);
242+
aws_host_address_clean_up(&callback_data.a_address);
243+
ASSERT_SUCCESS(aws_mutex_unlock(&mutex));
244+
aws_string_destroy(address);
245+
aws_string_destroy(expected_address);
246+
}
247+
248+
aws_host_resolver_release(resolver);
249+
aws_event_loop_group_release(el_group);
250+
251+
aws_io_library_clean_up();
252+
253+
return 0;
254+
}
255+
256+
AWS_TEST_CASE(
257+
test_default_host_resolver_ipv6_address_variations,
258+
s_test_default_host_resolver_ipv6_address_variations_fn)
259+
163260
/* just FYI, this test assumes that "s3.us-east-1.amazonaws.com" does not return IPv6 addresses. */
164261
static int s_test_default_with_ipv4_only_lookup_fn(struct aws_allocator *allocator, void *ctx) {
165262
(void)ctx;

0 commit comments

Comments
 (0)