MCPcopy
hub / github.com/gin-gonic/gin / TestBasicAuthForProxy407

Function TestBasicAuthForProxy407

auth_test.go:158–176  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

156}
157
158func TestBasicAuthForProxy407(t *testing.T) {
159 called := false
160 accounts := Accounts{"foo": "bar"}
161 router := New()
162 router.Use(BasicAuthForProxy(accounts, ""))
163 router.Any("/*proxyPath", func(c *Context) {
164 called = true
165 c.String(http.StatusOK, c.MustGet(AuthProxyUserKey).(string))
166 })
167
168 w := httptest.NewRecorder()
169 req, _ := http.NewRequest(http.MethodGet, "/test", nil)
170 req.Header.Set("Proxy-Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:password")))
171 router.ServeHTTP(w, req)
172
173 assert.False(t, called)
174 assert.Equal(t, http.StatusProxyAuthRequired, w.Code)
175 assert.Equal(t, "Basic realm=\"Proxy Authorization Required\"", w.Header().Get("Proxy-Authenticate"))
176}

Callers

nothing calls this directly

Calls 10

NewFunction · 0.85
BasicAuthForProxyFunction · 0.85
MustGetMethod · 0.80
SetMethod · 0.80
UseMethod · 0.65
AnyMethod · 0.65
StringMethod · 0.65
ServeHTTPMethod · 0.45
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected