Skip to content

Commit

Permalink
Updating the UUID dependency to google (#429)
Browse files Browse the repository at this point in the history
Signed-off-by: Feny Mehta <fbm3307@gmail.com>
  • Loading branch information
fbm3307 authored May 9, 2024
1 parent 52743fa commit 6f2788a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 56 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/aws/aws-sdk-go v1.44.100
github.com/codeready-toolchain/api v0.0.0-20240507023248-73662d6db2c5
github.com/codeready-toolchain/toolchain-common v0.0.0-20240429224949-78585f71122a
github.com/codeready-toolchain/toolchain-common v0.0.0-20240507174147-ed50ce546b3c
github.com/go-logr/logr v1.2.3
github.com/gofrs/uuid v4.2.0+incompatible
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/codeready-toolchain/api v0.0.0-20240507023248-73662d6db2c5 h1:BPIwkb0fqJEJ5GjMFgkoo13f8AY5UTWmPD4Hcm1GqoU=
github.com/codeready-toolchain/api v0.0.0-20240507023248-73662d6db2c5/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240429224949-78585f71122a h1:6ZqyPuT74RYEUToWCjPNieaEZ69wEx32te+8NafqNis=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240429224949-78585f71122a/go.mod h1:bluFxwf6L4eWtNlrL3niZaJjFH6UwJnYabls5ay+EQA=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240507174147-ed50ce546b3c h1:9EhiQ0dX1HrrpI7MYqvT/mmLNeMpTzWtwEEyWo3a1aA=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240507174147-ed50ce546b3c/go.mod h1:W2DY2gc5tC71iY1SM6pftJ5ML+Vo29pEzMbhLQpX8z0=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
14 changes: 7 additions & 7 deletions pkg/auth/keymanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
authsupport "github.com/codeready-toolchain/toolchain-common/pkg/test/auth"
testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config"

"github.com/gofrs/uuid"
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand All @@ -39,25 +39,25 @@ func (s *TestKeyManagerSuite) TestKeyFetching() {

// create test keys
tokengenerator := authsupport.NewTokenManager()
kid0 := uuid.Must(uuid.NewV4()).String()
kid0 := uuid.NewString()
_, err := tokengenerator.AddPrivateKey(kid0)
require.NoError(s.T(), err)
kid1 := uuid.Must(uuid.NewV4()).String()
kid1 := uuid.NewString()
_, err = tokengenerator.AddPrivateKey(kid1)
require.NoError(s.T(), err)

// create two test tokens, both valid
username0 := uuid.Must(uuid.NewV4()).String()
username0 := uuid.NewString()
identity0 := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: username0,
}
email0 := identity0.Username + "@email.tld"
jwt0, err := tokengenerator.GenerateSignedToken(*identity0, kid0, authsupport.WithEmailClaim(email0))
require.NoError(s.T(), err)
username1 := uuid.Must(uuid.NewV4()).String()
username1 := uuid.NewString()
identity1 := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: username1,
}
email1 := identity1.Username + "@email.tld"
Expand Down
66 changes: 33 additions & 33 deletions pkg/auth/tokenparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
authsupport "github.com/codeready-toolchain/toolchain-common/pkg/test/auth"
testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config"

