@@ -3,18 +3,29 @@ const Minio = require("minio");
3
3
const request = require ( "supertest" ) ;
4
4
5
5
const FILES = {
6
- "/foo/bar .txt" : {
7
- content : "dog " ,
6
+ "a .txt" : {
7
+ content : "Let go, or be dragged. " ,
8
8
} ,
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.` ,
11
11
} ,
12
- "/grumpy .txt" : {
13
- content : "bah " ,
12
+ "b/e .txt" : {
13
+ content : "If only you could hear the sound of snow. " ,
14
14
} ,
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
+ }
15
23
} ;
16
24
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 } ` ;
18
29
19
30
beforeAll ( async ( ) => {
20
31
const minioClient = new Minio . Client ( {
@@ -44,11 +55,95 @@ async function ensureBucketWithObjects(s3Client, bucketName, objects) {
44
55
}
45
56
}
46
57
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"
51
149
52
- expect ( res . statusCode ) . toBe ( 200 ) ;
53
- expect ( res . text ) . toBe ( FILES [ "/foo/bar.txt" ] . content ) ;
54
- } ) ;
0 commit comments