59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import type { Provenance, QueryRow } from "@/lib/types";
|
|
|
|
/**
|
|
* Fixture builders for the provenance shapes, shared by the query-log, detail
|
|
* and live-stream tests the way `features/activity/fakeEventSource.ts` is shared.
|
|
*
|
|
* The defaults describe the dullest possible query — an allowed name nothing
|
|
* matched, answered upstream — so each test states only the fields it is about.
|
|
*/
|
|
type Sections = {
|
|
[K in keyof Provenance]?: Partial<Provenance[K]>;
|
|
};
|
|
|
|
export function provenance(sections: Sections = {}): Provenance {
|
|
return {
|
|
request: {
|
|
time: 1_700_000_000,
|
|
domain: "example.com",
|
|
client: "192.0.2.10",
|
|
qtype: 1,
|
|
qclass: 1,
|
|
...sections.request,
|
|
},
|
|
group: { id: 1, name: "default", ...sections.group },
|
|
policy: {
|
|
action: "allow",
|
|
reason: "no_match",
|
|
matched: "",
|
|
source_id: null,
|
|
source_name: "",
|
|
...sections.policy,
|
|
},
|
|
rewrites: { cname_target: "", safe_search_target: "", ...sections.rewrites },
|
|
route: { kind: "upstream", forward_zone: "", upstream: "https://dns.example/dns-query", ...sections.route },
|
|
response: { rcode: 0, duration_us: 1234, ...sections.response },
|
|
};
|
|
}
|
|
|
|
/** The flat stored row of the same dull query. */
|
|
export function queryRow(id: number, overrides: Partial<QueryRow> = {}): QueryRow {
|
|
return {
|
|
id,
|
|
ts: 1_700_000_000,
|
|
domain: "example.com",
|
|
client_ip: "192.0.2.10",
|
|
qtype: 1,
|
|
qclass: 1,
|
|
rcode: 0,
|
|
blocked: false,
|
|
response_time_us: 1234,
|
|
cache_hit: false,
|
|
upstream: "https://dns.example/dns-query",
|
|
policy_action: "allow",
|
|
policy_reason: "no_match",
|
|
route_kind: "upstream",
|
|
...overrides,
|
|
};
|
|
}
|