Skip to content

Commit e9c4e3c

Browse files
committed
Save changes.
1 parent f12bc61 commit e9c4e3c

10 files changed

+44
-43
lines changed

xds/src/test/java/io/grpc/xds/CdsLoadBalancer2Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public class CdsLoadBalancer2Test {
107107
.node(BOOTSTRAP_NODE)
108108
.build();
109109
private final UpstreamTlsContext upstreamTlsContext =
110-
CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe", true);
110+
CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe", true, null, false);
111111
private final OutlierDetection outlierDetection = OutlierDetection.create(
112112
null, null, null, null, SuccessRateEjection.create(null, null, null, null), null);
113113

xds/src/test/java/io/grpc/xds/ClusterImplLoadBalancerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ public void endpointAddressesAttachedWithClusterName() {
881881
@Test
882882
public void endpointAddressesAttachedWithTlsConfig_securityEnabledByDefault() {
883883
UpstreamTlsContext upstreamTlsContext =
884-
CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe", true);
884+
CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe", true, null, false);
885885
LoadBalancerProvider weightedTargetProvider = new WeightedTargetLoadBalancerProvider();
886886
WeightedTargetConfig weightedTargetConfig =
887887
buildWeightedTargetConfig(ImmutableMap.of(locality, 10));
@@ -926,7 +926,7 @@ public void endpointAddressesAttachedWithTlsConfig_securityEnabledByDefault() {
926926

927927
// Config with a new UpstreamTlsContext.
928928
upstreamTlsContext =
929-
CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe1", true);
929+
CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe1", true, null, false);
930930
config = new ClusterImplConfig(CLUSTER, EDS_SERVICE_NAME, LRS_SERVER_INFO,
931931
null, Collections.<DropOverload>emptyList(),
932932
GracefulSwitchLoadBalancer.createLoadBalancingPolicyConfig(

xds/src/test/java/io/grpc/xds/ClusterResolverLoadBalancerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public class ClusterResolverLoadBalancerTest {
134134
private final Locality locality3 =
135135
Locality.create("test-region-3", "test-zone-3", "test-subzone-3");
136136
private final UpstreamTlsContext tlsContext =
137-
CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe", true);
137+
CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe", true, null, false);
138138
private final OutlierDetection outlierDetection = OutlierDetection.create(
139139
100L, 100L, 100L, 100, SuccessRateEjection.create(100, 100, 100, 100),
140140
FailurePercentageEjection.create(100, 100, 100, 100));

xds/src/test/java/io/grpc/xds/XdsSecurityClientServerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ private UpstreamTlsContext setBootstrapInfoAndBuildUpstreamTlsContext(String cli
546546
.buildBootstrapInfo("google_cloud_private_spiffe-client", clientKeyFile, clientPemFile,
547547
CA_PEM_FILE, null, null, null, null, spiffeFile);
548548
return CommonTlsContextTestsUtil
549-
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", hasIdentityCert);
549+
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", hasIdentityCert, null, false);
550550
}
551551

552552
private UpstreamTlsContext setBootstrapInfoAndBuildUpstreamTlsContextForUsingSystemRootCerts(
@@ -563,7 +563,7 @@ private UpstreamTlsContext setBootstrapInfoAndBuildUpstreamTlsContextForUsingSys
563563
CertificateValidationContext.newBuilder()
564564
.setSystemRootCerts(
565565
CertificateValidationContext.SystemRootCerts.newBuilder().build())
566-
.build());
566+
.build(), null, false);
567567
}
568568
return CommonTlsContextTestsUtil.buildNewUpstreamTlsContextForCertProviderInstance(
569569
"google_cloud_private_spiffe-client", "ROOT", null,

xds/src/test/java/io/grpc/xds/internal/security/ClientSslContextProviderFactoryTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext;
3131
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.TlsCertificate;
3232
import io.envoyproxy.envoy.type.matcher.v3.StringMatcher;
33-
import io.grpc.xds.EnvoyServerProtoData;
3433
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
3534
import io.grpc.xds.client.Bootstrapper;
3635
import io.grpc.xds.client.CommonBootstrapperTestUtils;
@@ -80,7 +79,7 @@ public void createCertProviderClientSslContextProvider() throws XdsInitializatio
8079
"gcp_id",
8180
"root-default",
8281
/* alpnProtocols= */ null,
83-
/* staticCertValidationContext= */ null);
82+
/* staticCertValidationContext= */ null, null, false);
8483

8584
Bootstrapper.BootstrapInfo bootstrapInfo = CommonBootstrapperTestUtils.getTestBootstrapInfo();
8685
clientSslContextProviderFactory =
@@ -139,7 +138,7 @@ public void createCertProviderClientSslContextProvider_onlyRootCert()
139138
"gcp_id",
140139
"root-default",
141140
/* alpnProtocols= */ null,
142-
/* staticCertValidationContext= */ null);
141+
/* staticCertValidationContext= */ null, null, false);
143142

144143
Bootstrapper.BootstrapInfo bootstrapInfo = CommonBootstrapperTestUtils.getTestBootstrapInfo();
145144
clientSslContextProviderFactory =
@@ -173,7 +172,7 @@ public void createCertProviderClientSslContextProvider_withStaticContext()
173172
"gcp_id",
174173
"root-default",
175174
/* alpnProtocols= */ null,
176-
staticCertValidationContext);
175+
staticCertValidationContext, null, false);
177176

