Skip to content

Commit c99f15e

Browse files
committed
basic integration tests with readme
1 parent 84febfe commit c99f15e

File tree

3 files changed

+118
-15
lines changed

3 files changed

+118
-15
lines changed

TESTING.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Testing
2+
3+
## Unit Tests
4+
We are working on an npm-based runner but for now we use the existing flow. Run `./test.sh` as described in the main README.
5+
6+
## Integration Tests
7+
1. Start the Minio and Gateway containers with `docker compose up --abort-on-container-exit`
8+
2. `npm test`

__tests__/basic.test.js

+109-14
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,29 @@ const Minio = require("minio");
33
const request = require("supertest");
44

55
const FILES = {
6-
"/foo/bar.txt": {
7-
content: "dog",
6+
"a.txt": {
7+
content: "Let go, or be dragged.",
88
},
9-
"/foo/baz.txt": {
10-
content: "cat",
9+
"b/c/d.txt": {
10+
content: `When thoughts arise, then do all things arise. When thoughts vanish, then do all things vanish.`,
1111
},
12-
"/grumpy.txt": {
13-
content: "bah",
12+
"b/e.txt": {
13+
content: "If only you could hear the sound of snow.",
1414
},
15+
"a/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.txt": {
16+
content: `
17+
"Where the is not one thing, what then?"
18+
"Throw it away!"
19+
"With not one thing, what there is to throw away?"
20+
"Then carry it off!"
21+
`
22+
}
1523
};
1624

17-
const BUCKET_NAME = "bucket-1";
25+
const BUCKET_NAME = "bucket-2";
26+
const GATEWAY_HOST = "localhost";
27+
const GATEWAY_PORT = "8989";
28+
const GATEWAY_BASE_URL = `http://${GATEWAY_HOST}:${GATEWAY_PORT}`;
1829

1930
beforeAll(async () => {
2031
const minioClient = new Minio.Client({
@@ -44,11 +55,95 @@ async function ensureBucketWithObjects(s3Client, bucketName, objects) {
4455
}
4556
}
4657

47-
test('adds 1 + 2 to equal 3', async () => {
48-
const res = await request('http://localhost:8989')
49-
.get("/foo/bar.txt")
50-
.set("accept", "binary/octet-stream");
58+
describe("Ordinary filenames", () => {
59+
test("simple url", async () => {
60+
const objectPath = "a.txt";
61+
const res = await request(GATEWAY_BASE_URL)
62+
.get(`/${objectPath}`);
63+
64+
expect(res.statusCode).toBe(200);
65+
expect(res.text).toBe(FILES[objectPath].content);
66+
});
67+
68+
test("many params that should be stripped", async () => {
69+
const objectPath = "a.txt";
70+
const res = await request(GATEWAY_BASE_URL)
71+
.get("/a.txt?some=param&that=should&be=stripped#aaah")
72+
.set("accept", "binary/octet-stream");
73+
74+
expect(res.statusCode).toBe(200);
75+
expect(res.text).toBe(FILES[objectPath].content);
76+
});
77+
78+
test("with a more complex path", async () => {
79+
const objectPath = "b/c/d.txt";
80+
const res = await request(GATEWAY_BASE_URL)
81+
.get("/b/c/d.txt")
82+
.set("accept", "binary/octet-stream");
83+
84+
expect(res.statusCode).toBe(200);
85+
expect(res.text).toBe(FILES[objectPath].content);
86+
});
87+
88+
test("with a more complex path", async () => {
89+
const objectPath = "b/e.txt";
90+
const res = await request(GATEWAY_BASE_URL)
91+
.get("/b/c/../e.txt")
92+
.set("accept", "binary/octet-stream");
93+
94+
expect(res.statusCode).toBe(200);
95+
expect(res.text).toBe(FILES[objectPath].content);
96+
});
97+
98+
test("another simple path", async () => {
99+
const objectPath = "b/e.txt";
100+
const res = await request(GATEWAY_BASE_URL)
101+
.get("/b/e.txt")
102+
.set("accept", "binary/octet-stream");
103+
104+
expect(res.statusCode).toBe(200);
105+
expect(res.text).toBe(FILES[objectPath].content);
106+
});
107+
108+
test("too many forward slashes", async () => {
109+
const objectPath = "b/e.txt";
110+
const res = await request(GATEWAY_BASE_URL)
111+
.get("/b//e.txt")
112+
.set("accept", "binary/octet-stream");
113+
114+
expect(res.statusCode).toBe(200);
115+
expect(res.text).toBe(FILES[objectPath].content);
116+
});
117+
118+
test("very long file name", async () => {
119+
const objectPath = "a/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.txt";
120+
const res = await request(GATEWAY_BASE_URL)
121+
.get("/a/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.txt")
122+
.set("accept", "binary/octet-stream");
123+
124+
expect(res.statusCode).toBe(200);
125+
expect(res.text).toBe(FILES[objectPath].content);
126+
});
127+
});
128+
129+
describe("strange file names and encodings", () => {
130+
131+
})
132+
133+
// # We try to request URLs that are properly encoded as well as URLs that
134+
// # are not properly encoded to understand what works and what does not.
135+
136+
// # Weird filenames
137+
// assertHttpRequestEquals "HEAD" "b/c/%3D" "200"
138+
// assertHttpRequestEquals "HEAD" "b/c/=" "200"
139+
140+
// assertHttpRequestEquals "HEAD" "b/c/%40" "200"
141+
// assertHttpRequestEquals "HEAD" "b/c/@" "200"
142+
143+
// assertHttpRequestEquals "HEAD" "b/c/%27%281%29.txt" "200"
144+
// assertHttpRequestEquals "HEAD" "b/c/'(1).txt" "200"
145+
146+
// # These URLs do not work unencoded
147+
// assertHttpRequestEquals "HEAD" 'a/plus%2Bplus.txt' "200"
148+
// assertHttpRequestEquals "HEAD" "%D1%81%D0%B8%D1%81%D1%82%D0%B5%D0%BC%D1%8B/%25bad%25file%25name%25" "200"
51149

52-
expect(res.statusCode).toBe(200);
53-
expect(res.text).toBe(FILES["/foo/bar.txt"].content);
54-
});

test/docker-compose.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
- "minio"
1818
restart: "no"
1919
environment:
20-
S3_BUCKET_NAME: "bucket-1"
20+
S3_BUCKET_NAME: "bucket-2"
2121
AWS_ACCESS_KEY_ID: "AKIAIOSFODNN7EXAMPLE"
2222
AWS_SECRET_ACCESS_KEY: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
2323
S3_SERVER: "minio"

0 commit comments

Comments
 (0)