Skip to content

Add transport version support for IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19 #128798

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

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
5 changes: 5 additions & 0 deletions docs/changelog/128798.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 128798
summary: Add transport version support for IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19
area: IdentityProvider
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ static TransportVersion def(int id) {
public static final TransportVersion ML_INFERENCE_SAGEMAKER_CHAT_COMPLETION_8_19 = def(8_841_0_37);
public static final TransportVersion ML_INFERENCE_VERTEXAI_CHATCOMPLETION_ADDED_8_19 = def(8_841_0_38);
public static final TransportVersion INFERENCE_CUSTOM_SERVICE_ADDED_8_19 = def(8_841_0_39);
public static final TransportVersion IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19 = def(8_841_0_40);
public static final TransportVersion V_9_0_0 = def(9_000_0_09);
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_1 = def(9_000_0_10);
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_2 = def(9_000_0_11);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public SamlInitiateSingleSignOnRequest(StreamInput in) throws IOException {
spEntityId = in.readString();
assertionConsumerService = in.readString();
samlAuthenticationState = in.readOptionalWriteable(SamlAuthenticationState::new);
if (in.getTransportVersion().onOrAfter(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES)) {
if (in.getTransportVersion().isPatchFrom(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19)
|| in.getTransportVersion().onOrAfter(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES)) {
attributes = in.readOptionalWriteable(SamlInitiateSingleSignOnAttributes::new);
}
}
Expand Down Expand Up @@ -99,7 +100,8 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(spEntityId);
out.writeString(assertionConsumerService);
out.writeOptionalWriteable(samlAuthenticationState);
if (out.getTransportVersion().onOrAfter(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES)) {
if (out.getTransportVersion().isPatchFrom(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19)
|| out.getTransportVersion().onOrAfter(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES)) {
out.writeOptionalWriteable(attributes);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,36 @@ public void testSerializationCurrentVersion() throws Exception {
}
}

public void testSerializationOldButCompatibleTransportVersion() throws Exception {
final SamlInitiateSingleSignOnRequest request = new SamlInitiateSingleSignOnRequest();
request.setSpEntityId("https://kibana_url");
request.setAssertionConsumerService("https://kibana_url/acs");
if (randomBoolean()) {
request.setAttributes(
new SamlInitiateSingleSignOnAttributes(
Map.ofEntries(
Map.entry("http://idp.elastic.co/attribute/custom1", List.of("foo")),
Map.entry("http://idp.elastic.co/attribute/custom2", List.of("bar", "baz"))
)
)
);
}
assertThat("An invalid request is not guaranteed to serialize correctly", request.validate(), nullValue());
final BytesStreamOutput out = new BytesStreamOutput();
out.setTransportVersion(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19);
request.writeTo(out);

try (StreamInput in = out.bytes().streamInput()) {
in.setTransportVersion(out.getTransportVersion());
final SamlInitiateSingleSignOnRequest request1 = new SamlInitiateSingleSignOnRequest(in);
assertThat(request1.getSpEntityId(), equalTo(request.getSpEntityId()));
assertThat(request1.getAssertionConsumerService(), equalTo(request.getAssertionConsumerService()));
assertThat(request1.getAttributes(), equalTo(request.getAttributes()));
final ActionRequestValidationException validationException = request1.validate();
assertNull(validationException);
}
}

public void testSerializationOldTransportVersion() throws Exception {
final SamlInitiateSingleSignOnRequest request = new SamlInitiateSingleSignOnRequest();
request.setSpEntityId("https://kibana_url");
Expand All @@ -83,7 +113,7 @@ public void testSerializationOldTransportVersion() throws Exception {
TransportVersionUtils.randomVersionBetween(
random(),
TransportVersions.MINIMUM_COMPATIBLE,
TransportVersionUtils.getPreviousVersion(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES)
TransportVersionUtils.getPreviousVersion(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19)
)
);
request.writeTo(out);
Expand Down
Loading