(t *testing.T)
| 18 | ) |
| 19 | |
| 20 | func TestCreateExtractors(t *testing.T) { |
| 21 | var testCases = []struct { |
| 22 | name string |
| 23 | givenRequest func() *http.Request |
| 24 | givenPathValues echo.PathValues |
| 25 | whenLookups string |
| 26 | whenLimit uint |
| 27 | expectValues []string |
| 28 | expectSource ExtractorSource |
| 29 | expectCreateError string |
| 30 | expectError string |
| 31 | }{ |
| 32 | { |
| 33 | name: "ok, header", |
| 34 | givenRequest: func() *http.Request { |
| 35 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 36 | req.Header.Set(echo.HeaderAuthorization, "Bearer token") |
| 37 | return req |
| 38 | }, |
| 39 | whenLookups: "header:Authorization:Bearer ", |
| 40 | expectValues: []string{"token"}, |
| 41 | expectSource: ExtractorSourceHeader, |
| 42 | }, |
| 43 | { |
| 44 | name: "ok, form", |
| 45 | givenRequest: func() *http.Request { |
| 46 | f := make(url.Values) |
| 47 | f.Set("name", "Jon Snow") |
| 48 | |
| 49 | req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) |
| 50 | req.Header.Add(echo.HeaderContentType, echo.MIMEApplicationForm) |
| 51 | return req |
| 52 | }, |
| 53 | whenLookups: "form:name", |
| 54 | expectValues: []string{"Jon Snow"}, |
| 55 | expectSource: ExtractorSourceForm, |
| 56 | }, |
| 57 | { |
| 58 | name: "ok, cookie", |
| 59 | givenRequest: func() *http.Request { |
| 60 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 61 | req.Header.Set(echo.HeaderCookie, "_csrf=token") |
| 62 | return req |
| 63 | }, |
| 64 | whenLookups: "cookie:_csrf", |
| 65 | expectValues: []string{"token"}, |
| 66 | expectSource: ExtractorSourceCookie, |
| 67 | }, |
| 68 | { |
| 69 | name: "ok, param", |
| 70 | givenPathValues: echo.PathValues{ |
| 71 | {Name: "id", Value: "123"}, |
| 72 | }, |
| 73 | whenLookups: "param:id", |
| 74 | expectValues: []string{"123"}, |
| 75 | expectSource: ExtractorSourcePathParam, |
| 76 | }, |
| 77 | { |
nothing calls this directly
no test coverage detected
searching dependent graphs…