1818package org .apache .doris .tablefunction ;
1919
2020import org .apache .doris .catalog .Env ;
21- import org .apache .doris .common .Config ;
2221import org .apache .doris .mysql .privilege .AccessControllerManager ;
2322import org .apache .doris .mysql .privilege .PrivPredicate ;
2423import org .apache .doris .nereids .exceptions .AnalysisException ;
25- import org .apache .doris .proto .InternalService .PGlobResponse ;
26- import org .apache .doris .proto .Types .PStatus ;
2724import org .apache .doris .qe .ConnectContext ;
28- import org .apache .doris .qe .SessionVariable ;
29- import org .apache .doris .resource .computegroup .ComputeGroup ;
3025import org .apache .doris .rpc .BackendServiceProxy ;
31- import org .apache .doris .system .Backend ;
3226import org .apache .doris .system .SystemInfoService ;
33- import org .apache .doris .thrift .TNetworkAddress ;
3427
3528import com .google .common .collect .ImmutableMap ;
3629import org .junit .jupiter .api .AfterEach ;
4134import org .mockito .MockedStatic ;
4235import org .mockito .Mockito ;
4336
44- import java .util .Collections ;
4537import java .util .Map ;
46- import java .util .concurrent .CompletableFuture ;
4738
48- public class LocalTableValuedFunctionEnableTest {
39+ public class LocalTableValuedFunctionDisabledTest {
4940 private static final Map <String , String > PROPERTIES = ImmutableMap .of (
50- "file_path" , "local_privilege_test .csv" , "backend_id" , "1" , "format" , "csv" );
41+ "file_path" , "local_disabled_test .csv" , "backend_id" , "1" , "format" , "csv" );
5142
5243 private final Env env = Mockito .mock (Env .class );
5344 private final ConnectContext context = Mockito .mock (ConnectContext .class );
5445 private final AccessControllerManager accessManager = Mockito .mock (AccessControllerManager .class );
5546 private final SystemInfoService systemInfo = Mockito .mock (SystemInfoService .class );
5647 private final BackendServiceProxy proxy = Mockito .mock (BackendServiceProxy .class );
57- private boolean originalEnableLocalTvf ;
5848 private MockedStatic <Env > mockedEnv ;
5949 private MockedStatic <ConnectContext > mockedContext ;
6050 private MockedStatic <BackendServiceProxy > mockedProxy ;
6151
6252 @ BeforeEach
63- public void setUp () throws Exception {
64- originalEnableLocalTvf = Config .enable_local_tvf ;
65- Config .enable_local_tvf = false ;
53+ public void setUp () {
6654 mockedEnv = Mockito .mockStatic (Env .class );
6755 mockedEnv .when (Env ::getCurrentEnv ).thenReturn (env );
6856 mockedEnv .when (Env ::getCurrentSystemInfo ).thenReturn (systemInfo );
@@ -71,45 +59,28 @@ public void setUp() throws Exception {
7159 mockedProxy = Mockito .mockStatic (BackendServiceProxy .class );
7260 mockedProxy .when (BackendServiceProxy ::getInstance ).thenReturn (proxy );
7361 Mockito .when (env .getAccessManager ()).thenReturn (accessManager );
74- Mockito .when (context .getSessionVariable ()).thenReturn (new SessionVariable ());
75- Mockito .when (context .getQueryTimeoutS ()).thenReturn (60 );
76-
77- Backend backend = Mockito .mock (Backend .class );
78- Mockito .when (backend .getId ()).thenReturn (1L );
79- Mockito .when (backend .getHost ()).thenReturn ("127.0.0.1" );
80- Mockito .when (backend .isAlive ()).thenReturn (true );
81- Mockito .when (backend .isQueryAvailable ()).thenReturn (true );
82- Mockito .when (backend .isLoadAvailable ()).thenReturn (true );
83- ComputeGroup computeGroup = Mockito .mock (ComputeGroup .class );
84- Mockito .when (context .getComputeGroup ()).thenReturn (computeGroup );
85- Mockito .when (computeGroup .getBackendList ()).thenReturn (Collections .singletonList (backend ));
86- Mockito .when (systemInfo .getBackend (1L )).thenReturn (backend );
87- Mockito .when (backend .getBrpcAddress ()).thenReturn (new TNetworkAddress ("127.0.0.1" , 8060 ));
88- Mockito .when (proxy .glob (Mockito .any (), Mockito .any ())).thenReturn (CompletableFuture .completedFuture (
89- PGlobResponse .newBuilder ().setStatus (PStatus .newBuilder ().setStatusCode (0 )).build ()));
9062 }
9163
9264 @ AfterEach
9365 public void tearDown () {
94- Config .enable_local_tvf = originalEnableLocalTvf ;
9566 mockedProxy .close ();
9667 mockedContext .close ();
9768 mockedEnv .close ();
9869 }
9970
10071 @ Test
101- public void testDisabledRejectsLocalBeforePropertyParsing () {
72+ public void testLocalDisabledBeforePropertyParsing () {
10273 AnalysisException exception = Assertions .assertThrows (AnalysisException .class ,
10374 () -> new LocalTableValuedFunction (ImmutableMap .of ()));
104- Assertions .assertTrue (exception .getMessage ().contains ("enable_local_tvf=true " ));
75+ Assertions .assertTrue (exception .getMessage ().contains ("LOCAL TVF is disabled " ));
10576 Mockito .verifyNoInteractions (accessManager , systemInfo , proxy );
10677 }
10778
10879 @ Test
109- public void testDisabledRejectsCsvAndLanceBeforeFileAccess () {
110- for (String format : new String [] {"csv" , "lance" }) {
80+ public void testFormatsDisabledBeforeFileAccess () {
81+ for (String format : new String [] {"csv" , "json" , " lance" }) {
11182 Map <String , String > properties = ImmutableMap .of (
112- "file_path" , "local_enable_test.csv " , "backend_id" , "1" , "format" , format );
83+ "file_path" , "local_disabled_test " , "backend_id" , "1" , "format" , format );
11384 AnalysisException exception = Assertions .assertThrows (AnalysisException .class ,
11485 () -> new LocalTableValuedFunction (properties ));
11586 Assertions .assertTrue (exception .getMessage ().contains ("LOCAL TVF is disabled" ));
@@ -118,33 +89,27 @@ public void testDisabledRejectsCsvAndLanceBeforeFileAccess() {
11889 }
11990
12091 @ Test
121- public void testEnabledLocalReachesExistingFileAccess () throws Exception {
122- Config .enable_local_tvf = true ;
123- Mockito .when (accessManager .checkGlobalPriv (context , PrivPredicate .ADMIN )).thenReturn (true );
124- new LocalTableValuedFunction (PROPERTIES );
125- Mockito .verify (proxy ).glob (Mockito .any (), Mockito .any ());
126- }
127-
128- @ Test
129- public void testDisabledRejectsFileLocalBeforeFileAccess () {
92+ public void testFileLocalDisabledBeforeFileAccess () {
13093 AnalysisException exception = Assertions .assertThrows (AnalysisException .class ,
13194 () -> new FileTableValuedFunction (PROPERTIES ));
13295 Assertions .assertTrue (exception .getMessage ().contains ("LOCAL TVF is disabled" ));
13396 Mockito .verifyNoInteractions (accessManager , systemInfo , proxy );
13497 }
13598
13699 @ Test
137- public void testEnabledFileLocalReachesExistingFileAccess () throws Exception {
138- Config .enable_local_tvf = true ;
139- Mockito .when (accessManager .checkGlobalPriv (context , PrivPredicate .ADMIN )).thenReturn (true );
140- new FileTableValuedFunction (PROPERTIES );
141- Mockito .verify (proxy ).glob (Mockito .any (), Mockito .any ());
100+ public void testPrivilegedUsersCannotAccessLocalFiles () {
101+ for (PrivPredicate privilege : new PrivPredicate [] {PrivPredicate .ADMIN , PrivPredicate .OPERATOR }) {
102+ Mockito .when (accessManager .checkGlobalPriv (context , privilege )).thenReturn (true );
103+ Assertions .assertThrows (AnalysisException .class , () -> new LocalTableValuedFunction (PROPERTIES ));
104+ Assertions .assertThrows (AnalysisException .class , () -> new FileTableValuedFunction (PROPERTIES ));
105+ }
106+ Mockito .verifyNoInteractions (accessManager , systemInfo , proxy );
142107 }
143108
144109 @ Test
145- public void testDisabledLocalDoesNotBlockFileS3 () {
110+ public void testFileS3RemainsAvailable () {
146111 Map <String , String > properties = ImmutableMap .<String , String >builder ()
147- .put ("uri" , "s3://test-bucket/local_enable_test .csv" )
112+ .put ("uri" , "s3://test-bucket/local_disabled_test .csv" )
148113 .put ("s3.endpoint" , "s3.us-east-1.amazonaws.com" )
149114 .put ("s3.region" , "us-east-1" )
150115 .put ("s3.access_key" , "test-access-key" )
@@ -158,30 +123,4 @@ public void testDisabledLocalDoesNotBlockFileS3() {
158123 }
159124 Mockito .verifyNoInteractions (accessManager , systemInfo , proxy );
160125 }
161-
162- @ Test
163- public void testEnabledLocalRejectsUnprivilegedUserBeforeFileAccess () {
164- Config .enable_local_tvf = true ;
165- AnalysisException exception = Assertions .assertThrows (AnalysisException .class ,
166- () -> new LocalTableValuedFunction (PROPERTIES ));
167- Assertions .assertTrue (exception .getMessage ().contains ("ADMIN/OPERATOR" ));
168- Mockito .verifyNoInteractions (systemInfo , proxy );
169- }
170-
171- @ Test
172- public void testOperatorCanAccessLocalFiles () throws Exception {
173- Config .enable_local_tvf = true ;
174- Mockito .when (accessManager .checkGlobalPriv (context , PrivPredicate .OPERATOR )).thenReturn (true );
175- new LocalTableValuedFunction (PROPERTIES );
176- Mockito .verify (proxy ).glob (Mockito .any (), Mockito .any ());
177- }
178-
179- @ Test
180- public void testEnabledLancePreservesExistingBackendSelection () throws Exception {
181- Config .enable_local_tvf = true ;
182- Mockito .when (accessManager .checkGlobalPriv (context , PrivPredicate .ADMIN )).thenReturn (true );
183- new LocalTableValuedFunction (ImmutableMap .of (
184- "file_path" , "local_enable_test.lance" , "backend_id" , "1" , "format" , "lance" ));
185- Mockito .verifyNoInteractions (proxy );
186- }
187126}
0 commit comments