aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2022-12-22 17:06:22 +0100
committerOliver Smith <osmith@sysmocom.de>2022-12-23 13:51:22 +0100
commit5decd4971329fded1575e5a6c27efe1680843d64 (patch)
tree72a10e5490d6818a883481074c5ea7aa101d21a8 /tests
parentc5f034b13d8ad88c4c97e1397750e8c9f0b0fff4 (diff)
mslookup: use apn functions from libosmocore
Use the apn functions from libosmocore to encode and decode qnames to avoid code duplication and to avoid unnecessary dynamic allocation. The unit tests for encoding and decoding rfc_question / rfc_record are still passing and have the same output. Fixes: OS#5821 Change-Id: I09d3c617fd6eb4075084ee106d3f3c5803861d2f
Diffstat (limited to 'tests')
-rw-r--r--tests/mslookup/mdns_test.c143
-rw-r--r--tests/mslookup/mdns_test.err82
2 files changed, 0 insertions, 225 deletions
diff --git a/tests/mslookup/mdns_test.c b/tests/mslookup/mdns_test.c
index 7b26f0f..3e5a230 100644
--- a/tests/mslookup/mdns_test.c
+++ b/tests/mslookup/mdns_test.c
@@ -32,148 +32,6 @@ struct qname_enc_dec_test {
size_t qname_max_len; /* default: strlen(qname) + 1 */
};
-static const struct qname_enc_dec_test qname_enc_dec_test_data[] = {
- {
- /* OK: typical mslookup domain */
- .domain = "hlr.1234567.imsi",
- .qname = "\x03" "hlr" "\x07" "1234567" "\x04" "imsi",
- },
- {
- /* Wrong format: double dot */
- .domain = "hlr..imsi",
- .qname = NULL,
- },
- {
- /* Wrong format: double dot */
- .domain = "hlr",
- .qname = "\x03hlr\0\x03imsi",
- },
- {
- /* Wrong format: dot at end */
- .domain = "hlr.",
- .qname = NULL,
- },
- {
- /* Wrong format: dot at start */
- .domain = ".hlr",
- .qname = NULL,
- },
- {
- /* Wrong format: empty */
- .domain = "",
- .qname = NULL,
- },
- {
- /* OK: maximum length */
- .domain =
- "123456789." "123456789." "123456789." "123456789." "123456789."
- "123456789." "123456789." "123456789." "123456789." "123456789."
- "123456789." "123456789." "123456789." "123456789." "123456789."
- "123456789." "123456789." "123456789." "123456789." "123456789."
- "123456789." "123456789." "123456789." "123456789." "123456789."
- "12345"
- ,
- .qname =
- "\t123456789\t123456789\t123456789\t123456789\t123456789"
- "\t123456789\t123456789\t123456789\t123456789\t123456789"
- "\t123456789\t123456789\t123456789\t123456789\t123456789"
- "\t123456789\t123456789\t123456789\t123456789\t123456789"
- "\t123456789\t123456789\t123456789\t123456789\t123456789"
- "\x05" "12345"
- },
- {
- /* Error: too long domain */
- .domain =
- "123456789." "123456789." "123456789." "123456789." "123456789."
- "123456789." "123456789." "123456789." "123456789." "123456789."
- "123456789." "123456789." "123456789." "123456789." "123456789."
- "123456789." "123456789." "123456789." "123456789." "123456789."
- "123456789." "123456789." "123456789." "123456789." "123456789."
- "12345toolong"
- ,
- .qname = NULL,
- },
- {
- /* Error: too long qname */
- .domain = NULL,
- .qname =
- "\t123456789\t123456789\t123456789\t123456789\t123456789"
- "\t123456789\t123456789\t123456789\t123456789\t123456789"
- "\t123456789\t123456789\t123456789\t123456789\t123456789"
- "\t123456789\t123456789\t123456789\t123456789\t123456789"
- "\t123456789\t123456789\t123456789\t123456789\t123456789"
- "\t123456789\t123456789\t123456789\t123456789\t123456789"
- },
- {
- /* Error: wrong token length in qname */
- .domain = NULL,
- .qname = "\x03" "hlr" "\x07" "1234567" "\x05" "imsi",
- },
- {
- /* Error: wrong token length in qname */
- .domain = NULL,
- .qname = "\x02" "hlr" "\x07" "1234567" "\x04" "imsi",
- },
- {
- /* Wrong format: token length at end of qname */
- .domain = NULL,
- .qname = "\x03hlr\x03",
- },
- {
- /* Error: overflow in label length */
- .domain = NULL,
- .qname = "\x03" "hlr" "\x07" "1234567" "\x04" "imsi",
- .qname_max_len = 17,
- },
-};
-
-void test_enc_dec_rfc_qname(void *ctx)
-{
- char quote_buf[300];
- int i;
-
- fprintf(stderr, "-- %s --\n", __func__);
-
- for (i = 0; i < ARRAY_SIZE(qname_enc_dec_test_data); i++) {
- const struct qname_enc_dec_test *t = &qname_enc_dec_test_data[i];
- char *res;
-
- if (t->domain) {
- fprintf(stderr, "domain: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), t->domain, -1));
- fprintf(stderr, "exp: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), t->qname, -1));
- res = osmo_mdns_rfc_qname_encode(ctx, t->domain);
- fprintf(stderr, "res: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), res, -1));
- if (t->qname == res || (t->qname && res && strcmp(t->qname, res) == 0))
- fprintf(stderr, "=> OK\n");
- else
- fprintf(stderr, "=> ERROR\n");
- if (res)
- talloc_free(res);
- fprintf(stderr, "\n");
- }
-
- if (t->qname) {
- size_t qname_max_len = t->qname_max_len;
- if (qname_max_len)
- fprintf(stderr, "qname_max_len: %lu\n", qname_max_len);
- else
- qname_max_len = strlen(t->qname) + 1;
-
- fprintf(stderr, "qname: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), t->qname, -1));
- fprintf(stderr, "exp: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), t->domain, -1));
- res = osmo_mdns_rfc_qname_decode(ctx, t->qname, qname_max_len);
- fprintf(stderr, "res: %s\n", osmo_quote_str_buf2(quote_buf, sizeof(quote_buf), res, -1));
- if (t->domain == res || (t->domain && res && strcmp(t->domain, res) == 0))
- fprintf(stderr, "=> OK\n");
- else
- fprintf(stderr, "=> ERROR\n");
- if (res)
- talloc_free(res);
- fprintf(stderr, "\n");
- }
- }
-}
-
#define PRINT_HDR(hdr, name) \
fprintf(stderr, "header %s:\n" \
".id = %i\n" \
@@ -589,7 +447,6 @@ int main(int argc, char **argv)
log_set_print_category_hex(osmo_stderr_target, 0);
log_set_use_color(osmo_stderr_target, 0);
- test_enc_dec_rfc_qname(ctx);
test_enc_dec_rfc_header();
test_enc_dec_rfc_header_einval();
test_enc_dec_rfc_question(ctx);
diff --git a/tests/mslookup/mdns_test.err b/tests/mslookup/mdns_test.err
index 51e5afe..0d650be 100644
--- a/tests/mslookup/mdns_test.err
+++ b/tests/mslookup/mdns_test.err
@@ -1,85 +1,3 @@
--- test_enc_dec_rfc_qname --
-domain: "hlr.1234567.imsi"
-exp: "\3hlr\a1234567\4imsi"
-res: "\3hlr\a1234567\4imsi"
-=> OK
-
-qname: "\3hlr\a1234567\4imsi"
-exp: "hlr.1234567.imsi"
-res: "hlr.1234567.imsi"
-=> OK
-
-domain: "hlr..imsi"
-exp: NULL
-res: NULL
-=> OK
-
-domain: "hlr"
-exp: "\3hlr"
-res: "\3hlr"
-=> OK
-
-qname: "\3hlr"
-exp: "hlr"
-res: "hlr"
-=> OK
-
-domain: "hlr."
-exp: NULL
-res: NULL
-=> OK
-
-domain: ".hlr"
-exp: NULL
-res: NULL
-=> OK
-
-domain: ""
-exp: NULL
-res: NULL
-=> OK
-
-domain: "123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.12345"
-exp: "\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\512345"
-res: "\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\512345"
-=> OK
-
-qname: "\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\512345"
-exp: "123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.12345"
-res: "123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.12345"
-=> OK
-
-domain: "123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.12345toolong"
-exp: NULL
-res: NULL
-=> OK
-
-qname: "\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\t123456789\
-exp: NULL
-res: NULL
-=> OK
-
-qname: "\3hlr\a1234567\5imsi"
-exp: NULL
-res: NULL
-=> OK
-
-qname: "\2hlr\a1234567\4imsi"
-exp: NULL
-res: NULL
-=> OK
-
-qname: "\3hlr\3"
-exp: NULL
-res: NULL
-=> OK
-
-qname_max_len: 17
-qname: "\3hlr\a1234567\4imsi"
-exp: NULL
-res: NULL
-=> OK
-
-- test_enc_dec_rfc_header --
header in:
.id = 1337