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

Function TestKeyAuth

middleware/key_auth_test.go:32–50  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30}
31
32func TestKeyAuth(t *testing.T) {
33 handlerCalled := false
34 handler := func(c *echo.Context) error {
35 handlerCalled = true
36 return c.String(http.StatusOK, "test")
37 }
38 middlewareChain := KeyAuth(testKeyValidator)(handler)
39
40 e := echo.New()
41 req := httptest.NewRequest(http.MethodGet, "/", nil)
42 req.Header.Set(echo.HeaderAuthorization, "Bearer valid-key")
43 rec := httptest.NewRecorder()
44 c := e.NewContext(req, rec)
45
46 err := middlewareChain(c)
47
48 assert.NoError(t, err)
49 assert.True(t, handlerCalled)
50}
51
52func TestKeyAuthWithConfig(t *testing.T) {
53 var testCases = []struct {

Callers

nothing calls this directly

Calls 4

StringMethod · 0.95
KeyAuthFunction · 0.85
SetMethod · 0.80
NewContextMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…