53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package auth
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
)
|
|
|
|
func TestBuildAuthTransportUsesExplicitProxyURL(t *testing.T) {
|
|
transport := buildAuthTransport("http://proxy.local:8080")
|
|
req := &http.Request{URL: mustParseURL(t, "https://oidc.us-east-1.amazonaws.com")}
|
|
|
|
got, err := transport.Proxy(req)
|
|
if err != nil {
|
|
t.Fatalf("unexpected proxy error: %v", err)
|
|
}
|
|
assertProxyURL(t, got, "http://proxy.local:8080")
|
|
}
|
|
|
|
func TestBuildAuthTransportFallsBackToEnvironmentProxy(t *testing.T) {
|
|
t.Setenv("HTTPS_PROXY", "http://env-proxy.local:2323")
|
|
t.Setenv("NO_PROXY", "")
|
|
t.Setenv("no_proxy", "")
|
|
|
|
transport := buildAuthTransport("")
|
|
req := &http.Request{URL: mustParseURL(t, "https://oidc.us-east-1.amazonaws.com")}
|
|
|
|
got, err := transport.Proxy(req)
|
|
if err != nil {
|
|
t.Fatalf("unexpected proxy error: %v", err)
|
|
}
|
|
assertProxyURL(t, got, "http://env-proxy.local:2323")
|
|
}
|
|
|
|
func mustParseURL(t *testing.T, raw string) *url.URL {
|
|
t.Helper()
|
|
parsed, err := url.Parse(raw)
|
|
if err != nil {
|
|
t.Fatalf("invalid test URL: %v", err)
|
|
}
|
|
return parsed
|
|
}
|
|
|
|
func assertProxyURL(t *testing.T, got *url.URL, want string) {
|
|
t.Helper()
|
|
if got == nil {
|
|
t.Fatalf("expected proxy URL %q, got nil", want)
|
|
}
|
|
if got.String() != want {
|
|
t.Fatalf("expected proxy URL %q, got %q", want, got.String())
|
|
}
|
|
}
|