(t *testing.T)
| 177 | } |
| 178 | |
| 179 | func 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 | }) |
nothing calls this directly
no test coverage detected