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

Function TestBasicAuthForProxySucceed

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

Source from the content-addressed store, hash-verified

139}
140
141func TestBasicAuthForProxySucceed(t *testing.T) {
142 accounts := Accounts{"admin": "password"}
143 router := New()
144 router.Use(BasicAuthForProxy(accounts, ""))
145 router.Any("/*proxyPath", func(c *Context) {
146 c.String(http.StatusOK, c.MustGet(AuthProxyUserKey).(string))
147 })
148
149 w := httptest.NewRecorder()
150 req, _ := http.NewRequest(http.MethodGet, "/test", nil)
151 req.Header.Set("Proxy-Authorization", authorizationHeader("admin", "password"))
152 router.ServeHTTP(w, req)
153
154 assert.Equal(t, http.StatusOK, w.Code)
155 assert.Equal(t, "admin", w.Body.String())
156}
157
158func TestBasicAuthForProxy407(t *testing.T) {
159 called := false

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected