Skip to content

Commit 7dbab69

Browse files
committed
Update authenticate to allow unknown fields (#37713)
AuthenticateResponse did not allow unknown fields. This commit fixes the test and ConstructingObjectParser such that it does now allow unknown fields. Relates #36938
1 parent 0de5396 commit 7dbab69

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/security/AuthenticateResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public final class AuthenticateResponse {
5353

5454
@SuppressWarnings("unchecked")
5555
private static final ConstructingObjectParser<AuthenticateResponse, Void> PARSER = new ConstructingObjectParser<>(
56-
"client_security_authenticate_response",
56+
"client_security_authenticate_response", true,
5757
a -> new AuthenticateResponse(new User((String) a[0], ((List<String>) a[1]), (Map<String, Object>) a[2],
5858
(String) a[3], (String) a[4]), (Boolean) a[5], (RealmInfo) a[6], (RealmInfo) a[7]));
5959
static {
60-
final ConstructingObjectParser<RealmInfo, Void> realmInfoParser = new ConstructingObjectParser<>("realm_info",
60+
final ConstructingObjectParser<RealmInfo, Void> realmInfoParser = new ConstructingObjectParser<>("realm_info", true,
6161
a -> new RealmInfo((String) a[0], (String) a[1]));
6262
realmInfoParser.declareString(constructorArg(), REALM_NAME);
6363
realmInfoParser.declareString(constructorArg(), REALM_TYPE);

client/rest-high-level/src/test/java/org/elasticsearch/client/security/AuthenticateResponseTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public void testFromXContent() throws IOException {
4242
this::createTestInstance,
4343
this::toXContent,
4444
AuthenticateResponse::fromXContent)
45-
.supportsUnknownFields(false)
45+
.supportsUnknownFields(true)
46+
//metadata is a series of kv pairs, so we dont want to add random fields here for test equality
47+
.randomFieldsExcludeFilter(f -> f.startsWith("metadata"))
4648
.test();
4749
}
4850

0 commit comments

Comments
 (0)