awl/tests/query_test.ts
Sam Therapy 2b7cd9ea73
Some checks failed
continuous-integration/drone/push Build is failing
Untested: add wild domain parsing
Signed-off-by: Sam Therapy <sam@samtherapy.net>
2022-06-19 15:51:14 +02:00

59 lines
1.8 KiB
TypeScript

// SPDX-License-Identifier: MIT
import { assertEquals } from "./testDeps.ts";
import { doQuery } from "../lib/query.ts";
Deno.test("Get localhost", async () => {
const res = await doQuery("localhost", "A");
assertEquals(res.dnsResponse, ["127.0.0.1"]);
assertEquals(res.response, "NOERROR");
});
Deno.test("Get localhost, external NS", async () => {
const res = await doQuery("localhost", "AAAA", { server: "1.1.1.1" });
assertEquals(res.dnsResponse, ["::1"]);
assertEquals(res.response, "NOERROR");
});
Deno.test("PTR localhost", async () => {
const res = await doQuery("1.0.0.127.in-addr.arpa.", "PTR");
assertEquals(res.dnsResponse, ["localhost."]);
});
// This test will fail if this random Bri ish phone number goes down
// It's also unreliable, so it's disabled
// Deno.test("NAPTR, Remote",async () => {
// const res = await doQuery("4.4.2.2.3.3.5.6.8.1.4.4.e164.arpa.", "NAPTR");
// assertStrictEquals(res.dnsResponse, [
// {
// order: 100,
// preference: 10,
// flags: "u",
// services: "E2U+sip",
// regexp: "!^\\+441865332(.*)$!sip:\\1@nominet.org.uk!",
// replacement: "."
// },
// {
// order: 100,
// preference: 20,
// flags: "u",
// services: "E2U+pstn:tel",
// regexp: "!^(.*)$!tel:\\1!",
// replacement: "."
// }
// ])
// })
Deno.test("Get invalid IP, regular NS", async () => {
const res = await doQuery("l", "A");
assertEquals(res.dnsResponse, undefined);
assertEquals(res.response, "NXDOMAIN");
});
// This isn't supposed to SERVFAIL
// It also takes forever
Deno.test("Get invalid IP, external NS", async () => {
const res = await doQuery("b", "AAAA", { server: "1.1.1.1" });
assertEquals(res.dnsResponse, undefined);
assertEquals(res.response, "SERVFAIL");
});