-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsecurity-surface.test.ts
More file actions
132 lines (117 loc) · 4.11 KB
/
Copy pathsecurity-surface.test.ts
File metadata and controls
132 lines (117 loc) · 4.11 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { readFileSync, readdirSync } from "node:fs";
import { describe, expect, it } from "vitest";
interface FooterLink {
readonly href: string;
readonly label: string;
}
interface DocsConfig {
readonly footer?: {
readonly links?: readonly {
readonly header: string;
readonly items: readonly FooterLink[];
}[];
};
readonly redirects?: readonly {
readonly destination: string;
readonly source: string;
}[];
}
const OWNERSHIP_TOKEN = "uda1iefj0dc1wig4yb4c3afl2m35st1ox7rufm0q4ljla00rmzazwhuyjvlgnzp2";
function docsConfig(): DocsConfig {
return JSON.parse(readFileSync("docs.json", "utf8")) as DocsConfig;
}
describe("public security guidance", (): void => {
it("keeps owner verification and security contacts discoverable", (): void => {
expect.assertions(10);
const config = docsConfig();
const trustLinks = config.footer?.links?.find(
(group): boolean => group.header === "Trust & support",
)?.items;
const securityPage = readFileSync("security.mdx", "utf8");
const securityText = readFileSync("security.txt", "utf8");
expect(config.redirects).toContainEqual({
source: "/.well-known/security.txt",
destination: "/security.txt",
});
expect(config.redirects).toContainEqual({
source: "/",
destination: "/api-reference/overview",
});
expect(config.redirects).toContainEqual({
source: "/introduction",
destination: "/api-reference/overview",
});
expect(trustLinks).toStrictEqual([
{ label: "Security", href: "/security" },
{ label: "Support", href: "mailto:support@xquik.com" },
{ label: "Privacy", href: "https://xquik.com/en/privacy" },
{ label: "Terms", href: "https://xquik.com/en/terms" },
]);
expect(securityText).toContain("Contact: mailto:security@xquik.com\n");
expect(securityText).toContain("Policy: https://docs.xquik.com/security\n");
expect(securityPage).toContain("[security@xquik.com](mailto:security@xquik.com)");
expect(securityPage).toContain(
"https://github.com/Xquik-dev/xquik-docs/security/advisories/new",
);
expect(securityPage).toContain("Progress updates at least every 14 days");
expect(
readFileSync(
"gridinsoft-uda1iefj0dc1wig4yb4c3afl2m35st1ox7rufm0q4ljla00rmzazwhuyjvlgnzp2.txt",
"utf8",
).trim(),
).toBe(OWNERSHIP_TOKEN);
});
it("keeps renamed SEO routes redirected to specific keyword slugs", (): void => {
expect.assertions(1);
expect(docsConfig().redirects).toEqual(
expect.arrayContaining([
{
source: "/quickstart",
destination: "/x-api-quickstart",
},
{
source: "/guides/read-data-richness",
destination: "/guides/tweet-profile-api-fields",
},
{
source: "/guides/tweet-search-export",
destination: "/guides/tweet-scraper-csv-export",
},
{
source: "/guides/types",
destination: "/guides/x-api-typescript-types",
},
{
source: "/mpp/overview",
destination: "/mpp/machine-payments-protocol",
},
{
source: "/sdks/csharp",
destination: "/sdks/csharp-x-api-sdk",
},
]),
);
});
it("normalizes trailing slashes on nested documentation URLs", (): void => {
expect.assertions(1);
expect(docsConfig().redirects).toEqual(
expect.arrayContaining([
{
source: "/:section/:slug*/",
destination: "/:section/:slug*",
},
]),
);
});
it("renders alternatives icons without decorative image elements", (): void => {
expect.assertions(3);
const alternatives = readdirSync("alternatives")
.filter((file): boolean => file.endsWith(".mdx"))
.map((file): string => readFileSync(`alternatives/${file}`, "utf8"))
.join("\n");
const overview = readFileSync("twitter-api-alternatives.mdx", "utf8");
expect(JSON.stringify(docsConfig())).not.toContain("/logo/x-only.svg");
expect(overview).not.toContain('icon="/logo/x-only.svg"');
expect(alternatives).not.toContain('icon="/logo/x-only.svg"');
});
});