-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathenv_test.go
More file actions
32 lines (24 loc) · 1.04 KB
/
env_test.go
File metadata and controls
32 lines (24 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package server
import (
"net/netip"
"os"
"slices"
"testing"
"github.com/go-playground/assert/v2"
)
func TestLimitExcludePrefixes(t *testing.T) {
v := os.Getenv("WARP_LIMIT_EXCLUDE_SUBNETS")
defer os.Setenv("WARP_LIMIT_EXCLUDE_SUBNETS", v)
os.Setenv("WARP_LIMIT_EXCLUDE_SUBNETS", "10.0.0.0/8;172.16.0.0/12;192.168.0.0/16")
prefixes := limitExcludePrefixes()
assert.Equal(t, len(prefixes), 3)
assert.Equal(t, slices.Contains(prefixes, netip.MustParsePrefix("10.0.0.0/8")), true)
assert.Equal(t, slices.Contains(prefixes, netip.MustParsePrefix("172.16.0.0/12")), true)
assert.Equal(t, slices.Contains(prefixes, netip.MustParsePrefix("192.168.0.0/16")), true)
assert.Equal(t, IsLimitExcludeAddr(netip.MustParseAddr("1.1.1.1")), false)
assert.Equal(t, IsLimitExcludeAddr(netip.MustParseAddr("192.168.1.1")), true)
assert.Equal(t, IsLimitExcludeAddr(netip.MustParseAddr("10.1.1.1")), true)
assert.Equal(t, IsLimitExcludeAddr(netip.MustParseAddr("172.16.1.1")), true)
os.Setenv("WARP_LIMIT_EXCLUDE_SUBNETS", "")
prefixes = limitExcludePrefixes()
}