Skip to content

Commit

Permalink
test(cli): https rpc support
Browse files Browse the repository at this point in the history
makes sure we dont have regression where HTTPS endpoint
starts getting cleartext requests
  • Loading branch information
lidel committed Jan 10, 2025
1 parent e28e3fb commit 985bfba
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/cli/cli_https_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cli

import (
"fmt"
"net"
"net/http"
"net/http/httptest"
"net/url"
"testing"

"github.com/ipfs/kubo/test/cli/harness"
"github.com/stretchr/testify/require"
)

func TestCLIWithRemoteHTTPS(t *testing.T) {
tests := []struct{ addrSuffix string }{{"https"}, {"tls/http"}}
for _, tt := range tests {
t.Run("with "+tt.addrSuffix+" multiaddr", func(t *testing.T) {

// Create HTTPS test server
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.TLS == nil {
t.Error("Mocked Kubo RPC received plain HTTP request instead of HTTPS TLS Handshake")
}
w.Write([]byte("OK"))

Check failure on line 25 in test/cli/cli_https_test.go

View workflow job for this annotation

GitHub Actions / go-lint

Error return value of `w.Write` is not checked (errcheck)
}))
defer server.Close()

serverURL, _ := url.Parse(server.URL)
_, port, _ := net.SplitHostPort(serverURL.Host)

// Create Kubo repo
node := harness.NewT(t).NewNode().Init()

// Attempt to talk to remote Kubo RPC endpoint over HTTPS
resp := node.RunIPFS("id", "--api", fmt.Sprintf("/ip4/127.0.0.1/tcp/%s/%s", port, tt.addrSuffix))

// Expect HTTPS error (confirming TLS and https:// were used, and not Cleartext HTTP)
require.Error(t, resp.Err)
require.Contains(t, resp.Stderr.String(), "Error: tls: failed to verify certificate: x509: certificate signed by unknown authority")

node.StopDaemon()

})
}
}

0 comments on commit 985bfba

Please sign in to comment.