MCPcopy Index your code
hub / github.com/coder/coder / TestIPV4Check

Function TestIPV4Check

cli/cliutil/awscheck_internal_test.go:16–96  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestIPV4Check(t *testing.T) {
17 t.Parallel()
18 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
19 httpapi.Write(context.Background(), w, http.StatusOK, awsIPRangesResponse{
20 IPV4Prefixes: []awsIPv4Prefix{
21 {
22 Prefix: "3.24.0.0/14",
23 },
24 {
25 Prefix: "15.230.15.29/32",
26 },
27 {
28 Prefix: "47.128.82.100/31",
29 },
30 },
31 IPV6Prefixes: []awsIPv6Prefix{
32 {
33 Prefix: "2600:9000:5206::/48",
34 },
35 {
36 Prefix: "2406:da70:8800::/40",
37 },
38 {
39 Prefix: "2600:1f68:5000::/40",
40 },
41 },
42 })
43 }))
44 t.Cleanup(srv.Close)
45 ctx := testutil.Context(t, testutil.WaitShort)
46 ranges, err := FetchAWSIPRanges(ctx, srv.URL)
47 require.NoError(t, err)
48
49 t.Run("Private/IPV4", func(t *testing.T) {
50 t.Parallel()
51 ip, err := netip.ParseAddr("192.168.0.1")
52 require.NoError(t, err)
53 isAws := ranges.CheckIP(ip)
54 require.False(t, isAws)
55 })
56
57 t.Run("AWS/IPV4", func(t *testing.T) {
58 t.Parallel()
59 ip, err := netip.ParseAddr("3.25.61.113")
60 require.NoError(t, err)
61 isAws := ranges.CheckIP(ip)
62 require.True(t, isAws)
63 })
64
65 t.Run("NonAWS/IPV4", func(t *testing.T) {
66 t.Parallel()
67 ip, err := netip.ParseAddr("159.196.123.40")
68 require.NoError(t, err)
69 isAws := ranges.CheckIP(ip)
70 require.False(t, isAws)
71 })
72
73 t.Run("Private/IPV6", func(t *testing.T) {

Callers

nothing calls this directly

Calls 6

WriteFunction · 0.92
ContextFunction · 0.92
FetchAWSIPRangesFunction · 0.85
CheckIPMethod · 0.80
CleanupMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected