2019-03-11 18:56:48 +02:00
|
|
|
package secure
|
2018-12-06 23:50:17 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2019-03-11 18:56:48 +02:00
|
|
|
"github.com/go-acme/lego/acme"
|
|
|
|
"github.com/go-acme/lego/acme/api/internal/nonces"
|
|
|
|
"github.com/go-acme/lego/acme/api/internal/sender"
|
|
|
|
"github.com/go-acme/lego/platform/tester"
|
2018-12-06 23:50:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNotHoldingLockWhileMakingHTTPRequests(t *testing.T) {
|
2019-02-06 19:15:53 +02:00
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
2018-12-06 23:50:17 +02:00
|
|
|
time.Sleep(250 * time.Millisecond)
|
|
|
|
w.Header().Add("Replay-Nonce", "12345")
|
|
|
|
w.Header().Add("Retry-After", "0")
|
|
|
|
err := tester.WriteJSONResponse(w, &acme.Challenge{Type: "http-01", Status: "Valid", URL: "http://example.com/", Token: "token"})
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
doer := sender.NewDoer(http.DefaultClient, "lego-test")
|
|
|
|
j := nonces.NewManager(doer, ts.URL)
|
|
|
|
ch := make(chan bool)
|
|
|
|
resultCh := make(chan bool)
|
|
|
|
go func() {
|
|
|
|
_, errN := j.Nonce()
|
|
|
|
if errN != nil {
|
|
|
|
t.Log(errN)
|
|
|
|
}
|
|
|
|
ch <- true
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
_, errN := j.Nonce()
|
|
|
|
if errN != nil {
|
|
|
|
t.Log(errN)
|
|
|
|
}
|
|
|
|
ch <- true
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
<-ch
|
|
|
|
<-ch
|
|
|
|
resultCh <- true
|
|
|
|
}()
|
|
|
|
select {
|
|
|
|
case <-resultCh:
|
|
|
|
case <-time.After(400 * time.Millisecond):
|
|
|
|
t.Fatal("JWS is probably holding a lock while making HTTP request")
|
|
|
|
}
|
|
|
|
}
|