-
-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into port-forward-only
- Loading branch information
Showing
3 changed files
with
84 additions
and
1 deletion.
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
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,76 @@ | ||
package settings | ||
|
||
import ( | ||
"net/netip" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_Firewall_validate(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := map[string]struct { | ||
firewall Firewall | ||
errWrapped error | ||
errMessage string | ||
}{ | ||
"empty": {}, | ||
"zero_vpn_input_port": { | ||
firewall: Firewall{ | ||
VPNInputPorts: []uint16{0}, | ||
}, | ||
errWrapped: ErrFirewallZeroPort, | ||
errMessage: "VPN input ports: cannot have a zero port", | ||
}, | ||
"zero_input_port": { | ||
firewall: Firewall{ | ||
InputPorts: []uint16{0}, | ||
}, | ||
errWrapped: ErrFirewallZeroPort, | ||
errMessage: "input ports: cannot have a zero port", | ||
}, | ||
"unspecified_outbound_subnet": { | ||
firewall: Firewall{ | ||
OutboundSubnets: []netip.Prefix{ | ||
netip.MustParsePrefix("0.0.0.0/0"), | ||
}, | ||
}, | ||
errWrapped: ErrFirewallPublicOutboundSubnet, | ||
errMessage: "outbound subnet is public: 0.0.0.0/0", | ||
}, | ||
"public_outbound_subnet": { | ||
firewall: Firewall{ | ||
OutboundSubnets: []netip.Prefix{ | ||
netip.MustParsePrefix("1.2.3.4/32"), | ||
}, | ||
}, | ||
errWrapped: ErrFirewallPublicOutboundSubnet, | ||
errMessage: "outbound subnet is public: 1.2.3.4/32", | ||
}, | ||
"valid_settings": { | ||
firewall: Firewall{ | ||
VPNInputPorts: []uint16{100, 101}, | ||
InputPorts: []uint16{200, 201}, | ||
OutboundSubnets: []netip.Prefix{ | ||
netip.MustParsePrefix("192.168.1.0/24"), | ||
netip.MustParsePrefix("10.10.1.1/32"), | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for name, testCase := range testCases { | ||
testCase := testCase | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
err := testCase.firewall.validate() | ||
|
||
assert.ErrorIs(t, err, testCase.errWrapped) | ||
if testCase.errWrapped != nil { | ||
assert.EqualError(t, err, testCase.errMessage) | ||
} | ||
}) | ||
} | ||
} |