Skip to content

Commit

Permalink
fix(server): Not found not correctly managed inside target router
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyno-zeta committed Sep 23, 2024
1 parent c55e070 commit 5968733
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 20 deletions.
3 changes: 3 additions & 0 deletions pkg/s3-proxy/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ func (svr *Server) generateRouter() (http.Handler, error) {
if rt == nil {
// Create a new router
rt = chi.NewRouter()

// Add not found
rt.NotFound(notFoundHandler)
}
// Loop over path list
funk.ForEach(tgt.Mount.Path, func(path string) {
Expand Down
90 changes: 70 additions & 20 deletions pkg/s3-proxy/server/server_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,15 @@ func TestPublicRouter(t *testing.T) {
inputMethod: "GET",
inputURL: "http://localhost/not-found/",
expectedCode: 404,
expectedBody: "404 page not found\n",
expectedBody: `<!DOCTYPE html>
<html>
<body>
<h1>Not Found /not-found/</h1>
</body>
</html>`,
expectedHeaders: map[string]string{
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
"Content-Type": "text/plain; charset=utf-8",
"Content-Type": "text/html; charset=utf-8",
},
},
{
Expand Down Expand Up @@ -3912,10 +3917,15 @@ func TestTracing(t *testing.T) {
inputMethod: "GET",
inputURL: "http://localhost/not-found/",
expectedCode: 404,
expectedBody: "404 page not found\n",
expectedBody: `<!DOCTYPE html>
<html>
<body>
<h1>Not Found /not-found/</h1>
</body>
</html>`,
expectedHeaders: map[string]string{
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
"Content-Type": "text/plain; charset=utf-8",
"Content-Type": "text/html; charset=utf-8",
},
},
{
Expand All @@ -3936,10 +3946,15 @@ func TestTracing(t *testing.T) {
inputMethod: "GET",
inputURL: "http://localhost/not-found/",
expectedCode: 404,
expectedBody: "404 page not found\n",
expectedBody: `<!DOCTYPE html>
<html>
<body>
<h1>Not Found /not-found/</h1>
</body>
</html>`,
expectedHeaders: map[string]string{
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
"Content-Type": "text/plain; charset=utf-8",
"Content-Type": "text/html; charset=utf-8",
},
},
}
Expand Down Expand Up @@ -5015,10 +5030,15 @@ func TestCORS(t *testing.T) {
"Host": "localhost",
},
expectedCode: 404,
expectedBody: "404 page not found\n",
expectedBody: `<!DOCTYPE html>
<html>
<body>
<h1>Not Found /not-found/</h1>
</body>
</html>`,
expectedHeaders: map[string]string{
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
"Content-Type": "text/plain; charset=utf-8",
"Content-Type": "text/html; charset=utf-8",
},
},
{
Expand Down Expand Up @@ -5050,10 +5070,15 @@ func TestCORS(t *testing.T) {
"Host": "localhost",
},
expectedCode: 404,
expectedBody: "404 page not found\n",
expectedBody: `<!DOCTYPE html>
<html>
<body>
<h1>Not Found /not-found/</h1>
</body>
</html>`,
expectedHeaders: map[string]string{
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
"Content-Type": "text/plain; charset=utf-8",
"Content-Type": "text/html; charset=utf-8",
"Access-Control-Allow-Origin": "*",
},
},
Expand Down Expand Up @@ -5088,10 +5113,15 @@ func TestCORS(t *testing.T) {
"Host": "localhost",
},
expectedCode: 404,
expectedBody: "404 page not found\n",
expectedBody: `<!DOCTYPE html>
<html>
<body>
<h1>Not Found /not-found/</h1>
</body>
</html>`,
expectedHeaders: map[string]string{
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
"Content-Type": "text/plain; charset=utf-8",
"Content-Type": "text/html; charset=utf-8",
"Access-Control-Allow-Origin": "https://test.fake",
},
},
Expand Down Expand Up @@ -5126,10 +5156,15 @@ func TestCORS(t *testing.T) {
"Host": "localhost",
},
expectedCode: 404,
expectedBody: "404 page not found\n",
expectedBody: `<!DOCTYPE html>
<html>
<body>
<h1>Not Found /not-found/</h1>
</body>
</html>`,
expectedHeaders: map[string]string{
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
"Content-Type": "text/plain; charset=utf-8",
"Content-Type": "text/html; charset=utf-8",
"Access-Control-Allow-Origin": "",
},
},
Expand Down Expand Up @@ -5164,10 +5199,15 @@ func TestCORS(t *testing.T) {
"Host": "localhost",
},
expectedCode: 404,
expectedBody: "404 page not found\n",
expectedBody: `<!DOCTYPE html>
<html>
<body>
<h1>Not Found /not-found/</h1>
</body>
</html>`,
expectedHeaders: map[string]string{
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
"Content-Type": "text/plain; charset=utf-8",
"Content-Type": "text/html; charset=utf-8",
"Access-Control-Allow-Origin": "https://test.fake",
},
},
Expand Down Expand Up @@ -5202,10 +5242,15 @@ func TestCORS(t *testing.T) {
"Host": "localhost",
},
expectedCode: 404,
expectedBody: "404 page not found\n",
expectedBody: `<!DOCTYPE html>
<html>
<body>
<h1>Not Found /not-found/</h1>
</body>
</html>`,
expectedHeaders: map[string]string{
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
"Content-Type": "text/plain; charset=utf-8",
"Content-Type": "text/html; charset=utf-8",
"Access-Control-Allow-Origin": "",
},
},
Expand Down Expand Up @@ -5240,10 +5285,15 @@ func TestCORS(t *testing.T) {
"Host": "localhost",
},
expectedCode: 404,
expectedBody: "404 page not found\n",
expectedBody: `<!DOCTYPE html>
<html>
<body>
<h1>Not Found /not-found/</h1>
</body>
</html>`,
expectedHeaders: map[string]string{
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
"Content-Type": "text/plain; charset=utf-8",
"Content-Type": "text/html; charset=utf-8",
"Access-Control-Allow-Origin": "",
},
},
Expand Down

0 comments on commit 5968733

Please sign in to comment.