118118@ RunWith (Parameterized .class )
119119public class XdsSecurityClientServerTest {
120120
121- // TODO: Change this is a specific domain after
121+ // TODO: Change this to a specific domain after
122122 // https://github.com/grpc/grpc-java/issues/12326 is fixed
123123 private static final String SAN_TO_MATCH = "*.test.google.fr" ;
124124
@@ -223,7 +223,7 @@ public void tlsClientServer_useSystemRootCerts_noMtls_useCombinedValidationConte
223223
224224 UpstreamTlsContext upstreamTlsContext =
225225 setBootstrapInfoAndBuildUpstreamTlsContextForUsingSystemRootCerts (CLIENT_KEY_FILE ,
226- CLIENT_PEM_FILE , true , SAN_TO_MATCH , false );
226+ CLIENT_PEM_FILE , true , SAN_TO_MATCH , false , null );
227227
228228 SimpleServiceGrpc .SimpleServiceBlockingStub blockingStub =
229229 getBlockingStub (upstreamTlsContext , /* overrideAuthority= */ OVERRIDE_AUTHORITY );
@@ -250,7 +250,7 @@ public void tlsClientServer_useSystemRootCerts_noMtls_validationContext() throws
250250
251251 UpstreamTlsContext upstreamTlsContext =
252252 setBootstrapInfoAndBuildUpstreamTlsContextForUsingSystemRootCerts (CLIENT_KEY_FILE ,
253- CLIENT_PEM_FILE , false , SAN_TO_MATCH , false );
253+ CLIENT_PEM_FILE , false , SAN_TO_MATCH , false , null );
254254
255255 SimpleServiceGrpc .SimpleServiceBlockingStub blockingStub =
256256 getBlockingStub (upstreamTlsContext , /* overrideAuthority= */ OVERRIDE_AUTHORITY );
@@ -273,7 +273,7 @@ public void tlsClientServer_useSystemRootCerts_mtls() throws Exception {
273273
274274 UpstreamTlsContext upstreamTlsContext =
275275 setBootstrapInfoAndBuildUpstreamTlsContextForUsingSystemRootCerts (CLIENT_KEY_FILE ,
276- CLIENT_PEM_FILE , true , SAN_TO_MATCH , true );
276+ CLIENT_PEM_FILE , true , SAN_TO_MATCH , true , null );
277277
278278 SimpleServiceGrpc .SimpleServiceBlockingStub blockingStub =
279279 getBlockingStub (upstreamTlsContext , /* overrideAuthority= */ OVERRIDE_AUTHORITY );
@@ -286,10 +286,11 @@ public void tlsClientServer_useSystemRootCerts_mtls() throws Exception {
286286
287287 /**
288288 * Use system root ca cert for TLS channel - no mTLS.
289- * Subj Alt Names to match are specified in the validaton context.
289+ * Subj Alt Names to match are specified in the validation context.
290290 */
291291 @ Test
292- public void tlsClientServer_useSystemRootCerts_failureToMatchSubjAltNames () throws Exception {
292+ public void tlsClientServer_useSystemRootCerts_noAutoSniValidation_failureToMatchSubjAltNames ()
293+ throws Exception {
293294 Path trustStoreFilePath = getCacertFilePathForTestCa ();
294295 try {
295296 setTrustStoreSystemProperties (trustStoreFilePath .toAbsolutePath ().toString ());
@@ -300,7 +301,7 @@ public void tlsClientServer_useSystemRootCerts_failureToMatchSubjAltNames() thro
300301
301302 UpstreamTlsContext upstreamTlsContext =
302303 setBootstrapInfoAndBuildUpstreamTlsContextForUsingSystemRootCerts (CLIENT_KEY_FILE ,
303- CLIENT_PEM_FILE , true , "server1.test.google.in" , false );
304+ CLIENT_PEM_FILE , true , "server1.test.google.in" , false , null );
304305
305306 SimpleServiceGrpc .SimpleServiceBlockingStub blockingStub =
306307 getBlockingStub (upstreamTlsContext , /* overrideAuthority= */ OVERRIDE_AUTHORITY );
@@ -317,6 +318,33 @@ public void tlsClientServer_useSystemRootCerts_failureToMatchSubjAltNames() thro
317318 }
318319 }
319320
321+ @ Test
322+ public void tlsClientServer_useSystemRootCerts_autoSniValidation ()
323+ throws Exception {
324+ Path trustStoreFilePath = getCacertFilePathForTestCa ();
325+ try {
326+ setTrustStoreSystemProperties (trustStoreFilePath .toAbsolutePath ().toString ());
327+ DownstreamTlsContext downstreamTlsContext =
328+ setBootstrapInfoAndBuildDownstreamTlsContext (SERVER_1_PEM_FILE , null , null , null , null ,
329+ null , false , false );
330+ buildServerWithTlsContext (downstreamTlsContext );
331+
332+ UpstreamTlsContext upstreamTlsContext =
333+ setBootstrapInfoAndBuildUpstreamTlsContextForUsingSystemRootCerts (CLIENT_KEY_FILE ,
334+ CLIENT_PEM_FILE , true ,
335+ // won't be used
336+ "server1.test.google.in" ,
337+ false , SAN_TO_MATCH );
338+
339+ SimpleServiceGrpc .SimpleServiceBlockingStub blockingStub =
340+ getBlockingStub (upstreamTlsContext , /* overrideAuthority= */ OVERRIDE_AUTHORITY );
341+ unaryRpc (/* requestMessage= */ "buddy" , blockingStub );
342+ } finally {
343+ Files .deleteIfExists (trustStoreFilePath );
344+ clearTrustStoreSystemProperties ();
345+ }
346+ }
347+
320348 /**
321349 * Use system root ca cert for TLS channel - mTLS.
322350 * Uses common_tls_context.combined_validation_context in upstream_tls_context.
@@ -333,7 +361,7 @@ public void tlsClientServer_useSystemRootCerts_requireClientAuth() throws Except
333361
334362 UpstreamTlsContext upstreamTlsContext =
335363 setBootstrapInfoAndBuildUpstreamTlsContextForUsingSystemRootCerts (CLIENT_KEY_FILE ,
336- CLIENT_PEM_FILE , true , SAN_TO_MATCH , false );
364+ CLIENT_PEM_FILE , true , SAN_TO_MATCH , false , null );
337365
338366 SimpleServiceGrpc .SimpleServiceBlockingStub blockingStub =
339367 getBlockingStub (upstreamTlsContext , /* overrideAuthority= */ OVERRIDE_AUTHORITY );
@@ -615,7 +643,7 @@ private UpstreamTlsContext setBootstrapInfoAndBuildUpstreamTlsContext(String cli
615643 private UpstreamTlsContext setBootstrapInfoAndBuildUpstreamTlsContextForUsingSystemRootCerts (
616644 String clientKeyFile ,
617645 String clientPemFile ,
618- boolean useCombinedValidationContext , String sanToMatch , boolean isMtls ) {
646+ boolean useCombinedValidationContext , String sanToMatch , boolean isMtls , String sni ) {
619647 bootstrapInfoForClient = CommonBootstrapperTestUtils
620648 .buildBootstrapInfo ("google_cloud_private_spiffe-client" , clientKeyFile , clientPemFile ,
621649 CA_PEM_FILE , null , null , null , null , null );
@@ -630,7 +658,7 @@ private UpstreamTlsContext setBootstrapInfoAndBuildUpstreamTlsContextForUsingSys
630658 .addMatchSubjectAltNames (
631659 StringMatcher .newBuilder ()
632660 .setExact (sanToMatch ))
633- .build ());
661+ .build (), sni , false );
634662 }
635663 return CommonTlsContextTestsUtil .buildNewUpstreamTlsContextForCertProviderInstance (
636664 "google_cloud_private_spiffe-client" , "ROOT" , null ,
0 commit comments