mirrored from https://git.sr.ht/~ancarda/tls-redirector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
34 lines (27 loc) · 992 Bytes
/
util_test.go
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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRemoveSquareBrackets(t *testing.T) {
assert.Equal(t, "[::1]a", removeSquareBrackets("[::1]a"))
assert.Equal(t, "a[::1]", removeSquareBrackets("a[::1]"))
assert.Equal(t, "::1", removeSquareBrackets("[::1]"))
}
func TestIsIPAddress_IPv4(t *testing.T) {
assert.True(t, isIPAddress("127.0.0.1"), "IPv4 address")
assert.True(t, isIPAddress("127.0.0.1:8080"), "IPv4 address with port")
}
func TestIsIPAddress_IPv6(t *testing.T) {
assert.True(t, isIPAddress("::1"), "IPv6 address")
assert.True(t, isIPAddress("[::1]"), "IPv6 address inside brackets")
assert.True(t, isIPAddress("[::1]:8080"), "IPv6 address with port")
}
func TestIsIPAddress_InvalidIPAddresses(t *testing.T) {
assert.False(t, isIPAddress("1.2.3.4.5"))
assert.False(t, isIPAddress("256.1.1.1"))
}
func TestIsIPAddress_RejectOtherStrings(t *testing.T) {
assert.False(t, isIPAddress("example.com"))
assert.False(t, isIPAddress(""))
}