-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The string fed into the ParseIP function needs to not have a port. This does that and adds a test to check the desired behavior. Closes: #1689 Signed-off-by: Hank Donnay <hdonnay@redhat.com> (cherry picked from commit b18f989)
- Loading branch information
Showing
2 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package httputil | ||
|
||
import ( | ||
"errors" | ||
"net" | ||
"testing" | ||
) | ||
|
||
func TestLocalOnly(t *testing.T) { | ||
tt := []struct { | ||
Network string | ||
Addr string | ||
Err *net.AddrError | ||
}{ | ||
{ | ||
Network: "tcp4", | ||
Addr: "192.168.0.1:443", | ||
Err: nil, | ||
}, | ||
{ | ||
Network: "tcp4", | ||
Addr: "127.0.0.1:443", | ||
Err: nil, | ||
}, | ||
{ | ||
Network: "tcp6", | ||
Addr: "[fe80::]:443", | ||
Err: nil, | ||
}, | ||
{ | ||
Network: "tcp4", | ||
Addr: "8.8.8.8:443", | ||
Err: &net.AddrError{ | ||
Addr: "tcp4!8.8.8.8:443", | ||
Err: "disallowed by policy", | ||
}, | ||
}, | ||
{ | ||
Network: "tcp6", | ||
Addr: "[2000::]:443", | ||
Err: &net.AddrError{ | ||
Addr: "tcp6![2000::]:443", | ||
Err: "disallowed by policy", | ||
}, | ||
}, | ||
} | ||
for _, tc := range tt { | ||
t.Logf("%s!%s", tc.Network, tc.Addr) | ||
var nErr *net.AddrError | ||
got := ctlLocalOnly(tc.Network, tc.Addr, nil) | ||
if errors.As(got, &nErr) { | ||
if tc.Err.Err != nErr.Err || tc.Err.Addr != nErr.Addr { | ||
t.Errorf("got: %v, want: %v", got, tc.Err) | ||
} | ||
} | ||
} | ||
} |