Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/crypto/providers/jwk/jwk.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

"filippo.io/age"
"github.com/go-jose/go-jose/v4"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
)
Expand All @@ -30,7 +32,7 @@ func unmarshalJWK(jwkBytes []byte) (*jose.JSONWebKey, error) {
jwk := &jose.JSONWebKey{}
err := jwk.UnmarshalJSON(jwkBytes)
if err != nil {
return nil, fmt.Errorf("jwk: failed to unmarshal jwk: %w", err)
return nil, status.Errorf(codes.InvalidArgument, "jwk: failed to unmarshal jwk: %v", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Suggestion: No test covers the unmarshalJWK failure path. TestInvalidKeyType exercises an unsupported key type after successful unmarshal, not an unmarshal failure. Consider adding a test that passes invalid bytes to Encrypt and asserts status.Code(err) == codes.InvalidArgument.

}
return jwk, nil
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/crypto/providers/jwk/jwk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ import (
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
"github.com/go-jose/go-jose/v4"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func TestUnmarshalJWK_InvalidArgument(t *testing.T) {
_, err := unmarshalJWK([]byte("not valid jwk json"))
require.Error(t, err)
require.Equal(t, codes.InvalidArgument, status.Code(err))
}

func TestGenerateKey(t *testing.T) {
provider := &JWKEncryptionProvider{}
ctx := context.Background()
Expand Down
Loading