"github.com/gofrs/uuid"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand All @@ -35,10 +35,10 @@ func (s *TestTokenParserSuite) TestTokenParser() {

// create test keys
tokengenerator := authsupport.NewTokenManager()
kid0 := uuid.Must(uuid.NewV4()).String()
kid0 := uuid.NewString()
_, err := tokengenerator.AddPrivateKey(kid0)
require.NoError(s.T(), err)
kid1 := uuid.Must(uuid.NewV4()).String()
kid1 := uuid.NewString()
_, err = tokengenerator.AddPrivateKey(kid1)
require.NoError(s.T(), err)

Expand Down Expand Up @@ -71,17 +71,17 @@ func (s *TestTokenParserSuite) TestTokenParser() {

s.Run("parse valid tokens", func() {
// create two test tokens, both valid
username0 := uuid.Must(uuid.NewV4()).String()
username0 := uuid.NewString()
identity0 := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: username0,
}
email0 := identity0.Username + "@email.tld"
jwt0, err := tokengenerator.GenerateSignedToken(*identity0, kid0, authsupport.WithEmailClaim(email0))
require.NoError(s.T(), err)
username1 := uuid.Must(uuid.NewV4()).String()
username1 := uuid.NewString()
identity1 := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: username1,
}
email1 := identity1.Username + "@email.tld"
Expand Down Expand Up @@ -110,9 +110,9 @@ func (s *TestTokenParserSuite) TestTokenParser() {

s.Run("parse invalid token", func() {
// create invalid test token (wrong set of claims, no email), signed with key1
invalidUsername := uuid.Must(uuid.NewV4()).String()
invalidUsername := uuid.NewString()
invalidIdentity := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: invalidUsername,
}
invalidJWT, err := tokengenerator.GenerateSignedToken(*invalidIdentity, kid1)
Expand All @@ -139,13 +139,13 @@ func (s *TestTokenParserSuite) TestTokenParser() {

s.Run("token signed by unknown key", func() {
// new key
kidX := uuid.Must(uuid.NewV4()).String()
kidX := uuid.NewString()
_, err := tokengenerator.AddPrivateKey(kidX)
require.NoError(s.T(), err)
// generate valid token
usernameX := uuid.Must(uuid.NewV4()).String()
usernameX := uuid.NewString()
identityX := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: usernameX,
}
emailX := identityX.Username + "@email.tld"
Expand All @@ -160,9 +160,9 @@ func (s *TestTokenParserSuite) TestTokenParser() {
})

s.Run("no KID header in token", func() {
username0 := uuid.Must(uuid.NewV4()).String()
username0 := uuid.NewString()
identity0 := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: username0,
}
email0 := identity0.Username + "@email.tld"
Expand All @@ -179,9 +179,9 @@ func (s *TestTokenParserSuite) TestTokenParser() {
})

s.Run("missing claim: preferred_username", func() {
username0 := uuid.Must(uuid.NewV4()).String()
username0 := uuid.NewString()
identity0 := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: username0,
}
email0 := identity0.Username + "@email.tld"
Expand All @@ -199,9 +199,9 @@ func (s *TestTokenParserSuite) TestTokenParser() {
})

s.Run("missing claim: email", func() {
username0 := uuid.Must(uuid.NewV4()).String()
username0 := uuid.NewString()
identity0 := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: username0,
}
// generate non-serialized token
Expand All @@ -216,9 +216,9 @@ func (s *TestTokenParserSuite) TestTokenParser() {
})

s.Run("missing claim: sub", func() {
username0 := uuid.Must(uuid.NewV4()).String()
username0 := uuid.NewString()
identity0 := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: username0,
}
email0 := identity0.Username + "@email.tld"
Expand All @@ -235,9 +235,9 @@ func (s *TestTokenParserSuite) TestTokenParser() {
})

s.Run("signature is good but token expired", func() {
username0 := uuid.Must(uuid.NewV4()).String()
username0 := uuid.NewString()
identity0 := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: username0,
}
email0 := identity0.Username + "@email.tld"
Expand All @@ -256,9 +256,9 @@ func (s *TestTokenParserSuite) TestTokenParser() {
})

s.Run("signature is good but token not valid yet", func() {
username0 := uuid.Must(uuid.NewV4()).String()
username0 := uuid.NewString()
identity0 := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: username0,
}
email0 := identity0.Username + "@email.tld"
Expand All @@ -277,9 +277,9 @@ func (s *TestTokenParserSuite) TestTokenParser() {
})

s.Run("signature is good and token expiration is within leeway", func() {
username0 := uuid.Must(uuid.NewV4()).String()
username0 := uuid.NewString()
identity0 := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: username0,
}
email0 := identity0.Username + "@email.tld"
Expand All @@ -297,9 +297,9 @@ func (s *TestTokenParserSuite) TestTokenParser() {
})

s.Run("token signed by known key but the signature is invalid", func() {
username0 := uuid.Must(uuid.NewV4()).String()
username0 := uuid.NewString()
identity0 := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: username0,
}
email0 := identity0.Username + "@email.tld"
Expand All @@ -311,7 +311,7 @@ func (s *TestTokenParserSuite) TestTokenParser() {
// replace signature with garbage
str := strings.Split(jwt0string, ".")
require.Len(s.T(), str, 3)
str[2] = uuid.Must(uuid.NewV4()).String()
str[2] = uuid.NewString()
jwt0string = strings.Join(str, ".")
// validate token
_, err = tokenParser.FromString(jwt0string)
Expand All @@ -321,9 +321,9 @@ func (s *TestTokenParserSuite) TestTokenParser() {

s.Run("parse valid token with original_sub claim", func() {
// create a test token with an original_sub claim
username0 := uuid.Must(uuid.NewV4()).String()
username0 := uuid.NewString()
identity0 := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: username0,
}
email0 := identity0.Username + "@email.tld"
Expand All @@ -343,9 +343,9 @@ func (s *TestTokenParserSuite) TestTokenParser() {
})

s.Run("parse valid token with aud claim", func() {
username0 := uuid.Must(uuid.NewV4()).String()
username0 := uuid.NewString()
identity0 := &authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
ID: uuid.New(),
Username: username0,
}
email0 := identity0.Username + "@email.tld"
Expand Down
12 changes: 6 additions & 6 deletions pkg/middleware/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
authsupport "github.com/codeready-toolchain/toolchain-common/pkg/test/auth"
testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config"

"github.com/gofrs/uuid"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand All @@ -46,24 +46,24 @@ func (s *TestAuthMiddlewareSuite) TestAuthMiddleware() {
func (s *TestAuthMiddlewareSuite) TestAuthMiddlewareService() {
// create a TokenGenerator and a key
tokengenerator := authsupport.NewTokenManager()
kid0 := uuid.Must(uuid.NewV4()).String()
kid0 := uuid.NewString()
_, err := tokengenerator.AddPrivateKey(kid0)
require.NoError(s.T(), err)

// create some test tokens
identity0 := authsupport.Identity{
ID: uuid.Must(uuid.NewV4()),
Username: uuid.Must(uuid.NewV4()).String(),
ID: uuid.New(),
Username: uuid.NewString(),
}
emailClaim0 := authsupport.WithEmailClaim(uuid.Must(uuid.NewV4()).String() + "@email.tld")
emailClaim0 := authsupport.WithEmailClaim(uuid.NewString() + "@email.tld")
// valid token
tokenValid, err := tokengenerator.GenerateSignedToken(identity0, kid0, emailClaim0)
require.NoError(s.T(), err)
// invalid token - no email
tokenInvalidNoEmail, err := tokengenerator.GenerateSignedToken(identity0, kid0)
require.NoError(s.T(), err)
// invalid token - garbage
tokenInvalidGarbage := uuid.Must(uuid.NewV4()).String()
tokenInvalidGarbage := uuid.NewString()
// invalid token - expired
expTime := time.Now().Add(-60 * time.Second)
expClaim := authsupport.WithExpClaim(expTime)
Expand Down
11 changes: 4 additions & 7 deletions pkg/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
authsupport "github.com/codeready-toolchain/toolchain-common/pkg/test/auth"
testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config"

"github.com/gofrs/uuid"
"github.com/google/uuid"
routev1 "github.com/openshift/api/route/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -171,8 +171,7 @@ func (s *TestProxySuite) checkPlainHTTPErrors(fakeApp *fake.ProxyFakeApp) {
req, err := http.NewRequest("GET", "http://localhost:8081/api/mycoolworkspace/pods", nil)
require.NoError(s.T(), err)
require.NotNil(s.T(), req)
userID, err := uuid.NewV4()
require.NoError(s.T(), err)
userID := uuid.New()
req.Header.Set("Authorization", "Bearer "+s.token(userID, authsupport.WithSubClaim("")))
resp, err := http.DefaultClient.Do(req)

Expand Down Expand Up @@ -385,8 +384,7 @@ func (s *TestProxySuite) checkWebLogin() {

func (s *TestProxySuite) checkProxyOK(fakeApp *fake.ProxyFakeApp, p *Proxy) {
s.Run("successfully proxy", func() {
userID, err := uuid.NewV4()
require.NoError(s.T(), err)
userID := uuid.New()

encodedSAToken := base64.RawURLEncoding.EncodeToString([]byte("clusterSAToken"))
encodedSSOToken := base64.RawURLEncoding.EncodeToString([]byte(s.token(userID)))
Expand Down Expand Up @@ -1158,8 +1156,7 @@ func (s *TestProxySuite) request() *http.Request {
req, err := http.NewRequest("GET", "http://localhost:8081/api/mycoolworkspace/pods", nil)
require.NoError(s.T(), err)
require.NotNil(s.T(), req)
userID, err := uuid.NewV4()
require.NoError(s.T(), err)
userID := uuid.New()
req.Header.Set("Authorization", "Bearer "+s.token(userID))

return req
Expand Down

0 comments on commit 6f2788a

Please sign in to comment.