Merge pull request #22 from tsenart/dont-verify-certs
Suport a curl -k mode?
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package vegeta
|
package vegeta
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@@ -39,12 +40,20 @@ func drill(rate uint64, reqs chan *http.Request, res chan Result) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var client = &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// hit executes the passed http.Request and puts the result into results.
|
// hit executes the passed http.Request and puts the result into results.
|
||||||
// Both transport errors and unsucessfull requests (non {2xx,3xx}) are
|
// Both transport errors and unsucessfull requests (non {2xx,3xx}) are
|
||||||
// considered errors.
|
// considered errors.
|
||||||
func hit(req *http.Request, res chan Result) {
|
func hit(req *http.Request, res chan Result) {
|
||||||
began := time.Now()
|
began := time.Now()
|
||||||
r, err := http.DefaultClient.Do(req)
|
r, err := client.Do(req)
|
||||||
result := Result{
|
result := Result{
|
||||||
Timestamp: began,
|
Timestamp: began,
|
||||||
Timing: time.Since(began),
|
Timing: time.Since(began),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package vegeta
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -22,3 +23,16 @@ func TestAttackRate(t *testing.T) {
|
|||||||
t.Fatalf("Wrong number of hits: want %d, got %d\n", rate, hits)
|
t.Fatalf("Wrong number of hits: want %d, got %d\n", rate, hits)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClientCertConfig(t *testing.T) {
|
||||||
|
server := httptest.NewTLSServer(
|
||||||
|
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}),
|
||||||
|
)
|
||||||
|
request, _ := http.NewRequest("GET", server.URL, nil)
|
||||||
|
results := make(chan Result, 1)
|
||||||
|
hit(request, results)
|
||||||
|
result := <-results
|
||||||
|
if strings.Contains(result.Error, "x509: certificate signed by unknown authority") {
|
||||||
|
t.Errorf("Invalid certificates should be ignored: Got `%s`", result.Error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user