@@ -211,7 +211,8 @@ public void tlsClientServer_noClientAuthentication() throws Exception {
211211 * Uses common_tls_context.combined_validation_context in upstream_tls_context.
212212 */
213213 @ Test
214- public void tlsClientServer_useSystemRootCerts_useCombinedValidationContext () throws Exception {
214+ public void tlsClientServer_useSystemRootCerts_noMtls_useCombinedValidationContext ()
215+ throws Exception {
215216 Path trustStoreFilePath = getCacertFilePathForTestCa ();
216217 try {
217218 setTrustStoreSystemProperties (trustStoreFilePath .toAbsolutePath ().toString ());
@@ -222,7 +223,7 @@ public void tlsClientServer_useSystemRootCerts_useCombinedValidationContext() th
222223
223224 UpstreamTlsContext upstreamTlsContext =
224225 setBootstrapInfoAndBuildUpstreamTlsContextForUsingSystemRootCerts (CLIENT_KEY_FILE ,
225- CLIENT_PEM_FILE , true , SAN_TO_MATCH );
226+ CLIENT_PEM_FILE , true , SAN_TO_MATCH , false );
226227
227228 SimpleServiceGrpc .SimpleServiceBlockingStub blockingStub =
228229 getBlockingStub (upstreamTlsContext , /* overrideAuthority= */ OVERRIDE_AUTHORITY );
@@ -238,7 +239,7 @@ public void tlsClientServer_useSystemRootCerts_useCombinedValidationContext() th
238239 * Uses common_tls_context.validation_context in upstream_tls_context.
239240 */
240241 @ Test
241- public void tlsClientServer_useSystemRootCerts_validationContext () throws Exception {
242+ public void tlsClientServer_useSystemRootCerts_noMtls_validationContext () throws Exception {
242243 Path trustStoreFilePath = getCacertFilePathForTestCa ().toAbsolutePath ();
243244 try {
244245 setTrustStoreSystemProperties (trustStoreFilePath .toAbsolutePath ().toString ());
@@ -249,7 +250,7 @@ public void tlsClientServer_useSystemRootCerts_validationContext() throws Except
249250
250251 UpstreamTlsContext upstreamTlsContext =
251252 setBootstrapInfoAndBuildUpstreamTlsContextForUsingSystemRootCerts (CLIENT_KEY_FILE ,
252- CLIENT_PEM_FILE , false , SAN_TO_MATCH );
253+ CLIENT_PEM_FILE , false , SAN_TO_MATCH , false );
253254
254255 SimpleServiceGrpc .SimpleServiceBlockingStub blockingStub =
255256 getBlockingStub (upstreamTlsContext , /* overrideAuthority= */ OVERRIDE_AUTHORITY );
@@ -260,6 +261,29 @@ public void tlsClientServer_useSystemRootCerts_validationContext() throws Except
260261 }
261262 }
262263
264+ @ Test
265+ public void tlsClientServer_useSystemRootCerts_mtls () throws Exception {
266+ Path trustStoreFilePath = getCacertFilePathForTestCa ();
267+ try {
268+ setTrustStoreSystemProperties (trustStoreFilePath .toAbsolutePath ().toString ());
269+ DownstreamTlsContext downstreamTlsContext =
270+ setBootstrapInfoAndBuildDownstreamTlsContext (SERVER_1_PEM_FILE , null , null , null , null ,
271+ null , false , true );
272+ buildServerWithTlsContext (downstreamTlsContext );
273+
274+ UpstreamTlsContext upstreamTlsContext =
275+ setBootstrapInfoAndBuildUpstreamTlsContextForUsingSystemRootCerts (CLIENT_KEY_FILE ,
276+ CLIENT_PEM_FILE , true , SAN_TO_MATCH , true );
277+
278+ SimpleServiceGrpc .SimpleServiceBlockingStub blockingStub =
279+ getBlockingStub (upstreamTlsContext , /* overrideAuthority= */ OVERRIDE_AUTHORITY );
280+ assertThat (unaryRpc (/* requestMessage= */ "buddy" , blockingStub )).isEqualTo ("Hello buddy" );
281+ } finally {
282+ Files .deleteIfExists (trustStoreFilePath );
283+ clearTrustStoreSystemProperties ();
284+ }
285+ }
286+
263287 /**
264288 * Use system root ca cert for TLS channel - no mTLS.
265289 * Subj Alt Names to match are specified in the validaton context.
@@ -276,7 +300,7 @@ public void tlsClientServer_useSystemRootCerts_failureToMatchSubjAltNames() thro
276300
277301 UpstreamTlsContext upstreamTlsContext =
278302 setBootstrapInfoAndBuildUpstreamTlsContextForUsingSystemRootCerts (CLIENT_KEY_FILE ,
279- CLIENT_PEM_FILE , true , "server1.test.google.in" );
303+ CLIENT_PEM_FILE , true , "server1.test.google.in" , false );
280304
281305 SimpleServiceGrpc .SimpleServiceBlockingStub blockingStub =
282306 getBlockingStub (upstreamTlsContext , /* overrideAuthority= */ OVERRIDE_AUTHORITY );
@@ -309,7 +333,7 @@ public void tlsClientServer_useSystemRootCerts_requireClientAuth() throws Except
309333
310334 UpstreamTlsContext upstreamTlsContext =
311335 setBootstrapInfoAndBuildUpstreamTlsContextForUsingSystemRootCerts (CLIENT_KEY_FILE ,
312- CLIENT_PEM_FILE , true , SAN_TO_MATCH );
336+ CLIENT_PEM_FILE , true , SAN_TO_MATCH , false );
313337
314338 SimpleServiceGrpc .SimpleServiceBlockingStub blockingStub =
315339 getBlockingStub (upstreamTlsContext , /* overrideAuthority= */ OVERRIDE_AUTHORITY );
@@ -590,13 +614,14 @@ private UpstreamTlsContext setBootstrapInfoAndBuildUpstreamTlsContext(String cli
590614 private UpstreamTlsContext setBootstrapInfoAndBuildUpstreamTlsContextForUsingSystemRootCerts (
591615 String clientKeyFile ,
592616 String clientPemFile ,
593- boolean useCombinedValidationContext , String sanToMatch ) {
617+ boolean useCombinedValidationContext , String sanToMatch , boolean isMtls ) {
594618 bootstrapInfoForClient = CommonBootstrapperTestUtils
595619 .buildBootstrapInfo ("google_cloud_private_spiffe-client" , clientKeyFile , clientPemFile ,
596620 CA_PEM_FILE , null , null , null , null , null );
597621 if (useCombinedValidationContext ) {
598622 return CommonTlsContextTestsUtil .buildUpstreamTlsContextForCertProviderInstance (
599- "google_cloud_private_spiffe-client" , "ROOT" , null ,
623+ isMtls ? "google_cloud_private_spiffe-client" : null ,
624+ isMtls ? "ROOT" : null , null ,
600625 null , null ,
601626 CertificateValidationContext .newBuilder ()
602627 .setSystemRootCerts (
0 commit comments