Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/fx/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ func validateRevocationPath(ctx context.Context, path []ucan.Delegation, didReso
func newEchoServer(id identity.Identity, ucanServer *server.HTTPServer, revocations store.RevocationStore) *echo.Echo {
e := echo.New()
e.HideBanner = true
// Outermost middleware: a handler panic becomes a 500 rather than a
// dropped connection.
e.Use(middleware.Recover())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{echo.GET, echo.POST, echo.OPTIONS},
Expand Down
15 changes: 15 additions & 0 deletions pkg/fx/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ func TestEchoPublicRoutes(t *testing.T) {
require.Equal(t, http.StatusOK, response.Code)
}

// A handler panic must not escape to net/http, which drops the connection
// without ever writing a response.
func TestAHandlerPanicBecomesAServerError(t *testing.T) {
id, err := identity.New("", "")
require.NoError(t, err)
e := newEchoServer(id, server.NewHTTP(id), memory.New())
e.GET("/panic", func(echo.Context) error { panic("handler exploded") })

response := httptest.NewRecorder()
require.NotPanics(t, func() {
e.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/panic", nil))
})
require.Equal(t, http.StatusInternalServerError, response.Code)
}

func TestParseFrom(t *testing.T) {
from, err := parseFrom("0")
require.NoError(t, err)
Expand Down
Loading