Skip to content

Commit 5dc3bce

Browse files
Remove overrideChannelBuilder (#678)
1 parent cba57c5 commit 5dc3bce

File tree

2 files changed

+7
-49
lines changed

2 files changed

+7
-49
lines changed

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/testutil/IntegrationTestUtil.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static org.junit.Assert.assertNull;
2020

2121
import android.content.Context;
22-
import android.net.SSLCertificateSocketFactory;
2322
import android.os.StrictMode;
2423
import androidx.test.core.app.ApplicationProvider;
2524
import com.google.android.gms.tasks.Task;
@@ -40,12 +39,10 @@
4039
import com.google.firebase.firestore.core.DatabaseInfo;
4140
import com.google.firebase.firestore.local.Persistence;
4241
import com.google.firebase.firestore.model.DatabaseId;
43-
import com.google.firebase.firestore.remote.GrpcCallProvider;
4442
import com.google.firebase.firestore.testutil.provider.FirestoreProvider;
4543
import com.google.firebase.firestore.util.AsyncQueue;
4644
import com.google.firebase.firestore.util.Logger;
4745
import com.google.firebase.firestore.util.Logger.Level;
48-
import io.grpc.okhttp.OkHttpChannelBuilder;
4946
import java.util.ArrayList;
5047
import java.util.HashMap;
5148
import java.util.List;
@@ -117,25 +114,7 @@ public static FirebaseFirestoreSettings newTestSettingsWithSnapshotTimestampsEna
117114

118115
if (CONNECT_TO_EMULATOR) {
119116
settings.setHost(String.format("%s:%d", EMULATOR_HOST, EMULATOR_PORT));
120-
121-
// The `sslEnabled` flag in DatabaseInfo currently does not in fact disable all SSL checks.
122-
// Instead, we manually disable the SSL certificate check and the hostname verification for
123-
// connections to the emulator.
124-
// TODO(mrschmidt): Update the client to respect the `sslEnabled` flag and remove these
125-
// channel overrides.
126-
OkHttpChannelBuilder channelBuilder =
127-
new OkHttpChannelBuilder(EMULATOR_HOST, EMULATOR_PORT) {
128-
@Override
129-
protected String checkAuthority(String authority) {
130-
return authority;
131-
}
132-
};
133-
channelBuilder.hostnameVerifier((hostname, session) -> true);
134-
SSLCertificateSocketFactory insecureFactory =
135-
(SSLCertificateSocketFactory) SSLCertificateSocketFactory.getInsecure(0, null);
136-
channelBuilder.sslSocketFactory(insecureFactory);
137-
channelBuilder.usePlaintext();
138-
GrpcCallProvider.overrideChannelBuilder(() -> channelBuilder);
117+
settings.setSslEnabled(false);
139118
} else {
140119
settings.setHost(provider.firestoreHost());
141120
}

firebase-firestore/src/main/java/com/google/firebase/firestore/remote/GrpcCallProvider.java

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package com.google.firebase.firestore.remote;
1616

1717
import android.content.Context;
18-
import androidx.annotation.VisibleForTesting;
1918
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
2019
import com.google.android.gms.common.GooglePlayServicesRepairableException;
2120
import com.google.android.gms.security.ProviderInstaller;
@@ -25,7 +24,6 @@
2524
import com.google.firebase.firestore.util.AsyncQueue;
2625
import com.google.firebase.firestore.util.Executors;
2726
import com.google.firebase.firestore.util.Logger;
28-
import com.google.firebase.firestore.util.Supplier;
2927
import com.google.firestore.v1.FirestoreGrpc;
3028
import io.grpc.CallCredentials;
3129
import io.grpc.CallOptions;
@@ -43,26 +41,11 @@ public class GrpcCallProvider {
4341

4442
private static final String LOG_TAG = "GrpcCallProvider";
4543

46-
private static Supplier<ManagedChannelBuilder<?>> overrideChannelBuilderSupplier;
47-
4844
private final Task<ManagedChannel> channelTask;
4945
private final AsyncQueue asyncQueue;
5046

5147
private CallOptions callOptions;
5248

53-
/**
54-
* Helper function to globally override the channel that RPCs use. Useful for testing when you
55-
* want to bypass SSL certificate checking.
56-
*
57-
* @param channelBuilderSupplier The supplier for a channel builder that is used to create gRPC
58-
* channels.
59-
*/
60-
@VisibleForTesting
61-
public static void overrideChannelBuilder(
62-
Supplier<ManagedChannelBuilder<?>> channelBuilderSupplier) {
63-
overrideChannelBuilderSupplier = channelBuilderSupplier;
64-
}
65-
6649
GrpcCallProvider(
6750
AsyncQueue asyncQueue,
6851
Context context,
@@ -105,16 +88,12 @@ private ManagedChannel initChannel(Context context, DatabaseInfo databaseInfo) {
10588
Logger.warn(LOG_TAG, "Failed to update ssl context: %s", e);
10689
}
10790

108-
ManagedChannelBuilder<?> channelBuilder;
109-
if (overrideChannelBuilderSupplier != null) {
110-
channelBuilder = overrideChannelBuilderSupplier.get();
111-
} else {
112-
channelBuilder = ManagedChannelBuilder.forTarget(databaseInfo.getHost());
113-
if (!databaseInfo.isSslEnabled()) {
114-
// Note that the boolean flag does *NOT* switch the wire format from Protobuf to Plaintext.
115-
// It merely turns off SSL encryption.
116-
channelBuilder.usePlaintext();
117-
}
91+
ManagedChannelBuilder<?> channelBuilder =
92+
ManagedChannelBuilder.forTarget(databaseInfo.getHost());
93+
if (!databaseInfo.isSslEnabled()) {
94+
// Note that the boolean flag does *NOT* switch the wire format from Protobuf to Plaintext.
95+
// It merely turns off SSL encryption.
96+
channelBuilder.usePlaintext();
11897
}
11998

12099
// Ensure gRPC recovers from a dead connection. (Not typically necessary, as the OS will

0 commit comments

Comments
 (0)