MCPcopy Index your code
hub / github.com/labstack/echo / TestContextInline

Function TestContextInline

context_test.go:460–493  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

458}
459
460func TestContextInline(t *testing.T) {
461 var testCases = []struct {
462 name string
463 whenName string
464 expectHeader string
465 }{
466 {
467 name: "ok",
468 whenName: "walle.png",
469 expectHeader: `inline; filename="walle.png"`,
470 },
471 {
472 name: "ok, escape quotes in malicious filename",
473 whenName: `malicious.sh"; \"; dummy=.txt`,
474 expectHeader: `inline; filename="malicious.sh\"; \\\"; dummy=.txt"`,
475 },
476 }
477 for _, tc := range testCases {
478 t.Run(tc.name, func(t *testing.T) {
479 e := New()
480 rec := httptest.NewRecorder()
481 req := httptest.NewRequest(http.MethodGet, "/", nil)
482 c := e.NewContext(req, rec)
483
484 err := c.Inline("_fixture/images/walle.png", tc.whenName)
485 if assert.NoError(t, err) {
486 assert.Equal(t, tc.expectHeader, rec.Header().Get(HeaderContentDisposition))
487
488 assert.Equal(t, http.StatusOK, rec.Code)
489 assert.Equal(t, 219885, rec.Body.Len())
490 }
491 })
492 }
493}
494
495func TestContextNoContent(t *testing.T) {
496 e := New()

Callers

nothing calls this directly

Calls 5

InlineMethod · 0.95
NewFunction · 0.85
NewContextMethod · 0.80
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…