(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestIsLocalHostname(t *testing.T) { |
| 10 | tests := []struct { |
| 11 | hostname string |
| 12 | allowlist []string |
| 13 | want bool |
| 14 | }{ |
| 15 | {hostname: "localhost", want: true}, // #00 |
| 16 | {hostname: "127.0.0.1", want: true}, // #01 |
| 17 | {hostname: "::1", want: true}, // #02 |
| 18 | {hostname: "0:0:0:0:0:0:0:1", want: true}, // #03 |
| 19 | {hostname: "127.0.0.95", want: true}, // #04 |
| 20 | {hostname: "0.0.0.0", want: true}, // #05 |
| 21 | {hostname: "192.168.123.45", want: true}, // #06 |
| 22 | |
| 23 | {hostname: "gogs.io", want: false}, // #07 |
| 24 | {hostname: "google.com", want: false}, // #08 |
| 25 | {hostname: "165.232.140.255", want: false}, // #09 |
| 26 | |
| 27 | {hostname: "192.168.123.45", allowlist: []string{"10.0.0.17"}, want: true}, // #10 |
| 28 | {hostname: "gogs.local", allowlist: []string{"gogs.local"}, want: false}, // #11 |
| 29 | |
| 30 | {hostname: "192.168.123.45", allowlist: []string{"*"}, want: false}, // #12 |
| 31 | } |
| 32 | for _, test := range tests { |
| 33 | t.Run("", func(t *testing.T) { |
| 34 | assert.Equal(t, test.want, IsBlockedLocalHostname(test.hostname, test.allowlist)) |
| 35 | }) |
| 36 | } |
| 37 | } |
nothing calls this directly
no test coverage detected