Skip to content

Commit

Permalink
chore(validate): fix listen address test for bind capable environment
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Mar 23, 2024
1 parent 6cc9afe commit 021e75a
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions validate/listenaddress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,24 @@ func Test_ListeningAddress(t *testing.T) {
// one privileged port in the system.
if unprivilegedPortStart > 1 {
lastPrivilegedPort := unprivilegedPortStart - 1
testCases["privileged_port_without_root"] = testCaseStruct{
address: fmt.Sprintf("1.2.3.4:%d", lastPrivilegedPort),
uid: 1000,
errWrapped: ErrPrivilegedPort,
errMessage: fmt.Sprintf("listening on privileged port is not allowed: "+
"port %d (user id 1000, unprivileged start port %d)",
lastPrivilegedPort, unprivilegedPortStart),
hasNetBindCap, err := hasNetBindServiceCapability()
if err != nil {
t.Fatal(err)
}

privilegedPortWithoutRootCase := testCaseStruct{
address: fmt.Sprintf("1.2.3.4:%d", lastPrivilegedPort),
uid: 1000,
}
if !hasNetBindCap {
privilegedPortWithoutRootCase.errWrapped = ErrPrivilegedPort
privilegedPortWithoutRootCase.errMessage = fmt.Sprintf(
"listening on privileged port is not allowed: port %d "+
"(user id 1000, unprivileged start port %d)",
lastPrivilegedPort, unprivilegedPortStart)
}
testCases["privileged_port_without_root"] = privilegedPortWithoutRootCase

testCases["allowed_privileged_port_without_root"] = testCaseStruct{
address: fmt.Sprintf("1.2.3.4:%d", lastPrivilegedPort),
uid: 1000,
Expand Down

0 comments on commit 021e75a

Please sign in to comment.