Skip to content

Commit

Permalink
fix: http_readlimit_test should reuse port
Browse files Browse the repository at this point in the history
  • Loading branch information
developStorm committed Jan 10, 2025
1 parent 3b4db6f commit 8b27ecc
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion modules/http/http_readlimit_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package http

import (
"context"
"crypto/rsa"
"encoding/hex"
"fmt"
"io"
"math/big"
"net"
"strings"
"syscall"
"testing"
"time"

"github.com/zmap/zcrypto/tls"
"github.com/zmap/zgrab2"
"github.com/zmap/zgrab2/lib/http"
"golang.org/x/sys/unix"
)

// BEGIN Taken from handshake_server_test.go -- certs for TLS server
Expand Down Expand Up @@ -81,7 +84,18 @@ func _write(writer io.Writer, data []byte) error {
// XXXX....
func (cfg *readLimitTestConfig) runFakeHTTPServer(t *testing.T) {
endpoint := fmt.Sprintf("127.0.0.1:%d", cfg.port)
listener, err := net.Listen("tcp", endpoint)
lc := net.ListenConfig{
Control: func(network, address string, c syscall.RawConn) error {
var opErr error
if err := c.Control(func(fd uintptr) {
opErr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
}); err != nil {
return err
}
return opErr
},
}
listener, err := lc.Listen(context.Background(), "tcp", endpoint)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 8b27ecc

Please sign in to comment.