|
32 | 32 | import java.util.Set;
|
33 | 33 |
|
34 | 34 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent;
|
| 35 | +import static org.hamcrest.Matchers.empty; |
35 | 36 | import static org.hamcrest.Matchers.emptyIterable;
|
36 | 37 | import static org.hamcrest.Matchers.equalTo;
|
37 | 38 | import static org.hamcrest.Matchers.not;
|
@@ -90,6 +91,31 @@ public void testStreamRoundTripWithAllFields() throws Exception {
|
90 | 91 | assertThat(assertSerializationRoundTrip(doc2), equalTo(doc1));
|
91 | 92 | }
|
92 | 93 |
|
| 94 | + public void testSerializationBeforeExtensionAttributes() throws Exception { |
| 95 | + final SamlServiceProviderDocument original = createFullDocument(); |
| 96 | + final TransportVersion version = randomBoolean() |
| 97 | + ? TransportVersionUtils.randomVersionBetween( |
| 98 | + random(), |
| 99 | + TransportVersions.V_9_0_0, |
| 100 | + TransportVersionUtils.getPreviousVersion(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST) |
| 101 | + ) |
| 102 | + : TransportVersionUtils.randomVersionBetween( |
| 103 | + random(), |
| 104 | + TransportVersions.V_8_0_0, |
| 105 | + TransportVersionUtils.getPreviousVersion(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST_8_19) |
| 106 | + ); |
| 107 | + final SamlServiceProviderDocument copy = copyWriteable( |
| 108 | + original, |
| 109 | + new NamedWriteableRegistry(List.of()), |
| 110 | + SamlServiceProviderDocument::new, |
| 111 | + version |
| 112 | + ); |
| 113 | + assertThat(copy.attributeNames.extensions, empty()); |
| 114 | + |
| 115 | + copy.attributeNames.setExtensions(original.attributeNames.extensions); |
| 116 | + assertThat(copy, equalTo(original)); |
| 117 | + } |
| 118 | + |
93 | 119 | private SamlServiceProviderDocument createFullDocument() throws GeneralSecurityException, IOException {
|
94 | 120 | final List<X509Credential> credentials = readCredentials();
|
95 | 121 | final List<X509Certificate> certificates = credentials.stream().map(X509Credential::getEntityCertificate).toList();
|
@@ -121,6 +147,7 @@ private SamlServiceProviderDocument createFullDocument() throws GeneralSecurityE
|
121 | 147 | doc1.attributeNames.setEmail("urn:" + randomAlphaOfLengthBetween(4, 8) + "." + randomAlphaOfLengthBetween(4, 8));
|
122 | 148 | doc1.attributeNames.setName("urn:" + randomAlphaOfLengthBetween(4, 8) + "." + randomAlphaOfLengthBetween(4, 8));
|
123 | 149 | doc1.attributeNames.setRoles("urn:" + randomAlphaOfLengthBetween(4, 8) + "." + randomAlphaOfLengthBetween(4, 8));
|
| 150 | + doc1.attributeNames.setExtensions(List.of("urn:" + randomAlphaOfLengthBetween(4, 8) + "." + randomAlphaOfLengthBetween(4, 8))); |
124 | 151 | return doc1;
|
125 | 152 | }
|
126 | 153 |
|
@@ -162,7 +189,7 @@ private SamlServiceProviderDocument assertXContentRoundTrip(SamlServiceProviderD
|
162 | 189 | private SamlServiceProviderDocument assertSerializationRoundTrip(SamlServiceProviderDocument doc) throws IOException {
|
163 | 190 | final TransportVersion version = TransportVersionUtils.randomVersionBetween(
|
164 | 191 | random(),
|
165 |
| - TransportVersions.V_8_0_0, |
| 192 | + TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST, |
166 | 193 | TransportVersion.current()
|
167 | 194 | );
|
168 | 195 | final SamlServiceProviderDocument read = copyWriteable(
|
|
0 commit comments