Skip to content

Commit

Permalink
Don't use static listener ports for unit tests
Browse files Browse the repository at this point in the history
Unit tests fail if anything on the system is bound to port 9000; instead
we bind to port 0 and allow the system to choose.
  • Loading branch information
lz-censys committed Oct 25, 2023
1 parent 7dfa4e9 commit 756029a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions url/rawparam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package urlutil

import (
"fmt"
"net"
"net/http"
"net/url"
"testing"
Expand Down Expand Up @@ -52,17 +53,20 @@ func TestParamIntegration(t *testing.T) {
w.WriteHeader(http.StatusOK)
})
//nolint:all
go http.ListenAndServe(":9000", nil)
listener, err := net.Listen("tcp", ":0")
require.Nil(t, err)

go http.Serve(listener, nil)

p := NewParams()
p.Add("sqli", "1+AND+(SELECT+*+FROM+(SELECT(SLEEP(12)))nQIP)")
p.Add("xss", "<script>alert('XSS')</script>")
p.Add("xssiwthspace", "<svg id=alert(1) onload=eval(id)>")
p.Add("jsprotocol", "javascript://alert(1)")

url, _ := url.Parse("http://localhost:9000/params")
url, _ := url.Parse("http://" + listener.Addr().String() + "/params")
url.RawQuery = p.Encode()
_, err := http.Get(url.String())
_, err = http.Get(url.String())
require.Nil(t, err)
require.Nil(t, routerErr)
}
Expand Down

0 comments on commit 756029a

Please sign in to comment.