|
6 | 6 | */ |
7 | 7 | package org.elasticsearch.xpack.security.transport; |
8 | 8 |
|
| 9 | +import com.carrotsearch.randomizedtesting.annotations.Repeat; |
| 10 | + |
9 | 11 | import org.elasticsearch.ElasticsearchSecurityException; |
10 | 12 | import org.elasticsearch.TransportVersion; |
11 | 13 | import org.elasticsearch.TransportVersions; |
|
112 | 114 | import static org.mockito.Mockito.verify; |
113 | 115 | import static org.mockito.Mockito.when; |
114 | 116 |
|
| 117 | +@Repeat(iterations = 1000) |
115 | 118 | public class SecurityServerTransportInterceptorTests extends ESTestCase { |
116 | 119 |
|
117 | 120 | private Settings settings; |
@@ -637,17 +640,22 @@ public void testSendWithCrossClusterAccessHeadersWithUnsupportedLicense() throws |
637 | 640 | final SecurityServerTransportInterceptor interceptor = new SecurityServerTransportInterceptor( |
638 | 641 | settings, |
639 | 642 | threadPool, |
640 | | - mock(AuthenticationService.class), |
641 | | - mock(AuthorizationService.class), |
642 | 643 | mockSslService(), |
643 | 644 | securityContext, |
644 | 645 | new DestructiveOperations( |
645 | 646 | Settings.EMPTY, |
646 | 647 | new ClusterSettings(Settings.EMPTY, Collections.singleton(DestructiveOperations.REQUIRES_NAME_SETTING)) |
647 | 648 | ), |
648 | | - mock(CrossClusterAccessAuthenticationService.class), |
649 | | - unsupportedLicenseState, |
650 | | - mockRemoteClusterCredentialsResolver(remoteClusterAlias) |
| 649 | + new CrossClusterAccessTransportInterceptor( |
| 650 | + mock(CrossClusterAccessAuthenticationService.class), |
| 651 | + mock(AuthenticationService.class), |
| 652 | + mock(AuthorizationService.class), |
| 653 | + unsupportedLicenseState, |
| 654 | + securityContext, |
| 655 | + threadPool, |
| 656 | + settings, |
| 657 | + mockRemoteClusterCredentialsResolver(remoteClusterAlias) |
| 658 | + ) |
651 | 659 | ); |
652 | 660 |
|
653 | 661 | final AsyncSender sender = interceptor.interceptSender(mock(AsyncSender.class, ignored -> { |
@@ -774,17 +782,24 @@ private void doTestSendWithCrossClusterAccessHeaders( |
774 | 782 | final SecurityServerTransportInterceptor interceptor = new SecurityServerTransportInterceptor( |
775 | 783 | settings, |
776 | 784 | threadPool, |
777 | | - mock(AuthenticationService.class), |
778 | | - authzService, |
779 | 785 | mockSslService(), |
780 | 786 | securityContext, |
781 | 787 | new DestructiveOperations( |
782 | 788 | Settings.EMPTY, |
783 | 789 | new ClusterSettings(Settings.EMPTY, Collections.singleton(DestructiveOperations.REQUIRES_NAME_SETTING)) |
784 | 790 | ), |
785 | | - mock(CrossClusterAccessAuthenticationService.class), |
786 | | - mockLicenseState, |
787 | | - ignored -> Optional.of(new RemoteClusterAliasWithCredentials(remoteClusterAlias, new SecureString(encodedApiKey.toCharArray()))) |
| 791 | + new CrossClusterAccessTransportInterceptor( |
| 792 | + mock(CrossClusterAccessAuthenticationService.class), |
| 793 | + mock(AuthenticationService.class), |
| 794 | + authzService, |
| 795 | + mockLicenseState, |
| 796 | + securityContext, |
| 797 | + threadPool, |
| 798 | + settings, |
| 799 | + ignored -> Optional.of( |
| 800 | + new RemoteClusterAliasWithCredentials(remoteClusterAlias, new SecureString(encodedApiKey.toCharArray())) |
| 801 | + ) |
| 802 | + ) |
788 | 803 | ); |
789 | 804 |
|
790 | 805 | final AtomicBoolean calledWrappedSender = new AtomicBoolean(false); |
@@ -912,21 +927,28 @@ public void testSendWithUserIfCrossClusterAccessHeadersConditionNotMet() throws |
912 | 927 | final SecurityServerTransportInterceptor interceptor = new SecurityServerTransportInterceptor( |
913 | 928 | settings, |
914 | 929 | threadPool, |
915 | | - mock(AuthenticationService.class), |
916 | | - authzService, |
917 | 930 | mockSslService(), |
918 | 931 | securityContext, |
919 | 932 | new DestructiveOperations( |
920 | 933 | Settings.EMPTY, |
921 | 934 | new ClusterSettings(Settings.EMPTY, Collections.singleton(DestructiveOperations.REQUIRES_NAME_SETTING)) |
922 | 935 | ), |
923 | | - mock(CrossClusterAccessAuthenticationService.class), |
924 | | - mockLicenseState, |
925 | | - ignored -> notRemoteConnection |
926 | | - ? Optional.empty() |
927 | | - : (finalNoCredential |
928 | | - ? Optional.of(new RemoteClusterAliasWithCredentials(remoteClusterAlias, null)) |
929 | | - : Optional.of(new RemoteClusterAliasWithCredentials(remoteClusterAlias, new SecureString(encodedApiKey.toCharArray())))) |
| 936 | + new CrossClusterAccessTransportInterceptor( |
| 937 | + mock(CrossClusterAccessAuthenticationService.class), |
| 938 | + mock(AuthenticationService.class), |
| 939 | + authzService, |
| 940 | + mockLicenseState, |
| 941 | + securityContext, |
| 942 | + threadPool, |
| 943 | + settings, |
| 944 | + ignored -> notRemoteConnection |
| 945 | + ? Optional.empty() |
| 946 | + : (finalNoCredential |
| 947 | + ? Optional.of(new RemoteClusterAliasWithCredentials(remoteClusterAlias, null)) |
| 948 | + : Optional.of( |
| 949 | + new RemoteClusterAliasWithCredentials(remoteClusterAlias, new SecureString(encodedApiKey.toCharArray())) |
| 950 | + )) |
| 951 | + ) |
930 | 952 | ); |
931 | 953 |
|
932 | 954 | final AtomicBoolean calledWrappedSender = new AtomicBoolean(false); |
@@ -971,17 +993,24 @@ public void testSendWithCrossClusterAccessHeadersThrowsOnOldConnection() throws |
971 | 993 | final SecurityServerTransportInterceptor interceptor = new SecurityServerTransportInterceptor( |
972 | 994 | settings, |
973 | 995 | threadPool, |
974 | | - mock(AuthenticationService.class), |
975 | | - mock(AuthorizationService.class), |
976 | 996 | mockSslService(), |
977 | 997 | securityContext, |
978 | 998 | new DestructiveOperations( |
979 | 999 | Settings.EMPTY, |
980 | 1000 | new ClusterSettings(Settings.EMPTY, Collections.singleton(DestructiveOperations.REQUIRES_NAME_SETTING)) |
981 | 1001 | ), |
982 | | - mock(CrossClusterAccessAuthenticationService.class), |
983 | | - mockLicenseState, |
984 | | - ignored -> Optional.of(new RemoteClusterAliasWithCredentials(remoteClusterAlias, new SecureString(encodedApiKey.toCharArray()))) |
| 1002 | + new CrossClusterAccessTransportInterceptor( |
| 1003 | + mock(CrossClusterAccessAuthenticationService.class), |
| 1004 | + mock(AuthenticationService.class), |
| 1005 | + mock(AuthorizationService.class), |
| 1006 | + mockLicenseState, |
| 1007 | + securityContext, |
| 1008 | + threadPool, |
| 1009 | + settings, |
| 1010 | + ignored -> Optional.of( |
| 1011 | + new RemoteClusterAliasWithCredentials(remoteClusterAlias, new SecureString(encodedApiKey.toCharArray())) |
| 1012 | + ) |
| 1013 | + ) |
985 | 1014 | ); |
986 | 1015 |
|
987 | 1016 | final AsyncSender sender = interceptor.interceptSender(new AsyncSender() { |
@@ -1070,17 +1099,24 @@ public void testSendRemoteRequestFailsIfUserHasNoRemoteIndicesPrivileges() throw |
1070 | 1099 | final SecurityServerTransportInterceptor interceptor = new SecurityServerTransportInterceptor( |
1071 | 1100 | settings, |
1072 | 1101 | threadPool, |
1073 | | - mock(AuthenticationService.class), |
1074 | | - authzService, |
1075 | 1102 | mockSslService(), |
1076 | 1103 | securityContext, |
1077 | 1104 | new DestructiveOperations( |
1078 | 1105 | Settings.EMPTY, |
1079 | 1106 | new ClusterSettings(Settings.EMPTY, Collections.singleton(DestructiveOperations.REQUIRES_NAME_SETTING)) |
1080 | 1107 | ), |
1081 | | - mock(CrossClusterAccessAuthenticationService.class), |
1082 | | - mockLicenseState, |
1083 | | - ignored -> Optional.of(new RemoteClusterAliasWithCredentials(remoteClusterAlias, new SecureString(encodedApiKey.toCharArray()))) |
| 1108 | + new CrossClusterAccessTransportInterceptor( |
| 1109 | + mock(CrossClusterAccessAuthenticationService.class), |
| 1110 | + mock(AuthenticationService.class), |
| 1111 | + authzService, |
| 1112 | + mockLicenseState, |
| 1113 | + securityContext, |
| 1114 | + threadPool, |
| 1115 | + settings, |
| 1116 | + ignored -> Optional.of( |
| 1117 | + new RemoteClusterAliasWithCredentials(remoteClusterAlias, new SecureString(encodedApiKey.toCharArray())) |
| 1118 | + ) |
| 1119 | + ) |
1084 | 1120 | ); |
1085 | 1121 |
|
1086 | 1122 | final AsyncSender sender = interceptor.interceptSender(new AsyncSender() { |
|
0 commit comments