ES-2836 - Added JWE public key encryption and patchWithPathParamsBodyHeaderWithBearerToken method#1890
ES-2836 - Added JWE public key encryption and patchWithPathParamsBodyHeaderWithBearerToken method#1890prathmeshj12 wants to merge 2 commits intomosip:developfrom
Conversation
Signed-off-by: Prathmesh Jadhav <[email protected]>
WalkthroughAdded three utility methods: one generating an RSA JWK for encryption, one caching an ENC JWK by name, and one performing PATCH requests using a Bearer token in the request header. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant RestClient as RestClient (util)
participant Server as Server/API
Client->>RestClient: call patchWithPathParamsBodyHeaderWithBearerToken(path, body, token)
RestClient->>Server: PATCH /resource/{id} (Authorization: Bearer <token>, body)
Server-->>RestClient: 2xx / error response
RestClient-->>Client: return response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/RestClient.java`:
- Line 1369: The log line in RestClient.java incorrectly states "Sending a PUT
request" for the PATCH method; update the RESTCLIENT_LOGGER message in the patch
method(s) (e.g., the method patchWithPathParamsBodyAndCookie and the other
patchWithPathParams... method) to say "Sending a PATCH request to " + url so the
debug output matches the HTTP method being executed.
🧹 Nitpick comments (2)
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java (1)
4389-4407: Log full exception details (and consider making failures explicit).
Onlye.getMessage()is logged and the method returnsnull, which obscures root causes and risks downstream NPEs. At least log the stack trace; ideally surface the failure more explicitly (exception or Optional).🔧 Suggested logging improvement
- } catch (Exception e) { - logger.error(e.getMessage()); - return null; - } + } catch (Exception e) { + logger.error("Failed to generate JWK encryption public key", e); + return null; + }apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/JWKKeyUtil.java (1)
33-38: Null return fromgenerateJWKEncPublicKey()gets silently cached.
AdminTestUtil.generateJWKEncPublicKey()returnsnullon failure. Cachingnullmeans a latergetJWKKey(keyName)silently returnsnullwith no indication that key generation failed. The existinggenerateAndCacheJWKKeyhas the same gap, but worth addressing here to avoid debugging headaches.Proposed null guard
public static String generateAndCacheEncJWKKey(String keyName) { String jwkKey = AdminTestUtil.generateJWKEncPublicKey(); + if (jwkKey == null) { + logger.error("Failed to generate ENC JWK key for: " + keyName); + return null; + } jwkKeyCache.put(keyName, jwkKey); logger.info("ENC keyName: " + keyName + " jwkKey: " + jwkKey); return jwkKey; }
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/RestClient.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Prathmesh Jadhav <[email protected]>
| } | ||
|
|
||
| public static String generateJWKEncPublicKey() { | ||
| try { |
There was a problem hiding this comment.
This looks code duplication, so look for the possibilities for wrapping single method for public key creation with parameters and call those methods as per the public key type
| logger.info("keyName: " + keyName + " jwkKey: " + jwkKey ); | ||
| return jwkKey; | ||
| } | ||
| public static String generateAndCacheEncJWKKey(String keyName) { |
Summary by CodeRabbit