178177
Bootstrapper.BootstrapInfo bootstrapInfo = CommonBootstrapperTestUtils.getTestBootstrapInfo();
179178
clientSslContextProviderFactory =
@@ -203,7 +202,7 @@ public void createCertProviderClientSslContextProvider_2providers()
203202
"file_provider",
204203
"root-default",
205204
/* alpnProtocols= */ null,
206-
/* staticCertValidationContext= */ null);
205+
/* staticCertValidationContext= */ null, null, false);
207206

208207
Bootstrapper.BootstrapInfo bootstrapInfo = CommonBootstrapperTestUtils.getTestBootstrapInfo();
209208
clientSslContextProviderFactory =

xds/src/test/java/io/grpc/xds/internal/security/CommonTlsContextTestsUtil.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,28 @@ public static String getTempFileNameForResourcesFile(String resFile) throws IOEx
149149
* Helper method to build UpstreamTlsContext for above tests. Called from other classes as well.
150150
*/
151151
static EnvoyServerProtoData.UpstreamTlsContext buildUpstreamTlsContext(
152-
CommonTlsContext commonTlsContext) {
153-
UpstreamTlsContext upstreamTlsContext =
154-
UpstreamTlsContext.newBuilder().setCommonTlsContext(commonTlsContext).build();
152+
CommonTlsContext commonTlsContext, String sni, boolean autoHostSni) {
153+
UpstreamTlsContext.Builder upstreamTlsContext =
154+
UpstreamTlsContext.newBuilder().setCommonTlsContext(commonTlsContext).setAutoHostSni(autoHostSni);
155+
if (sni != null) {
156+
upstreamTlsContext.setSni(sni);
157+
}
155158
return EnvoyServerProtoData.UpstreamTlsContext.fromEnvoyProtoUpstreamTlsContext(
156-
upstreamTlsContext);
159+
upstreamTlsContext.build());
157160
}
158161

159162
/** Helper method to build UpstreamTlsContext for multiple test classes. */
160163
public static EnvoyServerProtoData.UpstreamTlsContext buildUpstreamTlsContext(
161-
String commonInstanceName, boolean hasIdentityCert) {
164+
String commonInstanceName, boolean hasIdentityCert, String sni, boolean autoHostSni) {
162165
return buildUpstreamTlsContextForCertProviderInstance(
163166
hasIdentityCert ? commonInstanceName : null,
164167
hasIdentityCert ? "default" : null,
165168
commonInstanceName,
166169
"ROOT",
167170
null,
168-
null);
171+
null,
172+
sni,
173+
autoHostSni);
169174
}
170175

171176
/** Gets a cert from contents of a resource. */
@@ -271,20 +276,21 @@ private static CommonTlsContext.Builder addNewCertificateValidationContext(
271276
/** Helper method to build UpstreamTlsContext for CertProvider tests. */
272277
public static EnvoyServerProtoData.UpstreamTlsContext
273278
buildUpstreamTlsContextForCertProviderInstance(
274-
@Nullable String certInstanceName,
275-
@Nullable String certName,
276-
@Nullable String rootInstanceName,
277-
@Nullable String rootCertName,
278-
Iterable<String> alpnProtocols,
279-
CertificateValidationContext staticCertValidationContext) {
279+
@Nullable String certInstanceName,
280+
@Nullable String certName,
281+
@Nullable String rootInstanceName,
282+
@Nullable String rootCertName,
283+
Iterable<String> alpnProtocols,
284+
CertificateValidationContext staticCertValidationContext, String sni, boolean autoHostSni) {
280285
return buildUpstreamTlsContext(
281286
buildCommonTlsContextForCertProviderInstance(
282287
certInstanceName,
283288
certName,
284289
rootInstanceName,
285290
rootCertName,
286291
alpnProtocols,
287-
staticCertValidationContext));
292+
staticCertValidationContext),
293+
sni, autoHostSni);
288294
}
289295

