55package org .whispersystems .textsecuregcm .grpc ;
66
77import static org .assertj .core .api .Assertions .assertThat ;
8+ import static org .mockito .Mockito .mock ;
9+ import static org .mockito .Mockito .when ;
810
911import com .google .protobuf .ByteString ;
1012import io .grpc .ManagedChannel ;
1416import io .grpc .inprocess .InProcessServerBuilder ;
1517import java .io .IOException ;
1618import java .util .Collections ;
17- import java .util .List ;
19+ import java .util .Set ;
1820import java .util .concurrent .TimeUnit ;
1921import org .junit .jupiter .api .AfterEach ;
2022import org .junit .jupiter .api .BeforeEach ;
2123import org .junit .jupiter .api .Test ;
2224import org .signal .chat .rpc .EchoRequest ;
2325import org .signal .chat .rpc .EchoResponse ;
2426import org .signal .chat .rpc .EchoServiceGrpc ;
27+ import org .whispersystems .textsecuregcm .configuration .dynamic .DynamicConfiguration ;
28+ import org .whispersystems .textsecuregcm .configuration .dynamic .DynamicGrpcAllowListConfiguration ;
29+ import org .whispersystems .textsecuregcm .tests .util .FakeDynamicConfigurationManager ;
30+
2531
2632class GrpcAllowListInterceptorTest {
2733 private Server server ;
@@ -45,23 +51,23 @@ void tearDown() throws Exception {
4551 @ Test
4652 public void disableAll () throws Exception {
4753 final EchoServiceGrpc .EchoServiceBlockingStub client =
48- setup (false , Collections .emptyList (), Collections .emptyList ());
54+ setup (false , Collections .emptySet (), Collections .emptySet ());
4955 GrpcTestUtils .assertStatusException (Status .UNIMPLEMENTED , () ->
5056 client .echo (EchoRequest .newBuilder ().setPayload (ByteString .empty ()).build ()));
5157 }
5258
5359 @ Test
5460 public void enableAll () throws Exception {
5561 final EchoServiceGrpc .EchoServiceBlockingStub client =
56- setup (true , Collections .emptyList (), Collections .emptyList ());
62+ setup (true , Collections .emptySet (), Collections .emptySet ());
5763 final EchoResponse echo = client .echo (EchoRequest .newBuilder ().setPayload (ByteString .empty ()).build ());
5864 assertThat (echo .getPayload ()).isEqualTo (ByteString .empty ());
5965 }
6066
6167 @ Test
6268 public void enableByMethod () throws Exception {
6369 final EchoServiceGrpc .EchoServiceBlockingStub client =
64- setup (false , Collections .emptyList (), List .of ("org.signal.chat.rpc.EchoService/echo" ));
70+ setup (false , Collections .emptySet (), Set .of ("org.signal.chat.rpc.EchoService/echo" ));
6571
6672 final EchoResponse echo = client .echo (EchoRequest .newBuilder ().setPayload (ByteString .empty ()).build ());
6773 assertThat (echo .getPayload ()).isEqualTo (ByteString .empty ());
@@ -73,7 +79,7 @@ public void enableByMethod() throws Exception {
7379 @ Test
7480 public void enableByService () throws Exception {
7581 final EchoServiceGrpc .EchoServiceBlockingStub client =
76- setup (false , List .of ("org.signal.chat.rpc.EchoService" ), Collections .emptyList ());
82+ setup (false , Set .of ("org.signal.chat.rpc.EchoService" ), Collections .emptySet ());
7783
7884 final EchoResponse echo = client .echo (EchoRequest .newBuilder ().setPayload (ByteString .empty ()).build ());
7985 assertThat (echo .getPayload ()).isEqualTo (ByteString .empty ());
@@ -85,24 +91,27 @@ public void enableByService() throws Exception {
8591 @ Test
8692 public void enableByServiceWrongService () throws Exception {
8793 final EchoServiceGrpc .EchoServiceBlockingStub client =
88- setup (false , List .of ("org.signal.chat.rpc.NotEchoService" ), Collections .emptyList ());
94+ setup (false , Set .of ("org.signal.chat.rpc.NotEchoService" ), Collections .emptySet ());
8995
9096 GrpcTestUtils .assertStatusException (Status .UNIMPLEMENTED , () ->
9197 client .echo (EchoRequest .newBuilder ().setPayload (ByteString .empty ()).build ()));
9298 }
9399
94100 private EchoServiceGrpc .EchoServiceBlockingStub setup (
95101 boolean enableAll ,
96- List <String > enabledServices ,
97- List <String > enabledMethods )
102+ Set <String > enabledServices ,
103+ Set <String > enabledMethods )
98104 throws IOException {
99105 if (server != null ) {
100106 server .shutdownNow ();
101107 }
108+ final DynamicConfiguration configuration = mock (DynamicConfiguration .class );
109+ when (configuration .getGrpcAllowList ())
110+ .thenReturn (new DynamicGrpcAllowListConfiguration (enableAll , enabledServices , enabledMethods ));
102111 server = InProcessServerBuilder .forName ("GrpcAllowListInterceptorTest" )
103112 .directExecutor ()
104113 .addService (new EchoServiceImpl ())
105- .intercept (new GrpcAllowListInterceptor (enableAll , enabledServices , enabledMethods ))
114+ .intercept (new GrpcAllowListInterceptor (new FakeDynamicConfigurationManager <>( configuration ) ))
106115 .build ()
107116 .start ();
108117
0 commit comments