Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed May 22, 2024
1 parent 75770cd commit e974df9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion database/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ func testJWKs(t *testing.T, db Interface, resources *Resources) {
t.Errorf("unable to get jwk %s: %v", jkPub.KeyID(), err)
}

if !cmp.Equal(jkPub, got) {
if !cmp.Equal(jkPub, got, testutils.JwkOpts) {
t.Errorf("GetJWK() is %v, want %v", got, jkPub)
}
}
Expand Down
3 changes: 2 additions & 1 deletion database/jwk/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ package jwk
import (
"context"

"github.com/lestrrat-go/jwx/jwk"

"github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
"github.com/lestrrat-go/jwx/jwk"
)

// GetActiveJWK gets a JWK by UUID (kid) from the database if active.
Expand Down
2 changes: 1 addition & 1 deletion database/jwk/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestJWK_Engine_GetJWK(t *testing.T) {
t.Errorf("GetActiveJWK for %s returned err: %v", test.name, err)
}

if diff := cmp.Diff(test.want, got, jwkOpts); diff != "" {
if diff := cmp.Diff(test.want, got, testutils.JwkOpts); diff != "" {
t.Errorf("GetActiveJWK mismatch (-want +got):\n%s", diff)
}
})
Expand Down
25 changes: 0 additions & 25 deletions database/jwk/jwk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"testing"

"github.com/DATA-DOG/go-sqlmock"
"github.com/google/go-cmp/cmp"
"github.com/lestrrat-go/jwx/jwk"
"github.com/sirupsen/logrus"
"gorm.io/driver/postgres"
"gorm.io/driver/sqlite"
Expand Down Expand Up @@ -163,26 +161,3 @@ func testSqlite(t *testing.T) *engine {

return _engine
}

var jwkOpts = cmp.Options{
cmp.FilterValues(func(x, y interface{}) bool {
_, xOk := x.(jwk.RSAPublicKey)
_, yOk := y.(jwk.RSAPublicKey)
return xOk && yOk
}, cmp.Comparer(func(x, y interface{}) bool {
xJWK := x.(jwk.RSAPublicKey)
yJWK := y.(jwk.RSAPublicKey)

var rawXKey, rawYKey interface{}

if err := xJWK.Raw(&rawXKey); err != nil {
return false
}

if err := yJWK.Raw(&rawYKey); err != nil {
return false
}

return reflect.DeepEqual(rawXKey, rawYKey) && xJWK.KeyID() == yJWK.KeyID()
})),
}
3 changes: 2 additions & 1 deletion database/jwk/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ package jwk
import (
"context"

"github.com/lestrrat-go/jwx/jwk"

"github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
"github.com/lestrrat-go/jwx/jwk"
)

// ListJWKs gets a list of all configured JWKs from the database.
Expand Down
5 changes: 3 additions & 2 deletions database/testutils/api_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"crypto/rand"
"crypto/rsa"

"github.com/google/uuid"
"github.com/lestrrat-go/jwx/jwk"

api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/api/types/actions"
"github.com/go-vela/types/library"
"github.com/go-vela/types/raw"
"github.com/google/uuid"
"github.com/lestrrat-go/jwx/jwk"
)

// API TEST RESOURCES
Expand Down
27 changes: 27 additions & 0 deletions database/testutils/mock_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ package testutils

import (
"database/sql/driver"
"reflect"
"time"

"github.com/google/go-cmp/cmp"
"github.com/lestrrat-go/jwx/jwk"
)

// This will be used with the github.com/DATA-DOG/go-sqlmock library to compare values
Expand Down Expand Up @@ -33,3 +37,26 @@ func (t NowTimestamp) Match(v driver.Value) bool {

return now-ts < 10
}

var JwkOpts = cmp.Options{
cmp.FilterValues(func(x, y interface{}) bool {
_, xOk := x.(jwk.RSAPublicKey)
_, yOk := y.(jwk.RSAPublicKey)
return xOk && yOk
}, cmp.Comparer(func(x, y interface{}) bool {
xJWK := x.(jwk.RSAPublicKey)
yJWK := y.(jwk.RSAPublicKey)

var rawXKey, rawYKey interface{}

if err := xJWK.Raw(&rawXKey); err != nil {
return false
}

if err := yJWK.Raw(&rawYKey); err != nil {
return false
}

return reflect.DeepEqual(rawXKey, rawYKey) && xJWK.KeyID() == yJWK.KeyID()
})),
}

0 comments on commit e974df9

Please sign in to comment.