diff --git a/authorization_test.go b/authorization_test.go index c8648d019fc46a0914228dc3268d5c916f47dfc6..726ae580f2c0c164aeb4f3ce4803ace1765815c2 100644 --- a/authorization_test.go +++ b/authorization_test.go @@ -7,7 +7,7 @@ import ( "regexp" "testing" - "github.com/dgrijalva/jwt-go" + jwt "github.com/dgrijalva/jwt-go" "gitlab.com/gitlab-org/gitlab-workhorse/internal/api" "gitlab.com/gitlab-org/gitlab-workhorse/internal/helper" diff --git a/internal/gitaly/gitaly.go b/internal/gitaly/gitaly.go index ffcf7ee74e1293cf7c9f487bf849a32137d7c539..9aaf2317e33dfd798dd3c846afde39d05b9cf35e 100644 --- a/internal/gitaly/gitaly.go +++ b/internal/gitaly/gitaly.go @@ -3,10 +3,10 @@ package gitaly import ( "sync" - "github.com/grpc-ecosystem/go-grpc-middleware" + grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" pb "gitlab.com/gitlab-org/gitaly-proto/go" - "gitlab.com/gitlab-org/gitaly/auth" + gitalyauth "gitlab.com/gitlab-org/gitaly/auth" gitalyclient "gitlab.com/gitlab-org/gitaly/client" "google.golang.org/grpc" diff --git a/internal/helper/logging.go b/internal/helper/logging.go index e548c8aa6a913ce5ad3fa40ef0c0523ad0cd1ead..12fd76e48ca92ecb4b4948c7aacec5001860181b 100644 --- a/internal/helper/logging.go +++ b/internal/helper/logging.go @@ -94,8 +94,11 @@ func (l *statsCollectingResponseWriter) writeAccessLog(r *http.Request) { func (l *statsCollectingResponseWriter) accessLogFields(r *http.Request) log.Fields { duration := time.Since(l.started) + ip, _, _ := net.SplitHostPort(r.RemoteAddr) + return log.Fields{ "host": r.Host, + "remoteIp": ip, "remoteAddr": r.RemoteAddr, "method": r.Method, "uri": ScrubURLParams(r.RequestURI), diff --git a/internal/helper/logging_test.go b/internal/helper/logging_test.go index 1213f795b0b9dc98d2c02982f934089b02b1eda2..6b7e057aaa09b3f2920362d0f5938b0d5c965380 100644 --- a/internal/helper/logging_test.go +++ b/internal/helper/logging_test.go @@ -10,6 +10,40 @@ import ( "github.com/stretchr/testify/assert" ) +func Test_statsCollectingResponseWriter_remoteIp_accessLogFields(t *testing.T) { + testCases := []struct { + remoteAddr string + expected string + }{ + {remoteAddr: "", expected: ""}, + {remoteAddr: "bogus", expected: ""}, + {remoteAddr: "8.8.8.8:1234", expected: "8.8.8.8"}, + {remoteAddr: "8.8.8.8", expected: ""}, + {remoteAddr: "[2001:db8:85a3:8d3:1319:8a2e:370:7348]", expected: ""}, + {remoteAddr: "[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443", expected: "2001:db8:85a3:8d3:1319:8a2e:370:7348"}, + } + + for _, tc := range testCases { + req, err := http.NewRequest("GET", "/blah", nil) + req.RemoteAddr = tc.remoteAddr + assert.Nil(t, err) + + l := &statsCollectingResponseWriter{ + rw: nil, + status: 200, + wroteHeader: true, + written: 50, + started: time.Now(), + } + + fields := l.accessLogFields(req) + + ip := fields["remoteIp"].(string) + + assert.Equal(t, tc.expected, ip) + } +} + func Test_statsCollectingResponseWriter_accessLogFields(t *testing.T) { passwords := []string{ "should_be_filtered", // Basic case diff --git a/internal/helper/raven.go b/internal/helper/raven.go index 470332890da5b4b10667c309da5b12a970b0bf5e..657ebc6c5ab8e1953576a880356baab83194468f 100644 --- a/internal/helper/raven.go +++ b/internal/helper/raven.go @@ -4,7 +4,7 @@ import ( "net/http" "reflect" - "github.com/getsentry/raven-go" + raven "github.com/getsentry/raven-go" correlation "gitlab.com/gitlab-org/labkit/correlation/raven" ) diff --git a/internal/secret/jwt.go b/internal/secret/jwt.go index 04335e58f760e2f6e8c0c038f3d5f40fd554ce2e..3d19d1dfb47771a89a8cd34f184fcbc4def9b3d8 100644 --- a/internal/secret/jwt.go +++ b/internal/secret/jwt.go @@ -3,7 +3,7 @@ package secret import ( "fmt" - "github.com/dgrijalva/jwt-go" + jwt "github.com/dgrijalva/jwt-go" ) var ( diff --git a/raven.go b/raven.go index 28ff6ae22d7117c2717dae082515ecceb74d19a6..c92fdb4cfefc2662b215a9bf831b27454afbf133 100644 --- a/raven.go +++ b/raven.go @@ -4,7 +4,7 @@ import ( "net/http" "os" - "github.com/getsentry/raven-go" + raven "github.com/getsentry/raven-go" "gitlab.com/gitlab-org/gitlab-workhorse/internal/helper" ) diff --git a/upload_test.go b/upload_test.go index 930386add740d9430645bacf38d9d6d61adedcee..438c4565627349f398637607c9b543b0869c96d5 100644 --- a/upload_test.go +++ b/upload_test.go @@ -11,7 +11,7 @@ import ( "strings" "testing" - "github.com/dgrijalva/jwt-go" + jwt "github.com/dgrijalva/jwt-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require"