Skip to content

Commit 5968733

Browse files
committed
fix(server): Not found not correctly managed inside target router
1 parent c55e070 commit 5968733

File tree

2 files changed

+73
-20
lines changed

2 files changed

+73
-20
lines changed

pkg/s3-proxy/server/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ func (svr *Server) generateRouter() (http.Handler, error) {
268268
if rt == nil {
269269
// Create a new router
270270
rt = chi.NewRouter()
271+
272+
// Add not found
273+
rt.NotFound(notFoundHandler)
271274
}
272275
// Loop over path list
273276
funk.ForEach(tgt.Mount.Path, func(path string) {

pkg/s3-proxy/server/server_integration_test.go

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,15 @@ func TestPublicRouter(t *testing.T) {
124124
inputMethod: "GET",
125125
inputURL: "http://localhost/not-found/",
126126
expectedCode: 404,
127-
expectedBody: "404 page not found\n",
127+
expectedBody: `<!DOCTYPE html>
128+
<html>
129+
<body>
130+
<h1>Not Found /not-found/</h1>
131+
</body>
132+
</html>`,
128133
expectedHeaders: map[string]string{
129134
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
130-
"Content-Type": "text/plain; charset=utf-8",
135+
"Content-Type": "text/html; charset=utf-8",
131136
},
132137
},
133138
{
@@ -3912,10 +3917,15 @@ func TestTracing(t *testing.T) {
39123917
inputMethod: "GET",
39133918
inputURL: "http://localhost/not-found/",
39143919
expectedCode: 404,
3915-
expectedBody: "404 page not found\n",
3920+
expectedBody: `<!DOCTYPE html>
3921+
<html>
3922+
<body>
3923+
<h1>Not Found /not-found/</h1>
3924+
</body>
3925+
</html>`,
39163926
expectedHeaders: map[string]string{
39173927
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
3918-
"Content-Type": "text/plain; charset=utf-8",
3928+
"Content-Type": "text/html; charset=utf-8",
39193929
},
39203930
},
39213931
{
@@ -3936,10 +3946,15 @@ func TestTracing(t *testing.T) {
39363946
inputMethod: "GET",
39373947
inputURL: "http://localhost/not-found/",
39383948
expectedCode: 404,
3939-
expectedBody: "404 page not found\n",
3949+
expectedBody: `<!DOCTYPE html>
3950+
<html>
3951+
<body>
3952+
<h1>Not Found /not-found/</h1>
3953+
</body>
3954+
</html>`,
39403955
expectedHeaders: map[string]string{
39413956
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
3942-
"Content-Type": "text/plain; charset=utf-8",
3957+
"Content-Type": "text/html; charset=utf-8",
39433958
},
39443959
},
39453960
}
@@ -5015,10 +5030,15 @@ func TestCORS(t *testing.T) {
50155030
"Host": "localhost",
50165031
},
50175032
expectedCode: 404,
5018-
expectedBody: "404 page not found\n",
5033+
expectedBody: `<!DOCTYPE html>
5034+
<html>
5035+
<body>
5036+
<h1>Not Found /not-found/</h1>
5037+
</body>
5038+
</html>`,
50195039
expectedHeaders: map[string]string{
50205040
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
5021-
"Content-Type": "text/plain; charset=utf-8",
5041+
"Content-Type": "text/html; charset=utf-8",
50225042
},
50235043
},
50245044
{
@@ -5050,10 +5070,15 @@ func TestCORS(t *testing.T) {
50505070
"Host": "localhost",
50515071
},
50525072
expectedCode: 404,
5053-
expectedBody: "404 page not found\n",
5073+
expectedBody: `<!DOCTYPE html>
5074+
<html>
5075+
<body>
5076+
<h1>Not Found /not-found/</h1>
5077+
</body>
5078+
</html>`,
50545079
expectedHeaders: map[string]string{
50555080
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
5056-
"Content-Type": "text/plain; charset=utf-8",
5081+
"Content-Type": "text/html; charset=utf-8",
50575082
"Access-Control-Allow-Origin": "*",
50585083
},
50595084
},
@@ -5088,10 +5113,15 @@ func TestCORS(t *testing.T) {
50885113
"Host": "localhost",
50895114
},
50905115
expectedCode: 404,
5091-
expectedBody: "404 page not found\n",
5116+
expectedBody: `<!DOCTYPE html>
5117+
<html>
5118+
<body>
5119+
<h1>Not Found /not-found/</h1>
5120+
</body>
5121+
</html>`,
50925122
expectedHeaders: map[string]string{
50935123
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
5094-
"Content-Type": "text/plain; charset=utf-8",
5124+
"Content-Type": "text/html; charset=utf-8",
50955125
"Access-Control-Allow-Origin": "https://test.fake",
50965126
},
50975127
},
@@ -5126,10 +5156,15 @@ func TestCORS(t *testing.T) {
51265156
"Host": "localhost",
51275157
},
51285158
expectedCode: 404,
5129-
expectedBody: "404 page not found\n",
5159+
expectedBody: `<!DOCTYPE html>
5160+
<html>
5161+
<body>
5162+
<h1>Not Found /not-found/</h1>
5163+
</body>
5164+
</html>`,
51305165
expectedHeaders: map[string]string{
51315166
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
5132-
"Content-Type": "text/plain; charset=utf-8",
5167+
"Content-Type": "text/html; charset=utf-8",
51335168
"Access-Control-Allow-Origin": "",
51345169
},
51355170
},
@@ -5164,10 +5199,15 @@ func TestCORS(t *testing.T) {
51645199
"Host": "localhost",
51655200
},
51665201
expectedCode: 404,
5167-
expectedBody: "404 page not found\n",
5202+
expectedBody: `<!DOCTYPE html>
5203+
<html>
5204+
<body>
5205+
<h1>Not Found /not-found/</h1>
5206+
</body>
5207+
</html>`,
51685208
expectedHeaders: map[string]string{
51695209
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
5170-
"Content-Type": "text/plain; charset=utf-8",
5210+
"Content-Type": "text/html; charset=utf-8",
51715211
"Access-Control-Allow-Origin": "https://test.fake",
51725212
},
51735213
},
@@ -5202,10 +5242,15 @@ func TestCORS(t *testing.T) {
52025242
"Host": "localhost",
52035243
},
52045244
expectedCode: 404,
5205-
expectedBody: "404 page not found\n",
5245+
expectedBody: `<!DOCTYPE html>
5246+
<html>
5247+
<body>
5248+
<h1>Not Found /not-found/</h1>
5249+
</body>
5250+
</html>`,
52065251
expectedHeaders: map[string]string{
52075252
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
5208-
"Content-Type": "text/plain; charset=utf-8",
5253+
"Content-Type": "text/html; charset=utf-8",
52095254
"Access-Control-Allow-Origin": "",
52105255
},
52115256
},
@@ -5240,10 +5285,15 @@ func TestCORS(t *testing.T) {
52405285
"Host": "localhost",
52415286
},
52425287
expectedCode: 404,
5243-
expectedBody: "404 page not found\n",
5288+
expectedBody: `<!DOCTYPE html>
5289+
<html>
5290+
<body>
5291+
<h1>Not Found /not-found/</h1>
5292+
</body>
5293+
</html>`,
52445294
expectedHeaders: map[string]string{
52455295
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
5246-
"Content-Type": "text/plain; charset=utf-8",
5296+
"Content-Type": "text/html; charset=utf-8",
52475297
"Access-Control-Allow-Origin": "",
52485298
},
52495299
},

0 commit comments

Comments
 (0)