2015-03-11 22:42:08 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2015-04-20 18:30:35 +00:00
|
|
|
"bytes"
|
2020-11-06 19:27:35 +00:00
|
|
|
"context"
|
2015-04-20 18:30:35 +00:00
|
|
|
"io"
|
2015-03-11 22:42:08 +00:00
|
|
|
"net/http"
|
2015-04-23 15:43:20 +00:00
|
|
|
"os"
|
2018-01-25 00:57:49 +00:00
|
|
|
"strings"
|
2015-03-11 22:42:08 +00:00
|
|
|
"testing"
|
2020-11-06 19:27:35 +00:00
|
|
|
"time"
|
2019-07-17 10:29:25 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/vault/sdk/helper/consts"
|
2015-03-11 22:42:08 +00:00
|
|
|
)
|
|
|
|
|
2015-04-23 15:43:20 +00:00
|
|
|
func init() {
|
|
|
|
// Ensure our special envvars are not present
|
2015-04-23 15:46:22 +00:00
|
|
|
os.Setenv("VAULT_ADDR", "")
|
2015-04-23 15:43:20 +00:00
|
|
|
os.Setenv("VAULT_TOKEN", "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultConfig_envvar(t *testing.T) {
|
2015-04-23 15:46:22 +00:00
|
|
|
os.Setenv("VAULT_ADDR", "https://vault.mycompany.com")
|
|
|
|
defer os.Setenv("VAULT_ADDR", "")
|
2015-04-23 15:43:20 +00:00
|
|
|
|
|
|
|
config := DefaultConfig()
|
|
|
|
if config.Address != "https://vault.mycompany.com" {
|
|
|
|
t.Fatalf("bad: %s", config.Address)
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Setenv("VAULT_TOKEN", "testing")
|
|
|
|
defer os.Setenv("VAULT_TOKEN", "")
|
|
|
|
|
|
|
|
client, err := NewClient(config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if token := client.Token(); token != "testing" {
|
|
|
|
t.Fatalf("bad: %s", token)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-09 12:49:20 +00:00
|
|
|
func TestClientDefaultHttpClient(t *testing.T) {
|
|
|
|
_, err := NewClient(&Config{
|
|
|
|
HttpClient: http.DefaultClient,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 15:37:13 +00:00
|
|
|
func TestClientNilConfig(t *testing.T) {
|
|
|
|
client, err := NewClient(nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if client == nil {
|
|
|
|
t.Fatal("expected a non-nil client")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientSetAddress(t *testing.T) {
|
|
|
|
client, err := NewClient(nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := client.SetAddress("http://172.168.2.1:8300"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if client.addr.Host != "172.168.2.1:8300" {
|
|
|
|
t.Fatalf("bad: expected: '172.168.2.1:8300' actual: %q", client.addr.Host)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-11 22:42:08 +00:00
|
|
|
func TestClientToken(t *testing.T) {
|
|
|
|
tokenValue := "foo"
|
2015-08-22 00:36:19 +00:00
|
|
|
handler := func(w http.ResponseWriter, req *http.Request) {}
|
2015-03-11 22:42:08 +00:00
|
|
|
|
|
|
|
config, ln := testHTTPServer(t, http.HandlerFunc(handler))
|
|
|
|
defer ln.Close()
|
|
|
|
|
|
|
|
client, err := NewClient(config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2015-08-22 00:36:19 +00:00
|
|
|
client.SetToken(tokenValue)
|
2015-03-11 22:42:08 +00:00
|
|
|
|
|
|
|
// Verify the token is set
|
|
|
|
if v := client.Token(); v != tokenValue {
|
|
|
|
t.Fatalf("bad: %s", v)
|
|
|
|
}
|
|
|
|
|
|
|
|
client.ClearToken()
|
|
|
|
|
|
|
|
if v := client.Token(); v != "" {
|
|
|
|
t.Fatalf("bad: %s", v)
|
|
|
|
}
|
|
|
|
}
|
2015-03-31 04:20:23 +00:00
|
|
|
|
2020-03-11 13:22:58 +00:00
|
|
|
func TestClientHostHeader(t *testing.T) {
|
|
|
|
handler := func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
w.Write([]byte(req.Host))
|
|
|
|
}
|
|
|
|
config, ln := testHTTPServer(t, http.HandlerFunc(handler))
|
|
|
|
defer ln.Close()
|
|
|
|
|
|
|
|
config.Address = strings.ReplaceAll(config.Address, "127.0.0.1", "localhost")
|
|
|
|
client, err := NewClient(config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the token manually
|
|
|
|
client.SetToken("foo")
|
|
|
|
|
|
|
|
resp, err := client.RawRequest(client.NewRequest("PUT", "/"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the response
|
|
|
|
var buf bytes.Buffer
|
|
|
|
io.Copy(&buf, resp.Body)
|
|
|
|
|
|
|
|
// Verify we got the response from the primary
|
|
|
|
if buf.String() != strings.ReplaceAll(config.Address, "http://", "") {
|
|
|
|
t.Fatalf("Bad address: %s", buf.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-25 00:57:49 +00:00
|
|
|
func TestClientBadToken(t *testing.T) {
|
|
|
|
handler := func(w http.ResponseWriter, req *http.Request) {}
|
|
|
|
|
|
|
|
config, ln := testHTTPServer(t, http.HandlerFunc(handler))
|
|
|
|
defer ln.Close()
|
|
|
|
|
|
|
|
client, err := NewClient(config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
client.SetToken("foo")
|
|
|
|
_, err = client.RawRequest(client.NewRequest("PUT", "/"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
client.SetToken("foo\u007f")
|
|
|
|
_, err = client.RawRequest(client.NewRequest("PUT", "/"))
|
|
|
|
if err == nil || !strings.Contains(err.Error(), "printable") {
|
|
|
|
t.Fatalf("expected error due to bad token")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-20 18:30:35 +00:00
|
|
|
func TestClientRedirect(t *testing.T) {
|
|
|
|
primary := func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
w.Write([]byte("test"))
|
|
|
|
}
|
|
|
|
config, ln := testHTTPServer(t, http.HandlerFunc(primary))
|
|
|
|
defer ln.Close()
|
|
|
|
|
|
|
|
standby := func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
w.Header().Set("Location", config.Address)
|
|
|
|
w.WriteHeader(307)
|
|
|
|
}
|
|
|
|
config2, ln2 := testHTTPServer(t, http.HandlerFunc(standby))
|
|
|
|
defer ln2.Close()
|
|
|
|
|
|
|
|
client, err := NewClient(config2)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2015-09-03 14:36:59 +00:00
|
|
|
// Set the token manually
|
2015-04-20 18:30:35 +00:00
|
|
|
client.SetToken("foo")
|
|
|
|
|
|
|
|
// Do a raw "/" request
|
|
|
|
resp, err := client.RawRequest(client.NewRequest("PUT", "/"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the response
|
|
|
|
var buf bytes.Buffer
|
|
|
|
io.Copy(&buf, resp.Body)
|
|
|
|
|
|
|
|
// Verify we got the response from the primary
|
|
|
|
if buf.String() != "test" {
|
|
|
|
t.Fatalf("Bad: %s", buf.String())
|
|
|
|
}
|
|
|
|
}
|
2015-11-03 19:21:14 +00:00
|
|
|
|
|
|
|
func TestClientEnvSettings(t *testing.T) {
|
|
|
|
cwd, _ := os.Getwd()
|
|
|
|
oldCACert := os.Getenv(EnvVaultCACert)
|
|
|
|
oldCAPath := os.Getenv(EnvVaultCAPath)
|
|
|
|
oldClientCert := os.Getenv(EnvVaultClientCert)
|
|
|
|
oldClientKey := os.Getenv(EnvVaultClientKey)
|
2019-02-28 22:29:28 +00:00
|
|
|
oldSkipVerify := os.Getenv(EnvVaultSkipVerify)
|
2016-07-11 21:37:46 +00:00
|
|
|
oldMaxRetries := os.Getenv(EnvVaultMaxRetries)
|
2016-07-06 20:42:34 +00:00
|
|
|
os.Setenv(EnvVaultCACert, cwd+"/test-fixtures/keys/cert.pem")
|
|
|
|
os.Setenv(EnvVaultCAPath, cwd+"/test-fixtures/keys")
|
|
|
|
os.Setenv(EnvVaultClientCert, cwd+"/test-fixtures/keys/cert.pem")
|
|
|
|
os.Setenv(EnvVaultClientKey, cwd+"/test-fixtures/keys/key.pem")
|
2019-02-28 22:29:28 +00:00
|
|
|
os.Setenv(EnvVaultSkipVerify, "true")
|
2016-07-11 21:37:46 +00:00
|
|
|
os.Setenv(EnvVaultMaxRetries, "5")
|
2016-07-06 20:42:34 +00:00
|
|
|
defer os.Setenv(EnvVaultCACert, oldCACert)
|
|
|
|
defer os.Setenv(EnvVaultCAPath, oldCAPath)
|
|
|
|
defer os.Setenv(EnvVaultClientCert, oldClientCert)
|
|
|
|
defer os.Setenv(EnvVaultClientKey, oldClientKey)
|
2019-02-28 22:29:28 +00:00
|
|
|
defer os.Setenv(EnvVaultSkipVerify, oldSkipVerify)
|
2016-07-11 21:37:46 +00:00
|
|
|
defer os.Setenv(EnvVaultMaxRetries, oldMaxRetries)
|
2015-11-03 19:21:14 +00:00
|
|
|
|
|
|
|
config := DefaultConfig()
|
|
|
|
if err := config.ReadEnvironment(); err != nil {
|
|
|
|
t.Fatalf("error reading environment: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tlsConfig := config.HttpClient.Transport.(*http.Transport).TLSClientConfig
|
|
|
|
if len(tlsConfig.RootCAs.Subjects()) == 0 {
|
|
|
|
t.Fatalf("bad: expected a cert pool with at least one subject")
|
|
|
|
}
|
2017-11-13 15:35:36 +00:00
|
|
|
if tlsConfig.GetClientCertificate == nil {
|
2017-11-12 17:34:56 +00:00
|
|
|
t.Fatalf("bad: expected client tls config to have a certificate getter")
|
2015-11-03 19:21:14 +00:00
|
|
|
}
|
|
|
|
if tlsConfig.InsecureSkipVerify != true {
|
2016-04-13 19:38:29 +00:00
|
|
|
t.Fatalf("bad: %v", tlsConfig.InsecureSkipVerify)
|
2015-11-03 19:21:14 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-18 13:48:31 +00:00
|
|
|
|
2019-07-17 10:29:25 +00:00
|
|
|
func TestClientDeprecatedEnvSettings(t *testing.T) {
|
|
|
|
oldInsecure := os.Getenv(EnvVaultInsecure)
|
|
|
|
os.Setenv(EnvVaultInsecure, "true")
|
|
|
|
defer os.Setenv(EnvVaultInsecure, oldInsecure)
|
|
|
|
|
|
|
|
config := DefaultConfig()
|
|
|
|
if err := config.ReadEnvironment(); err != nil {
|
|
|
|
t.Fatalf("error reading environment: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tlsConfig := config.HttpClient.Transport.(*http.Transport).TLSClientConfig
|
|
|
|
if tlsConfig.InsecureSkipVerify != true {
|
|
|
|
t.Fatalf("bad: %v", tlsConfig.InsecureSkipVerify)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 18:23:59 +00:00
|
|
|
func TestClientEnvNamespace(t *testing.T) {
|
|
|
|
var seenNamespace string
|
|
|
|
handler := func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
seenNamespace = req.Header.Get(consts.NamespaceHeaderName)
|
|
|
|
}
|
|
|
|
config, ln := testHTTPServer(t, http.HandlerFunc(handler))
|
|
|
|
defer ln.Close()
|
|
|
|
|
|
|
|
oldVaultNamespace := os.Getenv(EnvVaultNamespace)
|
|
|
|
defer os.Setenv(EnvVaultNamespace, oldVaultNamespace)
|
|
|
|
os.Setenv(EnvVaultNamespace, "test")
|
|
|
|
|
|
|
|
client, err := NewClient(config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = client.RawRequest(client.NewRequest("GET", "/"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if seenNamespace != "test" {
|
|
|
|
t.Fatalf("Bad: %s", seenNamespace)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:42:06 +00:00
|
|
|
func TestParsingRateAndBurst(t *testing.T) {
|
|
|
|
var (
|
|
|
|
correctFormat = "400:400"
|
|
|
|
observedRate, observedBurst, err = parseRateLimit(correctFormat)
|
2018-05-11 20:28:03 +00:00
|
|
|
expectedRate, expectedBurst = float64(400), 400
|
2018-05-11 14:42:06 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if expectedRate != observedRate {
|
|
|
|
t.Errorf("Expected rate %v but found %v", expectedRate, observedRate)
|
|
|
|
}
|
|
|
|
if expectedBurst != observedBurst {
|
2019-03-19 16:34:13 +00:00
|
|
|
t.Errorf("Expected burst %v but found %v", expectedBurst, observedBurst)
|
2018-05-11 14:42:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParsingRateOnly(t *testing.T) {
|
|
|
|
var (
|
|
|
|
correctFormat = "400"
|
|
|
|
observedRate, observedBurst, err = parseRateLimit(correctFormat)
|
2018-05-11 20:28:03 +00:00
|
|
|
expectedRate, expectedBurst = float64(400), 400
|
2018-05-11 14:42:06 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if expectedRate != observedRate {
|
|
|
|
t.Errorf("Expected rate %v but found %v", expectedRate, observedRate)
|
|
|
|
}
|
|
|
|
if expectedBurst != observedBurst {
|
2019-03-19 16:34:13 +00:00
|
|
|
t.Errorf("Expected burst %v but found %v", expectedBurst, observedBurst)
|
2018-05-11 14:42:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParsingErrorCase(t *testing.T) {
|
|
|
|
var incorrectFormat = "foobar"
|
2018-05-11 20:28:03 +00:00
|
|
|
var _, _, err = parseRateLimit(incorrectFormat)
|
2018-05-11 14:42:06 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Error("Expected error, found no error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 13:48:31 +00:00
|
|
|
func TestClientTimeoutSetting(t *testing.T) {
|
|
|
|
oldClientTimeout := os.Getenv(EnvVaultClientTimeout)
|
|
|
|
os.Setenv(EnvVaultClientTimeout, "10")
|
|
|
|
defer os.Setenv(EnvVaultClientTimeout, oldClientTimeout)
|
|
|
|
config := DefaultConfig()
|
|
|
|
config.ReadEnvironment()
|
2018-05-25 18:38:06 +00:00
|
|
|
_, err := NewClient(config)
|
2017-07-18 13:48:31 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2017-10-10 12:46:54 +00:00
|
|
|
|
|
|
|
type roundTripperFunc func(*http.Request) (*http.Response, error)
|
|
|
|
|
|
|
|
func (rt roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) {
|
|
|
|
return rt(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientNonTransportRoundTripper(t *testing.T) {
|
|
|
|
client := &http.Client{
|
|
|
|
Transport: roundTripperFunc(http.DefaultTransport.RoundTrip),
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := NewClient(&Config{
|
|
|
|
HttpClient: client,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2017-10-27 18:08:30 +00:00
|
|
|
|
|
|
|
func TestClone(t *testing.T) {
|
2020-11-06 19:27:35 +00:00
|
|
|
client1, err := NewClient(DefaultConfig())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("NewClient failed: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set all of the things that we provide setter methods for, which modify config values
|
|
|
|
err = client1.SetAddress("http://example.com:8080")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("SetAddress failed: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
clientTimeout := time.Until(time.Now().AddDate(0, 0, 1))
|
|
|
|
client1.SetClientTimeout(clientTimeout)
|
|
|
|
|
|
|
|
checkRetry := func(ctx context.Context, resp *http.Response, err error) (bool, error) {
|
|
|
|
return true, nil
|
2017-10-27 18:08:30 +00:00
|
|
|
}
|
2020-11-06 19:27:35 +00:00
|
|
|
client1.SetCheckRetry(checkRetry)
|
|
|
|
|
|
|
|
client1.SetLimiter(5.0, 10)
|
|
|
|
client1.SetMaxRetries(5)
|
|
|
|
client1.SetOutputCurlString(true)
|
|
|
|
client1.SetSRVLookup(true)
|
|
|
|
|
|
|
|
client2, err := client1.Clone()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Clone failed: %v", err)
|
2017-10-27 18:08:30 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 19:27:35 +00:00
|
|
|
if client1.Address() != client2.Address() {
|
|
|
|
t.Fatalf("addresses don't match: %v vs %v", client1.Address(), client2.Address())
|
|
|
|
}
|
|
|
|
if client1.ClientTimeout() != client2.ClientTimeout() {
|
|
|
|
t.Fatalf("timeouts don't match: %v vs %v", client1.ClientTimeout(), client2.ClientTimeout())
|
|
|
|
}
|
|
|
|
if client1.CheckRetry() != nil && client2.CheckRetry() == nil {
|
|
|
|
t.Fatal("checkRetry functions don't match. client2 is nil.")
|
|
|
|
}
|
|
|
|
if (client1.Limiter() != nil && client2.Limiter() == nil) || (client1.Limiter() == nil && client2.Limiter() != nil) {
|
|
|
|
t.Fatalf("limiters don't match: %v vs %v", client1.Limiter(), client2.Limiter())
|
|
|
|
}
|
|
|
|
if client1.Limiter().Limit() != client2.Limiter().Limit() {
|
|
|
|
t.Fatalf("limiter limits don't match: %v vs %v", client1.Limiter().Limit(), client2.Limiter().Limit())
|
|
|
|
}
|
|
|
|
if client1.Limiter().Burst() != client2.Limiter().Burst() {
|
|
|
|
t.Fatalf("limiter bursts don't match: %v vs %v", client1.Limiter().Burst(), client2.Limiter().Burst())
|
|
|
|
}
|
|
|
|
if client1.MaxRetries() != client2.MaxRetries() {
|
|
|
|
t.Fatalf("maxRetries don't match: %v vs %v", client1.MaxRetries(), client2.MaxRetries())
|
|
|
|
}
|
|
|
|
if client1.OutputCurlString() != client2.OutputCurlString() {
|
|
|
|
t.Fatalf("outputCurlString doesn't match: %v vs %v", client1.OutputCurlString(), client2.OutputCurlString())
|
|
|
|
}
|
|
|
|
if client1.SRVLookup() != client2.SRVLookup() {
|
|
|
|
t.Fatalf("SRVLookup doesn't match: %v vs %v", client1.SRVLookup(), client2.SRVLookup())
|
|
|
|
}
|
2017-10-27 18:08:30 +00:00
|
|
|
}
|
2020-01-09 22:56:34 +00:00
|
|
|
|
|
|
|
func TestSetHeadersRaceSafe(t *testing.T) {
|
|
|
|
client, err1 := NewClient(nil)
|
|
|
|
if err1 != nil {
|
|
|
|
t.Fatalf("NewClient failed: %v", err1)
|
|
|
|
}
|
|
|
|
|
|
|
|
start := make(chan interface{})
|
|
|
|
done := make(chan interface{})
|
|
|
|
|
|
|
|
testPairs := map[string]string{
|
|
|
|
"soda": "rootbeer",
|
|
|
|
"veggie": "carrots",
|
|
|
|
"fruit": "apples",
|
|
|
|
"color": "red",
|
|
|
|
"protein": "egg",
|
|
|
|
}
|
|
|
|
|
|
|
|
for key, value := range testPairs {
|
|
|
|
tmpKey := key
|
|
|
|
tmpValue := value
|
|
|
|
go func() {
|
|
|
|
<-start
|
|
|
|
// This test fails if here, you replace client.AddHeader(tmpKey, tmpValue) with:
|
|
|
|
// headerCopy := client.Header()
|
|
|
|
// headerCopy.AddHeader(tmpKey, tmpValue)
|
|
|
|
// client.SetHeader(headerCopy)
|
|
|
|
client.AddHeader(tmpKey, tmpValue)
|
|
|
|
done <- true
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start everyone at once.
|
|
|
|
close(start)
|
|
|
|
|
|
|
|
// Wait until everyone is done.
|
|
|
|
for i := 0; i < len(testPairs); i++ {
|
|
|
|
<-done
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that all the test pairs are in the resulting
|
|
|
|
// headers.
|
|
|
|
resultingHeaders := client.Headers()
|
|
|
|
for key, value := range testPairs {
|
|
|
|
if resultingHeaders.Get(key) != value {
|
|
|
|
t.Fatal("expected " + value + " for " + key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|