Skip to content

Commit fbbb380

Browse files
committed
http: skip ssl verification only in tests
1 parent 295cf59 commit fbbb380

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

daemon.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type daemon struct {
4242
dhtMessenger *dhtpb.ProtocolMessenger
4343
createTestHost func() (host.Host, error)
4444
promRegistry *prometheus.Registry
45+
httpSkipVerify bool
4546
}
4647

4748
const (
@@ -252,7 +253,7 @@ func (d *daemon) runCidCheck(ctx context.Context, cidKey cid.Cid, ipniURL string
252253
return
253254
}
254255
defer testHost.Close()
255-
httpCheck := checkHTTPRetrieval(ctx, testHost, cidKey, httpInfo)
256+
httpCheck := checkHTTPRetrieval(ctx, testHost, cidKey, httpInfo, d.httpSkipVerify)
256257
provOutput.DataAvailableOverHTTP = httpCheck
257258
if !httpCheck.Connected {
258259
provOutput.ConnectionError = httpCheck.Error
@@ -385,7 +386,7 @@ func (d *daemon) runPeerCheck(ctx context.Context, ma multiaddr.Multiaddr, ai pe
385386

386387
// If they provided an http address and enabled retrieval, try that.
387388
if len(httpInfo.Addrs) > 0 && httpRetrieval {
388-
httpCheck := checkHTTPRetrieval(ctx, testHost, c, httpInfo)
389+
httpCheck := checkHTTPRetrieval(ctx, testHost, c, httpInfo, d.httpSkipVerify)
389390
out.DataAvailableOverHTTP = httpCheck
390391
if !httpCheck.Connected {
391392
out.ConnectionError = httpCheck.Error
@@ -520,7 +521,7 @@ func supportsHEAD(pstore peerstore.Peerstore, p peer.ID) bool {
520521
return ok && b
521522
}
522523

523-
func checkHTTPRetrieval(ctx context.Context, host host.Host, c cid.Cid, pinfo peer.AddrInfo) HTTPCheckOutput {
524+
func checkHTTPRetrieval(ctx context.Context, host host.Host, c cid.Cid, pinfo peer.AddrInfo, skipVerify bool) HTTPCheckOutput {
524525
log.Printf("Start of HTTP check for cid %s by attempting to connect to %s", c, pinfo)
525526

526527
out := HTTPCheckOutput{
@@ -530,7 +531,7 @@ func checkHTTPRetrieval(ctx context.Context, host host.Host, c cid.Cid, pinfo pe
530531
htnet := httpnet.New(host,
531532
httpnet.WithUserAgent(userAgent),
532533
httpnet.WithResponseHeaderTimeout(5*time.Second), // default: 10
533-
httpnet.WithInsecureSkipVerify(true),
534+
httpnet.WithInsecureSkipVerify(skipVerify),
534535
httpnet.WithHTTPWorkers(1),
535536
)
536537
defer htnet.Stop()

integration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func TestBasicIntegration(t *testing.T) {
161161
createTestHost: func() (host.Host, error) {
162162
return libp2p.New(libp2p.EnableHolePunching())
163163
},
164+
httpSkipVerify: true,
164165
}
165166
_ = startServer(ctx, d, ":1234", "", "")
166167
}()

0 commit comments

Comments
 (0)