Skip to content

ES-2836 - Added JWE public key encryption and patchWithPathParamsBodyHeaderWithBearerToken method#1890

Open
prathmeshj12 wants to merge 2 commits intomosip:developfrom
prathmeshj12:develop
Open

ES-2836 - Added JWE public key encryption and patchWithPathParamsBodyHeaderWithBearerToken method#1890
prathmeshj12 wants to merge 2 commits intomosip:developfrom
prathmeshj12:develop

Conversation

@prathmeshj12
Copy link
Contributor

@prathmeshj12 prathmeshj12 commented Feb 12, 2026

  1. Added "generateJWKEncPublicKey" for creating the public key with "Use.ENCRYPTION" and "Algorithm.RSA_OAEP_256"
  2. Added the "patchWithPathParamsBodyHeaderWithBearerToken" for eSignet "PatchWithPathParamsAndBody"

Summary by CodeRabbit

  • New Features
    • Added support for generating and caching encryption (ENC) keys alongside existing signing key functionality.
    • Extended API request capabilities to support Bearer token authentication for PATCH operations.
    • Enhanced cryptographic utilities for improved key management and workflow traceability.

@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2026

Walkthrough

Added 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

Cohort / File(s) Summary
JWK Encryption Key Generation
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java
Added public static String generateJWKEncPublicKey() to generate an RSA key pair and return a JWK JSON with use=ENCRYPTION and alg=RSA-OAEP-256. Added com.nimbusds.jose.JWEAlgorithm import.
ENC JWK Caching
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/JWKKeyUtil.java
Added public static String generateAndCacheEncJWKKey(String keyName) which calls the new AdminTestUtil method, caches the returned ENC JWK under the provided name, and logs the ENC-prefixed action.
PATCH with Bearer Token
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/RestClient.java
Added patchWithPathParamsBodyHeaderWithBearerToken(...) to send PATCH requests with path params and body using a Bearer token in the header (Authorization: Bearer <token> behavior mirrored for debug/non-debug flows).

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I hopped a key from code so bright,
Wrapped in RSA for secure flight,
I cached an ENC with careful cheer,
And sent a PATCH with Bearer near,
Tiny hops, but progress clear.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: adding JWE public key encryption support (generateJWKEncPublicKey method and related infrastructure) and a new patchWithPathParamsBodyHeaderWithBearerToken method.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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).
Only e.getMessage() is logged and the method returns null, 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 from generateJWKEncPublicKey() gets silently cached.

AdminTestUtil.generateJWKEncPublicKey() returns null on failure. Caching null means a later getJWKKey(keyName) silently returns null with no indication that key generation failed. The existing generateAndCacheJWKKey has 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;
     }

@prathmeshj12 prathmeshj12 changed the title ES-2836 - JWE automation fails when client encryption public key ES-2836 - Added JWE public key encryption and patchWithPathParamsBodyHeaderWithBearerToken method Feb 12, 2026
}

public static String generateJWKEncPublicKey() {
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this also same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants