Skip to content

Commit

Permalink
update: test ip
Browse files Browse the repository at this point in the history
  • Loading branch information
starsz committed Apr 29, 2021
1 parent 99fca5e commit 2e72edb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions api/internal/filter/ip_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ func TestIPFilter_Handle(t *testing.T) {
assert.Equal(t, 200, w.Code)

// should forbidden
conf.AllowList = []string{"8.8.8.8"}
conf.AllowList = []string{"127.0.0.1"}
r = gin.New()
r.Use(IPFilter())
r.GET("/test", func(c *gin.Context) {})

req := httptest.NewRequest("GET", "/test", nil)
req.Header.Set("X-Forwarded-For", "8.8.8.8")
req.Header.Set("X-Forwarded-For", "127.0.0.1")
w = httptest.NewRecorder()
r.ServeHTTP(w, req)
assert.Equal(t, 403, w.Code)

req = httptest.NewRequest("GET", "/test", nil)
req.Header.Set("X-Real-Ip", "8.8.8.8")
req.Header.Set("X-Real-Ip", "127.0.0.1")
w = httptest.NewRecorder()
r.ServeHTTP(w, req)
assert.Equal(t, 403, w.Code)
Expand Down

0 comments on commit 2e72edb

Please sign in to comment.