-
Notifications
You must be signed in to change notification settings - Fork 140
/
Copy pathbasic.test.ts
156 lines (136 loc) · 4.44 KB
/
basic.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import request from "supertest";
import container from "./support/container";
import s3Mock from "./support/s3Mock";
import { describe, expect, test, beforeAll, afterAll } from "@jest/globals";
import { TestConfig, DummyFileList } from "./support/configuration";
const BUCKET_NAME = "bucket-2";
// Config for the running container per test
const testConfig: TestConfig = {
name: "base_test",
image: {
dockerfile: "Dockerfile.oss",
},
container: {
env: {
S3_BUCKET_NAME: BUCKET_NAME,
AWS_ACCESS_KEY_ID: "AKIAIOSFODNN7EXAMPLE",
AWS_SECRET_ACCESS_KEY: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
S3_SERVER: "minio",
S3_SERVER_PORT: "9000",
S3_SERVER_PROTO: "http",
S3_REGION: "us-east-1",
DEBUG: "true",
S3_STYLE: "virtual",
ALLOW_DIRECTORY_LIST: "false",
PROVIDE_INDEX_PAGE: "",
APPEND_SLASH_FOR_POSSIBLE_DIRECTORY: "",
STRIP_LEADING_DIRECTORY_PATH: "",
PREFIX_LEADING_DIRECTORY_PATH: "",
AWS_SIGS_VERSION: "4",
STATIC_SITE_HOSTING: "",
PROXY_CACHE_MAX_SIZE: "10g",
PROXY_CACHE_INACTIVE: "60m",
PROXY_CACHE_VALID_OK: "1h",
PROXY_CACHE_VALID_NOTFOUND: "1m",
PROXY_CACHE_VALID_FORBIDDEN: "30s",
},
},
};
const CONFIG = container.Config(testConfig);
const minioClient = s3Mock.Client(
"localhost",
9090,
"AKIAIOSFODNN7EXAMPLE",
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
);
beforeAll(async () => {
try {
await container.stop(CONFIG);
} catch (e) {
console.log("no container to stop");
}
await s3Mock.ensureBucketWithObjects(minioClient, BUCKET_NAME, files());
await container.build(CONFIG);
await container.start(CONFIG);
});
afterAll(async () => {
await container.stop(CONFIG);
await s3Mock.deleteBucket(minioClient, BUCKET_NAME);
});
describe("Ordinary filenames", () => {
test("simple url", async () => {
const objectPath = "a.txt";
const res = await request(CONFIG.testContainer.baseUrl).get(
`/${objectPath}`,
);
expect(res.statusCode).toBe(200);
expect(res.text).toBe(fileContent(objectPath));
});
test("many params that should be stripped", async () => {
const objectPath = "a.txt";
const res = await request(CONFIG.testContainer.baseUrl)
.get("/a.txt?some=param&that=should&be=stripped#aaah")
.set("accept", "binary/octet-stream");
expect(res.statusCode).toBe(200);
expect(res.text).toBe(fileContent(objectPath));
});
test("with a more complex path", async () => {
const objectPath = "b/c/d.txt";
const res = await request(CONFIG.testContainer.baseUrl)
.get("/b/c/d.txt")
.set("accept", "binary/octet-stream");
expect(res.statusCode).toBe(200);
expect(res.text).toBe(fileContent(objectPath));
});
test("another simple path", async () => {
const objectPath = "b/e.txt";
const res = await request(CONFIG.testContainer.baseUrl)
.get("/b/e.txt")
.set("accept", "binary/octet-stream");
expect(res.statusCode).toBe(200);
expect(res.text).toBe(fileContent(objectPath));
});
test("too many forward slashes", async () => {
const objectPath = "b/e.txt";
const res = await request(CONFIG.testContainer.baseUrl)
.get("/b//e.txt")
.set("accept", "binary/octet-stream");
expect(res.statusCode).toBe(200);
expect(res.text).toBe(fileContent(objectPath));
});
test("very long file name", async () => {
const objectPath =
"a/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.txt";
const res = await request(CONFIG.testContainer.baseUrl)
.get(
"/a/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.txt",
)
.set("accept", "binary/octet-stream");
expect(res.statusCode).toBe(200);
expect(res.text).toBe(fileContent(objectPath));
});
});
function fileContent(key: string): string | undefined {
return files()[key]?.content;
}
function files(): DummyFileList {
return {
"a.txt": {
content: "Let go, or be dragged.",
},
"b/c/d.txt": {
content: `When thoughts arise, then do all things arise. When thoughts vanish, then do all things vanish.`,
},
"b/e.txt": {
content: "If only you could hear the sound of snow.",
},
"a/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.txt": {
content: `
"Where the is not one thing, what then?"
"Throw it away!"
"With not one thing, what there is to throw away?"
"Then carry it off!"
`,
},
};
}