Skip to content

Commit af9584b

Browse files
authored
feat: unban ipv6 address (#3573)
* feat: unban ipv6 address * chore: update unit tests
1 parent 0808336 commit af9584b

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

internal/bans/update/update.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,17 @@ import (
1313

1414
func validateIps(ips []string) error {
1515
for _, ip := range ips {
16-
ip := net.ParseIP(ip)
17-
if ip.To4() == nil {
18-
return errors.Errorf("only IPv4 supported at the moment: %s", ip)
16+
if net.ParseIP(ip) == nil {
17+
return errors.Errorf("invalid IP address: %s", ip)
1918
}
2019
}
2120
return nil
2221
}
2322

2423
func Run(ctx context.Context, projectRef string, dbIpsToUnban []string, fsys afero.Fs) error {
2524
// 1. sanity checks
26-
{
27-
err := validateIps(dbIpsToUnban)
28-
if err != nil {
29-
return err
30-
}
25+
if err := validateIps(dbIpsToUnban); err != nil {
26+
return err
3127
}
3228

3329
// 2. remove bans

internal/bans/update/update_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ import (
88

99
func TestPrivateSubnet(t *testing.T) {
1010
err := validateIps([]string{"12.3.4.5", "10.0.0.0", "1.2.3.1"})
11-
assert.Nil(t, err)
11+
assert.NoError(t, err)
1212
}
1313

14-
func TestIpv4(t *testing.T) {
15-
err := validateIps([]string{"12.3.4.5", "2001:db8:abcd:0012::0", "1.2.3.1"})
16-
assert.ErrorContains(t, err, "only IPv4 supported at the moment: 2001:db8:abcd:12::")
14+
func TestIPv6(t *testing.T) {
15+
err := validateIps([]string{"2001:db8:abcd:0012::0", "::0"})
16+
assert.NoError(t, err)
17+
}
18+
19+
func TestInvalidAddress(t *testing.T) {
20+
err := validateIps([]string{"12.3.4"})
21+
assert.ErrorContains(t, err, "invalid IP address: 12.3.4")
1722
}

0 commit comments

Comments
 (0)