Skip to content

MOSIP-45003: Fix Handlebars escaping, correct JSON array tags, and add modifySchemaGenerateHbsV2.#1957

Merged
mohanachandran-s merged 9 commits into
mosip:developfrom
SradhaMohanty5899:MOSIP-45003
Jun 10, 2026
Merged

MOSIP-45003: Fix Handlebars escaping, correct JSON array tags, and add modifySchemaGenerateHbsV2.#1957
mohanachandran-s merged 9 commits into
mosip:developfrom
SradhaMohanty5899:MOSIP-45003

Conversation

@SradhaMohanty5899

@SradhaMohanty5899 SradhaMohanty5899 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor
  • Handlebars Updates: Configured EscapingStrategy.NOOP to prevent HTML escaping and registered a custom {{json}} helper to safely serialize object contexts via Gson.
  • Schema Generation: Added modifySchemaGenerateHbsV2() which dynamically injects unescaped {{{json verifiedAttributes}}} blocks into the schema.
  • Tag Correction: Replaced incorrect "handles" string values with the singular "handle" across multiple test rig utility methods (modifySchemaGenerateHbs, updateIdentityHbs, generateHbsForUpdateDraft, and generateHbsForPrereg) to align with validation rules.

Summary by CodeRabbit

  • New Features
    • Added support for the new Identity V2 endpoint (v1/identity/v2).
  • Tests
    • Enhanced schema template generation with improved handling for verified attributes.
    • Optimized template engine configuration for more reliable JSON serialization in test validation flows.

Signed-off-by: Sradha Mohanty <mohantysradha10@gmail.com>
Signed-off-by: Sradha Mohanty <mohantysradha10@gmail.com>
Signed-off-by: Sradha Mohanty <mohantysradha10@gmail.com>
Signed-off-by: Sradha Mohanty <mohantysradha10@gmail.com>
Signed-off-by: Sradha Mohanty <mohantysradha10@gmail.com>
Signed-off-by: Sradha Mohanty <mohantysradha10@gmail.com>
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@SradhaMohanty5899, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 43 minutes and 7 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6acea0d8-d9ce-40fb-9989-a95f44a0d203

📥 Commits

Reviewing files that changed from the base of the PR and between d0bdff2 and e2e68ac.

📒 Files selected for processing (1)
  • apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java

Walkthrough

AdminTestUtil reconfigures Handlebars with no-op escaping and a custom JSON helper, adds V2 HBS post-processing methods to inject verifiedAttributes, normalizes "handle" token usage across identity/update/draft/pre-registration HBS generation, and adds ADD_IDENTITY_V2_ENDPOINT.

Changes

Handlebars Infrastructure and Schema HBS Generation

Layer / File(s) Summary
Handlebars Configuration with Custom JSON Helper
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java
Adds imports for EscapingStrategy, Helper, and Options, then configures the shared handlebars instance with EscapingStrategy.NOOP and registers a custom "json" helper that serializes context objects using the shared gson instance.
Schema HBS Post-Processing Enhancement
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java
Introduces modifySchemaGenerateHbsV2(boolean regenerateHbs) method that wraps the existing modifySchemaGenerateHbs(...) output and injects a verifiedAttributes template fragment by replacing the $VERIFIED_ATTRIBUTES$ placeholder with generated HBS content.
Identity Update HBS Post-Processing
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java
Introduces updateIdentityHbsV2(boolean regenerateHbs) that wraps updateIdentityHbs(...) output and injects/replaces the same verifiedAttributes template fragment.
Handle Token Normalization Across Schema Flows
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java
Updates ID schema, identity update, draft update, and pre-registration HBS generation to populate handleArray and emit tags arrays using singular "handle" (for email, phone, and functional ID entries) instead of "handles".
New endpoint constant
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/GlobalConstants.java
Adds public static final String ADD_IDENTITY_V2_ENDPOINT = "/v1/identity/v2"; next to other endpoint/header constants.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • mosip/mosip-functional-tests#1948: Modifies the same AdminTestUtil schema-to-Handlebars identity template generation logic, including how identity handle fields are detected and populated in HBS flows.
  • mosip/mosip-functional-tests#1952: Overlaps on AdminTestUtil Handlebars schema/identity template generation changes; addresses similar template placeholders and handle-related logic.

Suggested reviewers

  • jayesh12234
  • lsivanand

Poem

🐰 A rabbit scripts templates under moonlit code,

It trims "handles" to "handle" down the road,
No escaping to choke the JSON it spins,
Verified attributes tucked safe within,
Hopping through HBS where the new endpoint grins.

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the three main changes: Handlebars escaping fix, JSON array tag correction, and the new modifySchemaGenerateHbsV2 method.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java`:
- Around line 3822-3831: The shared public Handlebars instance disables escaping
(public static Handlebars handlebars = new
Handlebars().with(EscapingStrategy.NOOP)), which breaks escaping for all
templates; restore safe defaults by removing EscapingStrategy.NOOP from the
shared handlebars and instead scope raw output to only where needed: either (A)
change the "json" helper registration to return a Handlebars.SafeString wrapping
gson.toJson(context) so the helper emits unescaped JSON while the rest of the
template remains escaped, or (B) create a separate local Handlebars instance
(e.g., rawHandlebars.with(EscapingStrategy.NOOP)) used only inside
getJsonFromTemplate() when rendering the full JSON template; keep the public
handlebars escaped for general use and reference the existing symbols:
handlebars, getJsonFromTemplate(), the "json" Helper, EscapingStrategy.NOOP, and
gson.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bcf5c000-1bb8-42f5-8326-f1cfc667d381

📥 Commits

Reviewing files that changed from the base of the PR and between 429ceb7 and c1e0e51.

📒 Files selected for processing (1)
  • apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java

Signed-off-by: Sradha Mohanty <mohantysradha10@gmail.com>

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java`:
- Around line 5854-5858: The code assumes updateIdentityHbs(regenerateHbs)
returns a JSON with a "request" object which can be missing; in AdminTestUtil
where you build requestJson from hbs and call
requestJson.getJSONObject("request").put("verifiedAttributes",
"$VERIFIED_ATTRIBUTES$"), add a structural guard: parse hbs into JSONObject,
check containsKey("request") and that get("request") is a JSONObject (or not
null); if the guard fails, throw a clear RuntimeException/IllegalStateException
(or propagate the original error) with a descriptive message including hbs and
regenerateHbs context so callers fail fast instead of hitting JSONException
during mutation. Ensure the check is performed immediately after creating
requestJson and before any put() call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0020840a-755b-4974-a036-f3f0ef9d4280

📥 Commits

Reviewing files that changed from the base of the PR and between c1e0e51 and d0bdff2.

📒 Files selected for processing (2)
  • apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java
  • apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/GlobalConstants.java
✅ Files skipped from review due to trivial changes (1)
  • apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/GlobalConstants.java

Signed-off-by: Sradha Mohanty <mohantysradha10@gmail.com>
@mohanachandran-s mohanachandran-s merged commit 76f4fbb into mosip:develop Jun 10, 2026
9 checks passed
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