-
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
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package util
import (
"net"
"testing"
"github.com/stretchr/testify/assert"
)
func TestIsIPPPrivate(t *testing.T) {
cases := []struct {
ip string
isPrivate bool
}{
// case 0
{
ip: "127.0.0.1",
isPrivate: false, // TODO: according to go, this isn't private?
},
// case 1
{
ip: "127.1.2.3",
isPrivate: false, // TODO: according to go, this isn't private?
},
// case 2
{
ip: "10.255.255.0",
isPrivate: true,
},
// case 3
{
ip: "8.8.8.8",
isPrivate: false,
},
// case 4
{
ip: "::1",
isPrivate: false, // TODO: according to go, this isn't private?
},
// case 4
{
ip: "2a12:7c40::f00d",
isPrivate: false,
},
}
for n, c := range cases {
i := net.ParseIP(c.ip)
p := IsIPPrivate(i)
assert.Equal(t, c.isPrivate, p, "case %d: should be equal", n)
}
}