awl/tests/query_test.ts
Sam Therapy 6f4ae7de65
Initial commit
Signed-off-by: Sam Therapy <sam@samtherapy.net>
2022-06-18 20:11:46 +02:00

58 lines
1.7 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
// Deno.test("NAPTR, Remote",async () => {
// const res = await doQuery("4.4.2.2.3.3.5.6.8.1.4.4.e164.arpa.", "NAPTR");
// assertEquals(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 but idk
// 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");
// });