290296
/** Helper method to build UpstreamTlsContext for CertProvider tests. */
@@ -303,7 +309,7 @@ private static CommonTlsContext.Builder addNewCertificateValidationContext(
303309
rootInstanceName,
304310
rootCertName,
305311
alpnProtocols,
306-
staticCertValidationContext));
312+
staticCertValidationContext), null, false);
307313
}
308314

309315
/** Helper method to build DownstreamTlsContext for CertProvider tests. */

xds/src/test/java/io/grpc/xds/internal/security/SecurityProtocolNegotiatorsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void clientSecurityProtocolNegotiatorNewHandler_noFallback_expectExceptio
124124
@Test
125125
public void clientSecurityProtocolNegotiatorNewHandler_withTlsContextAttribute() {
126126
UpstreamTlsContext upstreamTlsContext =
127-
CommonTlsContextTestsUtil.buildUpstreamTlsContext(CommonTlsContext.newBuilder().build());
127+
CommonTlsContextTestsUtil.buildUpstreamTlsContext(CommonTlsContext.newBuilder().build(), null, false);
128128
ClientSecurityProtocolNegotiator pn =
129129
new ClientSecurityProtocolNegotiator(InternalProtocolNegotiators.plaintext());
130130
GrpcHttp2ConnectionHandler mockHandler = mock(GrpcHttp2ConnectionHandler.class);
@@ -153,7 +153,7 @@ public void clientSecurityHandler_addLast()
153153
CA_PEM_FILE, null, null, null, null, null);
154154
UpstreamTlsContext upstreamTlsContext =
155155
CommonTlsContextTestsUtil
156-
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", true);
156+
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", true, null, false);
157157

158158
SslContextProviderSupplier sslContextProviderSupplier =
159159
new SslContextProviderSupplier(upstreamTlsContext,
@@ -365,7 +365,7 @@ public void clientSecurityProtocolNegotiatorNewHandler_fireProtocolNegotiationEv
365365
CA_PEM_FILE, null, null, null, null, null);
366366
UpstreamTlsContext upstreamTlsContext =
367367
CommonTlsContextTestsUtil
368-
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", true);
368+
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", true, null, false);
369369

