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

Commit 3905412

Browse files
author
Bruno Oliveira da Silva
committed
Replace satori/go.uuid by gofrs/uuid (#611)
Fixes #611
1 parent 906a8fe commit 3905412

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

cookies.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"strings"
2323
"time"
2424

25-
uuid "github.com/satori/go.uuid"
25+
uuid "github.com/gofrs/uuid"
2626
)
2727

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

122122
// writeStateParameterCookie sets a state parameter cookie into the response
123123
func (r *oauthProxy) writeStateParameterCookie(req *http.Request, w http.ResponseWriter) string {
124-
uuid := uuid.NewV4().String()
124+
uuid, err := uuid.NewV4()
125+
if err != nil {
126+
w.WriteHeader(http.StatusInternalServerError)
127+
}
125128
requestURI := base64.StdEncoding.EncodeToString([]byte(req.URL.RequestURI()))
126129
r.dropCookie(w, req.Host, requestURICookie, requestURI, 0)
127-
r.dropCookie(w, req.Host, requestStateCookie, uuid, 0)
128-
return uuid
130+
r.dropCookie(w, req.Host, requestStateCookie, uuid.String(), 0)
131+
return uuid.String()
129132
}
130133

131134
// clearAllCookies is just a helper function for the below

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/fsnotify/fsnotify v1.4.7
1414
github.com/garyburd/redigo v1.6.0 // indirect
1515
github.com/go-chi/chi v3.3.3+incompatible
16+
github.com/gofrs/uuid v3.3.0+incompatible
1617
github.com/jonboulle/clockwork v0.1.0 // indirect
1718
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 // indirect
1819
github.com/onsi/ginkgo v1.8.0 // indirect
@@ -21,7 +22,6 @@ require (
2122
github.com/pmezard/go-difflib v1.0.0 // indirect
2223
github.com/prometheus/client_golang v0.9.2
2324
github.com/rs/cors v1.6.0
24-
github.com/satori/go.uuid v1.2.0
2525
github.com/stretchr/testify v1.2.2
2626
github.com/unrolled/secure v0.0.0-20181221173256-0d6b5bb13069
2727
github.com/urfave/cli v0.0.0-20181029213200-b67dcf995b6a

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ github.com/garyburd/redigo v1.6.0 h1:0VruCpn7yAIIu7pWVClQC8wxCJEcG3nyzpMSHKi1PQc
2424
github.com/garyburd/redigo v1.6.0/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
2525
github.com/go-chi/chi v3.3.3+incompatible h1:KHkmBEMNkwKuK4FdQL7N2wOeB9jnIx7jR5wsuSBEFI8=
2626
github.com/go-chi/chi v3.3.3+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
27+
github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84=
28+
github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
2729
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
2830
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
2931
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
@@ -53,8 +55,6 @@ github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nL
5355
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
5456
github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI=
5557
github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
56-
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
57-
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
5858
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
5959
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
6060
github.com/unrolled/secure v0.0.0-20181221173256-0d6b5bb13069 h1:RKeYksgIwGE8zFJTvXI1WWx09QPrGyaVFMy0vpU7j/o=

middleware.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ import (
2323
"strings"
2424
"time"
2525

26+
uuid "github.com/gofrs/uuid"
27+
2628
"github.com/PuerkitoBio/purell"
2729
"github.com/coreos/go-oidc/jose"
2830
"github.com/go-chi/chi/middleware"
29-
uuid "github.com/satori/go.uuid"
3031
"github.com/unrolled/secure"
3132
"go.uber.org/zap"
3233
"go.uber.org/zap/zapcore"
@@ -72,7 +73,11 @@ func (r *oauthProxy) requestIDMiddleware(header string) func(http.Handler) http.
7273
return func(next http.Handler) http.Handler {
7374
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
7475
if v := req.Header.Get(header); v == "" {
75-
req.Header.Set(header, uuid.NewV1().String())
76+
uuid, err := uuid.NewV1()
77+
if err != nil {
78+
w.WriteHeader(http.StatusInternalServerError)
79+
}
80+
req.Header.Set(header, uuid.String())
7681
}
7782

7883
next.ServeHTTP(w, req)

middleware_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import (
2727
"time"
2828

2929
"github.com/coreos/go-oidc/jose"
30+
uuid "github.com/gofrs/uuid"
3031
"github.com/rs/cors"
31-
uuid "github.com/satori/go.uuid"
3232
"github.com/stretchr/testify/assert"
3333
"go.uber.org/zap"
3434
"gopkg.in/resty.v1"

utils_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"testing"
2828
"time"
2929

30-
uuid "github.com/satori/go.uuid"
30+
uuid "github.com/gofrs/uuid"
3131
"github.com/stretchr/testify/assert"
3232
"github.com/stretchr/testify/require"
3333
)
@@ -113,7 +113,10 @@ func TestGetRequestHostURL(t *testing.T) {
113113

114114
func BenchmarkUUID(b *testing.B) {
115115
for n := 0; n < b.N; n++ {
116-
s := uuid.NewV1()
116+
s, err := uuid.NewV1()
117+
if err != nil {
118+
b.Errorf("test case should not have failed")
119+
}
117120
_ = s.String()
118121
}
119122
}

0 commit comments

Comments
 (0)