Skip to content

Commit

Permalink
fix: middleware test
Browse files Browse the repository at this point in the history
Gin update to 1.7 broke the work with IP addresses of clients:
now 'X-Forwarded-For' and 'X-Real-Ip' headers needs to be set as
trusted for 'c.ClientIP()' method to successfully read the client's IP
in case 'gin.Run' method is not used. Related issue:
gin-gonic/gin#2697
  • Loading branch information
akijakya committed Jan 24, 2022
1 parent 0588dd3 commit b598453
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/platform/gin/auditlog/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestMiddleware(t *testing.T) {
RequestBody: body,
StatusCode: http.StatusOK,
ResponseTime: 1000,
ResponseSize: 18,
ResponseSize: 17,
Errors: nil,
},
}
Expand All @@ -77,7 +77,9 @@ func TestMiddleware(t *testing.T) {

middleware := Middleware(driver, WithClock(clock), WithUserIDExtractor(userIDExtractor))

gin.SetMode(gin.ReleaseMode)
engine := gin.New()
engine.TrustedPlatform = "X-Real-Ip"
engine.Use(func(c *gin.Context) { c.Set(correlationid.ContextKey, "cid") }, middleware)
engine.POST("/", func(c *gin.Context) {
clock.Advance(time.Second)
Expand Down

0 comments on commit b598453

Please sign in to comment.