Skip to content

test(openidm-script): reproduce custom endpoint field projection collision (#183)#190

Open
vharseko wants to merge 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:issues/183
Open

test(openidm-script): reproduce custom endpoint field projection collision (#183)#190
vharseko wants to merge 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:issues/183

Conversation

@vharseko

Copy link
Copy Markdown
Member

Description

What

Adds a regression test
openidm-script/src/test/java/org/forgerock/openidm/script/CustomEndpointFieldProjectionTest.java
that reproduces the custom-endpoint field-projection bug reported in
discussion #183.

Why

A custom (scripted) endpoint returns the full object without explicitly setting the
response fields (ScriptedRequestHandler.evaluate() calls
newResourceResponse(id, null, resultJson) without addField(...)). The generic CREST
projection Resources.filterResource(JsonValue, Collection<JsonPointer>) then collapsed
each requested pointer to its leaf() name, so manager/userName overwrote the
top-level userName.

Reproduction

Request ?_fields=userName,manager,manager/userName against a user that has a manager:

{
  "userName": "<manager's userName — WRONG>",
  "manager": { "userName": "<manager's userName — correct>" }
}

How the test works

  • A minimal RequestHandler (FullObjectEndpoint) mimics a scripted endpoint and returns
    the full nested object without addField(...).
  • It is wrapped with Resources.newInternalConnection(...), and a read is issued with
    _fields=description,userName,givenName,sn,manager,manager/userName.
  • The test asserts the correct projection:
    • top-level userName == user's own userName
    • manager/userName == manager's userName (nested under manager)

Before the fix (commons 3.1.1-SNAPSHOT) the test fails:

expected: "bjensen"
 but was: "jdoe"

Fix

The root cause is fixed in commons:
OpenIdentityPlatform/commons#183.
With the updated json-resource, the generic projection preserves the JsonPointer
structure and this test passes.

Related

…ision (OpenIdentityPlatform#183)

Add CustomEndpointFieldProjectionTest reproducing the field-projection bug
from discussion OpenIdentityPlatform#183: a custom scripted endpoint returns the full object
without setting response fields (like ScriptedRequestHandler.evaluate()),
so the generic CREST projection Resources.filterResource() is applied to the
raw result using request.getFields().

When two requested fields share the same leaf name on different nesting
levels (userName and manager/userName), the nested one overwrote the
top-level one, so top-level userName ended up holding the manager's userName.

The test goes through the real path (Resources.newInternalConnection ->
connection.read) and asserts the correct behaviour:
  - top-level userName keeps the user's own userName
  - manager/userName is nested under manager

Fixed in commons: OpenIdentityPlatform/commons#183

Refs: OpenIdentityPlatform#183 (discussion)
@vharseko vharseko requested a review from maximthomas June 10, 2026 11:29
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.

2 participants