Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RealmIdentifier XContent parser #88410

Merged
merged 1 commit into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public int compareTo(RealmIdentifier other) {
);

static {
REALM_IDENTIFIER_PARSER.declareString(constructorArg(), new ParseField("name"));
REALM_IDENTIFIER_PARSER.declareString(constructorArg(), new ParseField("type"));
REALM_IDENTIFIER_PARSER.declareString(constructorArg(), new ParseField("name"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.env.Environment;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser;
import org.junit.Before;
import org.mockito.Mockito;

import java.io.IOException;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

public class RealmConfigTests extends ESTestCase {
Expand Down Expand Up @@ -57,4 +64,13 @@ public void testWillNotFailWhenOrderIsMissingAndDisabled() {
final RealmConfig realmConfig = new RealmConfig(realmIdentifier, settings, environment, threadContext);
assertThat(realmConfig.enabled(), is(false));
}

public void testXContentSerialization() throws IOException {
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
realmIdentifier.toXContent(builder, ToXContent.EMPTY_PARAMS);
try (XContentParser parser = createParser(builder)) {
assertThat(RealmConfig.REALM_IDENTIFIER_PARSER.parse(parser, null), equalTo(realmIdentifier));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.core.security.authc;

import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.test.AbstractSerializingTestCase;
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;

public class RealmDomainTests extends AbstractSerializingTestCase<RealmDomain> {

@Override
protected RealmDomain doParseInstance(XContentParser parser) throws IOException {
return RealmDomain.REALM_DOMAIN_PARSER.parse(parser, null);
}

@Override
protected Writeable.Reader<RealmDomain> instanceReader() {
return RealmDomain::readFrom;
}

@Override
protected RealmDomain createTestInstance() {
return AuthenticationTestHelper.randomDomain(randomBoolean());
}

}