MCPcopy Create free account
hub / github.com/dnote/dnote / TestGetSessionKeyFromCookie

Function TestGetSessionKeyFromCookie

pkg/server/middleware/helpers_test.go:26–72  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestGetSessionKeyFromCookie(t *testing.T) {
27 testCases := []struct {
28 cookie *http.Cookie
29 expected string
30 }{
31 {
32 cookie: &http.Cookie{
33 Name: "id",
34 Value: "foo",
35 HttpOnly: true,
36 },
37 expected: "foo",
38 },
39 {
40 cookie: nil,
41 expected: "",
42 },
43 {
44 cookie: &http.Cookie{
45 Name: "foo",
46 Value: "bar",
47 HttpOnly: true,
48 },
49 expected: "",
50 },
51 }
52
53 for _, tc := range testCases {
54 // set up
55 r, err := http.NewRequest("GET", "/", nil)
56 if err != nil {
57 t.Fatal(errors.Wrap(err, "constructing request"))
58 }
59
60 if tc.cookie != nil {
61 r.AddCookie(tc.cookie)
62 }
63
64 // execute
65 got, err := getSessionKeyFromCookie(r)
66 if err != nil {
67 t.Fatal(errors.Wrap(err, "executing"))
68 }
69
70 assert.Equal(t, got, tc.expected, "result mismatch")
71 }
72}
73
74func TestGetSessionKeyFromAuth(t *testing.T) {
75 testCases := []struct {

Callers

nothing calls this directly

Calls 2

EqualFunction · 0.92
getSessionKeyFromCookieFunction · 0.70

Tested by

no test coverage detected