370370
SslContextProviderSupplier sslContextProviderSupplier =
371371
new SslContextProviderSupplier(upstreamTlsContext,
@@ -416,7 +416,7 @@ public void clientSecurityProtocolNegotiatorNewHandler_handleHandlerRemoved() {
416416
CA_PEM_FILE, null, null, null, null, null);
417417
UpstreamTlsContext upstreamTlsContext =
418418
CommonTlsContextTestsUtil
419-
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", true);
419+
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", true, null, false);
420420

421421
SslContextProviderSupplier sslContextProviderSupplier =
422422
new SslContextProviderSupplier(upstreamTlsContext,

xds/src/test/java/io/grpc/xds/internal/security/SslContextProviderSupplierTest.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,14 @@ public class SslContextProviderSupplierTest {
5757

5858
private void prepareSupplier(boolean autoHostSni) {
5959
upstreamTlsContext =
60-
CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe", true);
60+
CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe", true, null, autoHostSni);
6161
mockSslContextProvider = mock(SslContextProvider.class);
6262
doReturn(mockSslContextProvider)
6363
.when(mockTlsContextManager)
6464
.findOrCreateClientSslContextProvider(eq(upstreamTlsContext), eq(HOSTNAME));
6565
supplier = new SslContextProviderSupplier(upstreamTlsContext, mockTlsContextManager);
6666
}
6767

68-
private EnvoyServerProtoData.UpstreamTlsContext getUpstreamTlsContext(boolean autoHostSni) {
69-
70-
}
71-
7268
private void callUpdateSslContext() {
7369
mockCallback = mock(SslContextProvider.Callback.class);
7470
when(mockCallback.getHostname()).thenReturn(HOSTNAME);
@@ -79,7 +75,7 @@ private void callUpdateSslContext() {
7975

8076
@Test
8177
public void get_updateSecret() {
82-
prepareSupplier();
78+
prepareSupplier(false);
8379
callUpdateSslContext();
8480
verify(mockTlsContextManager, times(2))
8581
.findOrCreateClientSslContextProvider(eq(upstreamTlsContext), eq(HOSTNAME));
@@ -103,7 +99,7 @@ public void get_updateSecret() {
10399

104100
@Test
105101
public void get_onException() {
106-
prepareSupplier();
102+
prepareSupplier(false);
107103
callUpdateSslContext();
108104
ArgumentCaptor<SslContextProvider.Callback> callbackCaptor =
109105
ArgumentCaptor.forClass(SslContextProvider.Callback.class);
@@ -119,7 +115,7 @@ public void get_onException() {
119115

120116
@Test
121117
public void testClose() {
122-
prepareSupplier();
118+
prepareSupplier(false);
123119
callUpdateSslContext();
124120
supplier.close();
125121
verify(mockTlsContextManager, times(1))
@@ -133,7 +129,7 @@ public void testClose() {
133129

134130
@Test
135131
public void testClose_nullSslContextProvider() {
136-
prepareSupplier();
132+
prepareSupplier(false);
137133
doThrow(new NullPointerException()).when(mockTlsContextManager)
138134
.releaseClientSslContextProvider(null, HOSTNAME);
139135
supplier.close();

xds/src/test/java/io/grpc/xds/internal/security/TlsContextManagerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void createClientSslContextProvider() {
8282
CA_PEM_FILE, null, null, null, null, null);
8383
UpstreamTlsContext upstreamTlsContext =
8484
CommonTlsContextTestsUtil
85-
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", false);
85+
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", false, null, false);
8686

8787
TlsContextManagerImpl tlsContextManagerImpl = new TlsContextManagerImpl(bootstrapInfoForClient);
8888
SslContextProvider clientSecretProvider =
@@ -126,15 +126,15 @@ public void createClientSslContextProvider_differentInstance() {
126126
CA_PEM_FILE, "cert-instance-2", CLIENT_KEY_FILE, CLIENT_PEM_FILE, CA_PEM_FILE, null);
127127
UpstreamTlsContext upstreamTlsContext =
128128
CommonTlsContextTestsUtil
129-
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", false);
129+
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", false, null, false);
130130

131131
TlsContextManagerImpl tlsContextManagerImpl = new TlsContextManagerImpl(bootstrapInfoForClient);
132132
SslContextProvider clientSecretProvider =
133133
tlsContextManagerImpl.findOrCreateClientSslContextProvider(upstreamTlsContext, SNI);
134134
assertThat(clientSecretProvider).isNotNull();
135135

136136
UpstreamTlsContext upstreamTlsContext1 =
137-
CommonTlsContextTestsUtil.buildUpstreamTlsContext("cert-instance-2", true);
137+
CommonTlsContextTestsUtil.buildUpstreamTlsContext("cert-instance-2", true, null, false);
138138

139139
SslContextProvider clientSecretProvider1 =
140140
tlsContextManagerImpl.findOrCreateClientSslContextProvider(upstreamTlsContext1, SNI);
@@ -164,7 +164,7 @@ public void createServerSslContextProvider_releaseInstance() {
164164
public void createClientSslContextProvider_releaseInstance() {
165165
UpstreamTlsContext upstreamTlsContext =
166166
CommonTlsContextTestsUtil
167-
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", true);
167+
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", true, null, false);
168168

169169
TlsContextManagerImpl tlsContextManagerImpl =
170170
new TlsContextManagerImpl(mockClientFactory, mockServerFactory);

xds/src/test/java/io/grpc/xds/internal/security/certprovider/CertProviderClientSslContextProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private CertProviderClientSslContextProvider getSslContextProvider(
8181
rootInstanceName,
8282
"root-default",
8383
alpnProtocols,
84-
staticCertValidationContext);
84+
staticCertValidationContext, null, false);
8585
return (CertProviderClientSslContextProvider)
8686
certProviderClientSslContextProviderFactory.getProvider(
8787
upstreamTlsContext,

0 commit comments

Comments
 (0)