GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — t3code/scripts/mock-update-server.test.ts at main · AndryHTC/t3code

Expand file tree

/

mock-update-server.test.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
83 lines (73 loc) · 3.06 KB
/

mock-update-server.test.ts

Copy path

File metadata and controls

83 lines (73 loc) · 3.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import { NodeHttpServer, NodeServices } from "@effect/platform-node";
import { assert, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Path from "effect/Path";
import { HttpClient, HttpRouter } from "effect/http";
import { makeMockUpdateRouteLayer } from "./mock-update-server.ts";
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const withMockUpdateServer = <A, E, R>(rootRealPath: string, effect: Effect.Effect<A, E, R>) =>
effect.pipe(
Effect.provide(
HttpRouter.serve(makeMockUpdateRouteLayer(rootRealPath), {
disableListenLog: true,
disableLogger: true,
}).pipe(Layer.provideMerge(NodeHttpServer.layerTest)),
),
);
it.layer(NodeServices.layer)("mock-update-server", (it) => {
it.effect("rejects encoded path traversal outside the configured root", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const root = yield* fileSystem.makeTempDirectoryScoped({
prefix: "mock-update-server-root-",
});
const outside = yield* fileSystem.makeTempDirectoryScoped({
prefix: "mock-update-server-outside-",
});
const rootRealPath = yield* fileSystem.realPath(root);
yield* fileSystem.writeFileString(path.join(outside, "secret.txt"), "nope\n");
yield* withMockUpdateServer(
rootRealPath,
Effect.gen(function* () {
const client = yield* HttpClient.HttpClient;
const response = yield* client.get("/%2e%2e/secret.txt");
assert.equal(response.status, 404);
assert.equal(yield* response.text, "Not Found");
}),
);
}),
);
it.effect.skipIf(!symlinksSupported)(
"rejects symlinked files that escape the configured root",
() =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const root = yield* fileSystem.makeTempDirectoryScoped({
prefix: "mock-update-server-root-",
});
const outside = yield* fileSystem.makeTempDirectoryScoped({
prefix: "mock-update-server-outside-",
});
const rootRealPath = yield* fileSystem.realPath(root);
const outsideFile = path.join(outside, "outside.yml");
const linksDir = path.join(root, "links");
const symlinkPath = path.join(linksDir, "outside.yml");
yield* fileSystem.writeFileString(outsideFile, "version: outside\n");
yield* fileSystem.makeDirectory(linksDir, { recursive: true });
yield* fileSystem.symlink(outsideFile, symlinkPath);
yield* withMockUpdateServer(
rootRealPath,
Effect.gen(function* () {
const client = yield* HttpClient.HttpClient;
const response = yield* client.get("/links/outside.yml");
assert.equal(response.status, 404);
assert.equal(yield* response.text, "Not Found");
}),
);
}),
);
});
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.