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"
|
|
|
|
|
2020-09-02 03:20:01 +02:00
|
|
|
"github.com/go-acme/lego/v4/acme"
|
|
|
|
"github.com/go-acme/lego/v4/acme/api/internal/nonces"
|
|
|
|
"github.com/go-acme/lego/v4/acme/api/internal/sender"
|
|
|
|
"github.com/go-acme/lego/v4/platform/tester"
|
2018-12-06 23:50:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNotHoldingLockWhileMakingHTTPRequests(t *testing.T) {
|
2021-11-02 01:52:38 +02:00
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
2018-12-06 23:50:17 +02:00
|
|
|
time.Sleep(250 * time.Millisecond)
|
2020-10-17 14:51:55 +02:00
|
|
|
w.Header().Set("Replay-Nonce", "12345")
|
|
|
|
w.Header().Set("Retry-After", "0")
|
2018-12-06 23:50:17 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}))
|
2021-11-02 01:52:38 +02:00
|
|
|
t.Cleanup(server.Close)
|
2018-12-06 23:50:17 +02:00
|
|
|
|
|
|
|
doer := sender.NewDoer(http.DefaultClient, "lego-test")
|
2021-11-02 01:52:38 +02:00
|
|
|
j := nonces.NewManager(doer, server.URL)
|
2018-12-06 23:50:17 +02:00
|
|
|
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:
|
2022-09-17 20:04:47 +02:00
|
|
|
case <-time.After(500 * time.Millisecond):
|
2018-12-06 23:50:17 +02:00
|
|
|
t.Fatal("JWS is probably holding a lock while making HTTP request")
|
|
|
|
}
|
|
|
|
}
|