diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:40 +0000 |
commit | fc53809803cd2bc2434e312b19a18fa36776da12 (patch) | |
tree | b4b43bd6538f51965ce32856e9c053d0f90919c8 /src/resolve/test-resolved-packet.c | |
parent | Adding upstream version 255.5. (diff) | |
download | systemd-fc53809803cd2bc2434e312b19a18fa36776da12.tar.xz systemd-fc53809803cd2bc2434e312b19a18fa36776da12.zip |
Adding upstream version 256.upstream/256
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/resolve/test-resolved-packet.c | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/src/resolve/test-resolved-packet.c b/src/resolve/test-resolved-packet.c index dd8c969..8a65ea0 100644 --- a/src/resolve/test-resolved-packet.c +++ b/src/resolve/test-resolved-packet.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "hexdecoct.h" #include "log.h" #include "resolved-dns-packet.h" #include "tests.h" @@ -23,4 +24,190 @@ TEST(dns_packet_new) { assert_se(dns_packet_new(&p2, DNS_PROTOCOL_DNS, DNS_PACKET_SIZE_MAX + 1, DNS_PACKET_SIZE_MAX) == -EFBIG); } +TEST(naptr) { + _cleanup_(dns_packet_unrefp) DnsPacket *p = NULL; + + static const char twilio_reply[] = + "Sq+BgAABAAkAAAABBnR3aWxpbwNjb20AACMAAcAMACMAAQAABwgAMgAUAAoBUwdTSVArRDJUAARf" + "c2lwBF90Y3AEcHN0bgdpZTEtdG54BnR3aWxpbwNjb20AwAwAIwABAAAHCAAyAAoACgFTB1NJUCtE" + "MlUABF9zaXAEX3VkcARwc3RuB3VzMi10bngGdHdpbGlvA2NvbQDADAAjAAEAAAcIADQAFAAKAVMI" + "U0lQUytEMlQABV9zaXBzBF90Y3AEcHN0bgd1czEtdG54BnR3aWxpbwNjb20AwAwAIwABAAAHCAAy" + "AAoACgFTB1NJUCtEMlUABF9zaXAEX3VkcARwc3RuB2llMS10bngGdHdpbGlvA2NvbQDADAAjAAEA" + "AAcIADIAFAAKAVMHU0lQK0QyVAAEX3NpcARfdGNwBHBzdG4HdXMyLXRueAZ0d2lsaW8DY29tAMAM" + "ACMAAQAABwgANAAUAAoBUwhTSVBTK0QyVAAFX3NpcHMEX3RjcARwc3RuB3VzMi10bngGdHdpbGlv" + "A2NvbQDADAAjAAEAAAcIADQAFAAKAVMIU0lQUytEMlQABV9zaXBzBF90Y3AEcHN0bgdpZTEtdG54" + "BnR3aWxpbwNjb20AwAwAIwABAAAHCAAyAAoACgFTB1NJUCtEMlUABF9zaXAEX3VkcARwc3RuB3Vz" + "MS10bngGdHdpbGlvA2NvbQDADAAjAAEAAAcIADIAFAAKAVMHU0lQK0QyVAAEX3NpcARfdGNwBHBz" + "dG4HdXMxLXRueAZ0d2lsaW8DY29tAAAAKQIAAAAAAAAA"; + + static const char twilio_reply_string[] = + "20 10 \"S\" \"SIP+D2T\" \"\" _sip._tcp.pstn.ie1-tnx.twilio.com.\n" + "10 10 \"S\" \"SIP+D2U\" \"\" _sip._udp.pstn.us2-tnx.twilio.com.\n" + "20 10 \"S\" \"SIPS+D2T\" \"\" _sips._tcp.pstn.us1-tnx.twilio.com.\n" + "10 10 \"S\" \"SIP+D2U\" \"\" _sip._udp.pstn.ie1-tnx.twilio.com.\n" + "20 10 \"S\" \"SIP+D2T\" \"\" _sip._tcp.pstn.us2-tnx.twilio.com.\n" + "20 10 \"S\" \"SIPS+D2T\" \"\" _sips._tcp.pstn.us2-tnx.twilio.com.\n" + "20 10 \"S\" \"SIPS+D2T\" \"\" _sips._tcp.pstn.ie1-tnx.twilio.com.\n" + "10 10 \"S\" \"SIP+D2U\" \"\" _sip._udp.pstn.us1-tnx.twilio.com.\n" + "20 10 \"S\" \"SIP+D2T\" \"\" _sip._tcp.pstn.us1-tnx.twilio.com.\n"; + + static const char twilio_reply_json[] = + "[\n" + " {\n" + " \"key\" : {\n" + " \"class\" : 1,\n" + " \"type\" : 35,\n" + " \"name\" : \"twilio.com\"\n" + " },\n" + " \"order\" : 20,\n" + " \"preference\" : 10,\n" + " \"naptrFlags\" : \"S\",\n" + " \"services\" : \"SIP+D2T\",\n" + " \"regexp\" : \"\",\n" + " \"replacement\" : \"_sip._tcp.pstn.ie1-tnx.twilio.com\"\n" + " },\n" + " {\n" + " \"key\" : {\n" + " \"class\" : 1,\n" + " \"type\" : 35,\n" + " \"name\" : \"twilio.com\"\n" + " },\n" + " \"order\" : 10,\n" + " \"preference\" : 10,\n" + " \"naptrFlags\" : \"S\",\n" + " \"services\" : \"SIP+D2U\",\n" + " \"regexp\" : \"\",\n" + " \"replacement\" : \"_sip._udp.pstn.us2-tnx.twilio.com\"\n" + " },\n" + " {\n" + " \"key\" : {\n" + " \"class\" : 1,\n" + " \"type\" : 35,\n" + " \"name\" : \"twilio.com\"\n" + " },\n" + " \"order\" : 20,\n" + " \"preference\" : 10,\n" + " \"naptrFlags\" : \"S\",\n" + " \"services\" : \"SIPS+D2T\",\n" + " \"regexp\" : \"\",\n" + " \"replacement\" : \"_sips._tcp.pstn.us1-tnx.twilio.com\"\n" + " },\n" + " {\n" + " \"key\" : {\n" + " \"class\" : 1,\n" + " \"type\" : 35,\n" + " \"name\" : \"twilio.com\"\n" + " },\n" + " \"order\" : 10,\n" + " \"preference\" : 10,\n" + " \"naptrFlags\" : \"S\",\n" + " \"services\" : \"SIP+D2U\",\n" + " \"regexp\" : \"\",\n" + " \"replacement\" : \"_sip._udp.pstn.ie1-tnx.twilio.com\"\n" + " },\n" + " {\n" + " \"key\" : {\n" + " \"class\" : 1,\n" + " \"type\" : 35,\n" + " \"name\" : \"twilio.com\"\n" + " },\n" + " \"order\" : 20,\n" + " \"preference\" : 10,\n" + " \"naptrFlags\" : \"S\",\n" + " \"services\" : \"SIP+D2T\",\n" + " \"regexp\" : \"\",\n" + " \"replacement\" : \"_sip._tcp.pstn.us2-tnx.twilio.com\"\n" + " },\n" + " {\n" + " \"key\" : {\n" + " \"class\" : 1,\n" + " \"type\" : 35,\n" + " \"name\" : \"twilio.com\"\n" + " },\n" + " \"order\" : 20,\n" + " \"preference\" : 10,\n" + " \"naptrFlags\" : \"S\",\n" + " \"services\" : \"SIPS+D2T\",\n" + " \"regexp\" : \"\",\n" + " \"replacement\" : \"_sips._tcp.pstn.us2-tnx.twilio.com\"\n" + " },\n" + " {\n" + " \"key\" : {\n" + " \"class\" : 1,\n" + " \"type\" : 35,\n" + " \"name\" : \"twilio.com\"\n" + " },\n" + " \"order\" : 20,\n" + " \"preference\" : 10,\n" + " \"naptrFlags\" : \"S\",\n" + " \"services\" : \"SIPS+D2T\",\n" + " \"regexp\" : \"\",\n" + " \"replacement\" : \"_sips._tcp.pstn.ie1-tnx.twilio.com\"\n" + " },\n" + " {\n" + " \"key\" : {\n" + " \"class\" : 1,\n" + " \"type\" : 35,\n" + " \"name\" : \"twilio.com\"\n" + " },\n" + " \"order\" : 10,\n" + " \"preference\" : 10,\n" + " \"naptrFlags\" : \"S\",\n" + " \"services\" : \"SIP+D2U\",\n" + " \"regexp\" : \"\",\n" + " \"replacement\" : \"_sip._udp.pstn.us1-tnx.twilio.com\"\n" + " },\n" + " {\n" + " \"key\" : {\n" + " \"class\" : 1,\n" + " \"type\" : 35,\n" + " \"name\" : \"twilio.com\"\n" + " },\n" + " \"order\" : 20,\n" + " \"preference\" : 10,\n" + " \"naptrFlags\" : \"S\",\n" + " \"services\" : \"SIP+D2T\",\n" + " \"regexp\" : \"\",\n" + " \"replacement\" : \"_sip._tcp.pstn.us1-tnx.twilio.com\"\n" + " }\n" + "]\n"; + + _cleanup_free_ void *buf = NULL; + size_t sz = 0; + + assert_se(unbase64mem(twilio_reply, &buf, &sz) >= 0); + + assert_se(dns_packet_new(&p, DNS_PROTOCOL_DNS, sz, DNS_PACKET_SIZE_MAX) == 0); + assert_se(p->allocated >= sz); + + memcpy(DNS_PACKET_DATA(p), buf, sz); + p->size = sz; + + assert_se(dns_packet_extract(p) >= 0); + + _cleanup_(json_variant_unrefp) JsonVariant *a = NULL; + _cleanup_free_ char *joined = NULL; + DnsResourceRecord *rr; + DNS_ANSWER_FOREACH(rr, p->answer) { + const char *s; + + s = ASSERT_PTR(dns_resource_record_to_string(rr)); + printf("%s\n", s); + + assert_se(strextend(&joined, s, "\n")); + + _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + assert_se(dns_resource_record_to_json(rr, &v) >= 0); + + assert_se(json_variant_append_array(&a, v) >= 0); + } + + assert(streq(joined, twilio_reply_string)); + + _cleanup_(json_variant_unrefp) JsonVariant *parsed = NULL; + assert_se(json_parse(twilio_reply_json, /* flags= */ 0, &parsed, /* ret_line= */ NULL, /* ret_column= */ NULL) >= 0); + + assert_se(json_variant_equal(parsed, a)); +} + DEFINE_TEST_MAIN(LOG_DEBUG); |