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

Function TestGetCredential

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

Source from the content-addressed store, hash-verified

111}
112
113func TestGetCredential(t *testing.T) {
114 r1 := mustMakeRequest(t)
115 r2 := mustMakeRequest(t)
116 r2.Header.Set("Authorization", "Bearer foo")
117 r3 := mustMakeRequest(t)
118 r3.Header.Set("Authorization", "Bearer bar")
119
120 r4 := mustMakeRequest(t)
121 c4 := http.Cookie{
122 Name: "id",
123 Value: "foo",
124 HttpOnly: true,
125 }
126 r4.AddCookie(&c4)
127
128 r5 := mustMakeRequest(t)
129 c5 := http.Cookie{
130 Name: "id",
131 Value: "foo",
132 HttpOnly: true,
133 }
134 r5.AddCookie(&c5)
135 r5.Header.Set("Authorization", "Bearer foo")
136
137 testCases := []struct {
138 request *http.Request
139 expected string
140 }{
141 {
142 request: r1,
143 expected: "",
144 },
145 {
146 request: r2,
147 expected: "foo",
148 },
149 {
150 request: r3,
151 expected: "bar",
152 },
153 {
154 request: r4,
155 expected: "foo",
156 },
157 {
158 request: r5,
159 expected: "foo",
160 },
161 }
162
163 for _, tc := range testCases {
164 // execute
165 got, err := GetCredential(tc.request)
166 if err != nil {
167 t.Fatal(errors.Wrap(err, "executing"))
168 }
169
170 assert.Equal(t, got, tc.expected, "result mismatch")

Callers

nothing calls this directly

Calls 3

EqualFunction · 0.92
mustMakeRequestFunction · 0.85
GetCredentialFunction · 0.70

Tested by

no test coverage detected