2727import org .elasticsearch .xpack .core .common .validation .SourceDestValidator .SourceDestValidation ;
2828import org .elasticsearch .xpack .core .deprecation .DeprecationIssue ;
2929import org .elasticsearch .xpack .core .deprecation .DeprecationIssue .Level ;
30+ import org .elasticsearch .xpack .core .security .authc .AuthenticationTestHelper ;
31+ import org .elasticsearch .xpack .core .security .user .User ;
3032import org .elasticsearch .xpack .core .transform .AbstractSerializingTransformTestCase ;
3133import org .elasticsearch .xpack .core .transform .TransformConfigVersion ;
3234import org .elasticsearch .xpack .core .transform .TransformDeprecations ;
4446import java .util .Map ;
4547
4648import static org .elasticsearch .test .TestMatchers .matchesPattern ;
49+ import static org .elasticsearch .xpack .core .security .authc .AuthenticationField .AUTHENTICATION_KEY ;
4750import static org .elasticsearch .xpack .core .transform .transforms .DestConfigTests .randomDestConfig ;
4851import static org .elasticsearch .xpack .core .transform .transforms .SourceConfigTests .randomInvalidSourceConfig ;
4952import static org .elasticsearch .xpack .core .transform .transforms .SourceConfigTests .randomSourceConfig ;
@@ -58,6 +61,8 @@ public class TransformConfigTests extends AbstractSerializingTransformTestCase<T
5861
5962 private String transformId ;
6063 private boolean runWithHeaders ;
64+ private static final String DATA_FRAME_TRANSFORMS_ADMIN_ROLE = "data_frame_transforms_admin" ;
65+ private static final String DATA_FRAME_TRANSFORMS_USER_ROLE = "data_frame_transforms_user" ;
6166
6267 public static TransformConfig randomTransformConfigWithoutHeaders () {
6368 return randomTransformConfigWithoutHeaders (randomAlphaOfLengthBetween (1 , 10 ));
@@ -165,6 +170,25 @@ public static TransformConfig randomTransformConfigWithSettings(SettingsConfig s
165170 );
166171 }
167172
173+ public static TransformConfig randomTransformConfigWithHeaders (Map <String , String > headers ) {
174+ return new TransformConfig (
175+ randomAlphaOfLengthBetween (1 , 10 ),
176+ randomSourceConfig (),
177+ randomDestConfig (),
178+ randomBoolean () ? null : TimeValue .timeValueMillis (randomIntBetween (1_000 , 3_600_000 )),
179+ randomBoolean () ? null : randomSyncConfig (),
180+ headers ,
181+ randomBoolean () ? null : PivotConfigTests .randomPivotConfig (),
182+ randomBoolean () ? null : LatestConfigTests .randomLatestConfig (),
183+ randomBoolean () ? null : randomAlphaOfLengthBetween (1 , 1000 ),
184+ randomBoolean () ? null : SettingsConfigTests .randomSettingsConfig (),
185+ randomBoolean () ? null : randomMetadata (),
186+ randomBoolean () ? null : randomRetentionPolicyConfig (),
187+ randomBoolean () ? null : Instant .now (),
188+ TransformConfigVersion .CURRENT .toString ()
189+ );
190+ }
191+
168192 public static TransformConfig randomTransformConfig (
169193 String id ,
170194 TransformConfigVersion version ,
@@ -915,10 +939,13 @@ public void testGroupByStayInOrder() throws IOException {
915939 }
916940 }
917941
918- public void testCheckForDeprecations () {
942+ public void testCheckForDeprecations_NoDeprecationWarnings () throws IOException {
919943 String id = randomAlphaOfLengthBetween (1 , 10 );
920944 assertThat (randomTransformConfig (id , TransformConfigVersion .CURRENT ).checkForDeprecations (xContentRegistry ()), is (empty ()));
945+ }
921946
947+ public void testCheckForDeprecations_WithDeprecatedFields_VersionCurrent () throws IOException {
948+ String id = randomAlphaOfLengthBetween (1 , 10 );
922949 TransformConfig deprecatedConfig = randomTransformConfigWithDeprecatedFields (id , TransformConfigVersion .CURRENT );
923950
924951 // check _and_ clear warnings
@@ -940,8 +967,11 @@ public void testCheckForDeprecations() {
940967 )
941968 )
942969 );
970+ }
943971
944- deprecatedConfig = randomTransformConfigWithDeprecatedFields (id , TransformConfigVersion .V_7_10_0 );
972+ public void testCheckForDeprecations_WithDeprecatedFields_Version_7_10 () throws IOException {
973+ String id = randomAlphaOfLengthBetween (1 , 10 );
974+ TransformConfig deprecatedConfig = randomTransformConfigWithDeprecatedFields (id , TransformConfigVersion .V_7_10_0 );
945975
946976 // check _and_ clear warnings
947977 assertWarnings (TransformDeprecations .ACTION_MAX_PAGE_SEARCH_SIZE_IS_DEPRECATED );
@@ -962,8 +992,11 @@ public void testCheckForDeprecations() {
962992 )
963993 )
964994 );
995+ }
965996
966- deprecatedConfig = randomTransformConfigWithDeprecatedFields (id , TransformConfigVersion .V_7_4_0 );
997+ public void testCheckForDeprecations_WithDeprecatedFields_Version_7_4 () throws IOException {
998+ String id = randomAlphaOfLengthBetween (1 , 10 );
999+ TransformConfig deprecatedConfig = randomTransformConfigWithDeprecatedFields (id , TransformConfigVersion .V_7_4_0 );
9671000
9681001 // check _and_ clear warnings
9691002 assertWarnings (TransformDeprecations .ACTION_MAX_PAGE_SEARCH_SIZE_IS_DEPRECATED );
@@ -994,6 +1027,44 @@ public void testCheckForDeprecations() {
9941027 );
9951028 }
9961029
1030+ public void testCheckForDeprecations_WithDeprecatedTransformUserAdmin () throws IOException {
1031+ testCheckForDeprecations_WithDeprecatedRoles (List .of (DATA_FRAME_TRANSFORMS_ADMIN_ROLE ));
1032+ }
1033+
1034+ public void testCheckForDeprecations_WithDeprecatedTransformUserRole () throws IOException {
1035+ testCheckForDeprecations_WithDeprecatedRoles (List .of (DATA_FRAME_TRANSFORMS_USER_ROLE ));
1036+ }
1037+
1038+ public void testCheckForDeprecations_WithDeprecatedTransformRoles () throws IOException {
1039+ testCheckForDeprecations_WithDeprecatedRoles (List .of (DATA_FRAME_TRANSFORMS_ADMIN_ROLE , DATA_FRAME_TRANSFORMS_USER_ROLE ));
1040+ }
1041+
1042+ private void testCheckForDeprecations_WithDeprecatedRoles (List <String > roles ) throws IOException {
1043+ var authentication = AuthenticationTestHelper .builder ()
1044+ .realm ()
1045+ .user (new User (randomAlphaOfLength (10 ), roles .toArray (String []::new )))
1046+ .build ();
1047+ Map <String , String > headers = Map .of (AUTHENTICATION_KEY , authentication .encode ());
1048+ TransformConfig deprecatedConfig = randomTransformConfigWithHeaders (headers );
1049+
1050+ // important: checkForDeprecations does _not_ create new deprecation warnings
1051+ assertThat (
1052+ deprecatedConfig .checkForDeprecations (xContentRegistry ()),
1053+ equalTo (
1054+ List .of (
1055+ new DeprecationIssue (
1056+ Level .CRITICAL ,
1057+ "Transform [" + deprecatedConfig .getId () + "] uses deprecated transform roles " + roles ,
1058+ TransformDeprecations .DATA_FRAME_TRANSFORMS_ROLES_BREAKING_CHANGES_URL ,
1059+ TransformDeprecations .DATA_FRAME_TRANSFORMS_ROLES_IS_DEPRECATED ,
1060+ false ,
1061+ null
1062+ )
1063+ )
1064+ )
1065+ );
1066+ }
1067+
9971068 public void testSerializingMetadataPreservesOrder () throws IOException {
9981069 String json = Strings .format ("""
9991070 {
0 commit comments