MCPcopy
hub / github.com/oauth2-proxy/oauth2-proxy / TestBasicAuthPassword

Function TestBasicAuthPassword

oauthproxy_test.go:179–263  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

177}
178
179func TestBasicAuthPassword(t *testing.T) {
180 providerServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
181 logger.Printf("%#v", r)
182 var payload string
183 switch r.URL.Path {
184 case "/oauth/token":
185 payload = `{"access_token": "my_auth_token"}`
186 default:
187 payload = r.Header.Get("Authorization")
188 if payload == "" {
189 payload = "No Authorization header found."
190 }
191 }
192 w.WriteHeader(200)
193 _, err := w.Write([]byte(payload))
194 if err != nil {
195 t.Fatal(err)
196 }
197 }))
198
199 basicAuthPassword := "This is a secure password"
200 opts := baseTestOptions()
201 opts.UpstreamServers = options.UpstreamConfig{
202 Upstreams: []options.Upstream{
203 {
204 ID: providerServer.URL,
205 Path: "/",
206 URI: providerServer.URL,
207 },
208 },
209 }
210
211 opts.Cookie.Secure = false
212 opts.InjectRequestHeaders = []options.Header{
213 {
214 Name: "Authorization",
215 Values: []options.HeaderValue{
216 {
217 ClaimSource: &options.ClaimSource{
218 Claim: "email",
219 BasicAuthPassword: &options.SecretSource{
220 Value: []byte(basicAuthPassword),
221 },
222 },
223 },
224 },
225 },
226 }
227
228 err := validation.Validate(opts)
229 assert.NoError(t, err)
230
231 providerURL, _ := url.Parse(providerServer.URL)
232 const emailAddress = "john.doe@example.com"
233
234 proxy, err := NewOAuthProxy(opts, func(email string) bool {
235 return email == emailAddress
236 })

Callers

nothing calls this directly

Calls 13

ServeHTTPMethod · 0.95
PrintfFunction · 0.92
ValidateFunction · 0.92
baseTestOptionsFunction · 0.85
NewOAuthProxyFunction · 0.85
NewTestProviderFunction · 0.85
WriteHeaderMethod · 0.80
GetMethod · 0.65
SaveMethod · 0.65
SetMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected