Skip to content

Commit

Permalink
fix: import JWK unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr committed Jan 9, 2024
1 parent ea429d7 commit b1f0310
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cmd/cmd_import_jwk.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,18 @@ the imported keys will be added to that set. Otherwise, a new set will be create

key = cli.ToSDKFriendlyJSONWebKey(key, "", "")

var buf bytes.Buffer
var jsonWebKey hydra.JsonWebKey
type jwk hydra.JsonWebKey // opt out of OpenAPI-generated UnmarshalJSON
var (
buf bytes.Buffer
jsonWebKey jwk
)
if err := json.NewEncoder(&buf).Encode(key); err != nil {
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Could not encode key from `%s` to JSON: %s", src, err)
return cmdx.FailSilently(cmd)
}

if err := json.NewDecoder(&buf).Decode(&jsonWebKey); err != nil {
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Could not decode key from `%s` to JSON: %s", src, err)
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Could not decode key from `%s` from JSON: %s", src, err)

Check warning on line 87 in cmd/cmd_import_jwk.go

View check run for this annotation

Codecov / codecov/patch

cmd/cmd_import_jwk.go#L87

Added line #L87 was not covered by tests
return cmdx.FailSilently(cmd)
}

Expand All @@ -107,7 +110,7 @@ the imported keys will be added to that set. Otherwise, a new set will be create
return cmdx.FailSilently(cmd)
}

keys[src] = append(keys[src], jsonWebKey)
keys[src] = append(keys[src], hydra.JsonWebKey(jsonWebKey))
}

imported := make([]hydra.JsonWebKey, 0, len(keys))
Expand Down

0 comments on commit b1f0310

Please sign in to comment.