Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Commit

Permalink
Replace satori/go.uuid by gofrs/uuid (#611)
Browse files Browse the repository at this point in the history
Fixes #611
  • Loading branch information
Bruno Oliveira da Silva committed May 21, 2020
1 parent 906a8fe commit 3905412
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
11 changes: 7 additions & 4 deletions cookies.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strings"
"time"

uuid "github.com/satori/go.uuid"
uuid "github.com/gofrs/uuid"
)

// SameSite cookie config options
Expand Down Expand Up @@ -121,11 +121,14 @@ func (r *oauthProxy) dropRefreshTokenCookie(req *http.Request, w http.ResponseWr

// writeStateParameterCookie sets a state parameter cookie into the response
func (r *oauthProxy) writeStateParameterCookie(req *http.Request, w http.ResponseWriter) string {
uuid := uuid.NewV4().String()
uuid, err := uuid.NewV4()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
requestURI := base64.StdEncoding.EncodeToString([]byte(req.URL.RequestURI()))
r.dropCookie(w, req.Host, requestURICookie, requestURI, 0)
r.dropCookie(w, req.Host, requestStateCookie, uuid, 0)
return uuid
r.dropCookie(w, req.Host, requestStateCookie, uuid.String(), 0)
return uuid.String()
}

// clearAllCookies is just a helper function for the below
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/fsnotify/fsnotify v1.4.7
github.com/garyburd/redigo v1.6.0 // indirect
github.com/go-chi/chi v3.3.3+incompatible
github.com/gofrs/uuid v3.3.0+incompatible
github.com/jonboulle/clockwork v0.1.0 // indirect
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 // indirect
github.com/onsi/ginkgo v1.8.0 // indirect
Expand All @@ -21,7 +22,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v0.9.2
github.com/rs/cors v1.6.0
github.com/satori/go.uuid v1.2.0
github.com/stretchr/testify v1.2.2
github.com/unrolled/secure v0.0.0-20181221173256-0d6b5bb13069
github.com/urfave/cli v0.0.0-20181029213200-b67dcf995b6a
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ github.com/garyburd/redigo v1.6.0 h1:0VruCpn7yAIIu7pWVClQC8wxCJEcG3nyzpMSHKi1PQc
github.com/garyburd/redigo v1.6.0/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
github.com/go-chi/chi v3.3.3+incompatible h1:KHkmBEMNkwKuK4FdQL7N2wOeB9jnIx7jR5wsuSBEFI8=
github.com/go-chi/chi v3.3.3+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84=
github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
Expand Down Expand Up @@ -53,8 +55,6 @@ github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nL
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI=
github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/unrolled/secure v0.0.0-20181221173256-0d6b5bb13069 h1:RKeYksgIwGE8zFJTvXI1WWx09QPrGyaVFMy0vpU7j/o=
Expand Down
9 changes: 7 additions & 2 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import (
"strings"
"time"

uuid "github.com/gofrs/uuid"

"github.com/PuerkitoBio/purell"
"github.com/coreos/go-oidc/jose"
"github.com/go-chi/chi/middleware"
uuid "github.com/satori/go.uuid"
"github.com/unrolled/secure"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -72,7 +73,11 @@ func (r *oauthProxy) requestIDMiddleware(header string) func(http.Handler) http.
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if v := req.Header.Get(header); v == "" {
req.Header.Set(header, uuid.NewV1().String())
uuid, err := uuid.NewV1()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
req.Header.Set(header, uuid.String())
}

next.ServeHTTP(w, req)
Expand Down
2 changes: 1 addition & 1 deletion middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"time"

"github.com/coreos/go-oidc/jose"
uuid "github.com/gofrs/uuid"
"github.com/rs/cors"
uuid "github.com/satori/go.uuid"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"gopkg.in/resty.v1"
Expand Down
7 changes: 5 additions & 2 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"testing"
"time"

uuid "github.com/satori/go.uuid"
uuid "github.com/gofrs/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -113,7 +113,10 @@ func TestGetRequestHostURL(t *testing.T) {

func BenchmarkUUID(b *testing.B) {
for n := 0; n < b.N; n++ {
s := uuid.NewV1()
s, err := uuid.NewV1()
if err != nil {
b.Errorf("test case should not have failed")
}
_ = s.String()
}
}
Expand Down

0 comments on commit 3905412

Please sign in to comment.