Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

markdownImages.test.ts

41 lines1.5 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { classifyMarkdownImageSource } from "./markdownImages.js";
4​
5describe("classifyMarkdownImageSource", () => {
6 it.each([
7 ["images/result.png", "/workspace/project", "/workspace/project/images/result.png"],
8 [
9 "images\\result.png",
10 "C:\\Users\\dara\\project",
11 "C:\\Users\\dara\\project\\images\\result.png",
12 ],
13 ["file:///workspace/project/image%20one.png", null, "/workspace/project/image one.png"],
14 ["file://server/share/image.png", "\\\\server\\share", "\\\\server\\share\\image.png"],
15 ])("maps %s to a workspace file", (source, workspaceRoot, path) => {
16 expect(classifyMarkdownImageSource(source, workspaceRoot)).toEqual({
17 _tag: "WorkspaceFile",
18 path,
19 });
20 });
21​
22 it.each(["image.png", "javascript:alert(1)", "file://%"])(
23 "blocks unsupported or unresolved source %s",
24 (source) => {
25 expect(classifyMarkdownImageSource(source)).toEqual({ _tag: "Blocked" });
26 },
27 );
28​
29 // Loading these makes Windows send the user's NTLM credentials to the named host.
30 it.each([
31 "file://attacker.test/share/cat.jpg",
32 "\\\\attacker.test\\share\\cat.jpg",
33 "/\\attacker.test\\share\\cat.jpg",
34 "file:/%5Cattacker.test%5Cshare%5Ccat.jpg",
35 "\\\\server\\other\\cat.jpg",
36 ])("blocks network path %s outside the project", (source) => {
37 expect(classifyMarkdownImageSource(source, "\\\\server\\share\\project")).toEqual({
38 _tag: "Blocked",
39 });
40 });
41});