-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.ts
68 lines (60 loc) · 1.58 KB
/
main_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { assertEquals } from "https://deno.land/std@0.208.0/assert/mod.ts";
import bufferToJSON from "./src/utils/bufferToJSON.ts";
const dnsResponse = {
id: 1,
type: "response",
flags: 384,
flag_qr: true,
opcode: "QUERY",
flag_aa: false,
flag_tc: false,
flag_rd: true,
flag_ra: true,
flag_z: false,
flag_ad: false,
flag_cd: false,
rcode: "NOERROR",
questions: [ { name: "cloudflare.com", type: "A", class: "IN" } ],
answers: [
{
name: "cloudflare.com",
type: "A",
ttl: 300,
class: "IN",
flush: false,
data: "104.16.132.229"
},
{
name: "cloudflare.com",
type: "A",
ttl: 300,
class: "IN",
flush: false,
data: "104.16.133.229"
}
],
authorities: [],
additionals: []
}
Deno.test(async function postResolve() {
const query = {
type: 'query',
id: 1,
flags: 256,
questions: [
{ type: 'A', name: 'cloudflare.com' },
{ type: 'A', name: 'analytics.google.com' }
]
};
const data = JSON.stringify(query);
const body = new TextEncoder().encode(data);
const response = await fetch('http://localhost:3000', { method: 'POST', body })
const buff = await response.arrayBuffer();
assertEquals(dnsResponse, bufferToJSON(buff, null) as any);
});
// Deno.test(async function getResolve() {
// const domainBase64 = btoa('cloudflare.com');
// const response = await fetch('http://localhost:3000/dns-query?dns=' + domainBase64 + '&type=A')
// const data = await response.arrayBuffer();
// assertEquals(dnsResponse, bufferToJSON(data, null) as any);
// });