-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_ip_test.go
More file actions
31 lines (23 loc) · 822 Bytes
/
user_ip_test.go
File metadata and controls
31 lines (23 loc) · 822 Bytes
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
package user_ip
import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)
func TestGetNoIp(t *testing.T) {
req := &http.Request{Method: "GET"}
ip := Get(req)
assert.Equal(t, ip, "", "Should not find an ip address.")
}
func TestGetWithPrivateForwadedIp(t *testing.T) {
req := &http.Request{Method: "GET", Header: make(http.Header)}
ip := Get(req)
req.Header.Set("X-Forwarded-For", "100.64.0.0, 192.168.0.0")
assert.Equal(t, ip, "", "Should not find an ip address.")
}
func TestGetWithGlobalAndPrivateForwardedIps(t *testing.T) {
req := &http.Request{Method: "GET", Header: make(http.Header)}
req.Header.Set("X-Forwarded-For", "65.55.37.104, 100.64.0.0, 192.168.0.0, 192.0.0.0")
ip := Get(req)
assert.Equal(t, ip, "65.55.37.104", "Should be the first ip, which is the global ip address.")
}