@@ -173,6 +173,63 @@ public void testProviderForClient_mtls() throws Exception {
173173 assertThat (testCallback1 .updatedSslContext ).isNotSameInstanceAs (testCallback .updatedSslContext );
174174 }
175175
176+ @ Test
177+ public void testProviderForClient_systemRootCerts () throws Exception {
178+ final CertificateProvider .DistributorWatcher [] watcherCaptor =
179+ new CertificateProvider .DistributorWatcher [1 ];
180+ TestCertificateProvider .createAndRegisterProviderProvider (
181+ certificateProviderRegistry , watcherCaptor , "testca" , 0 );
182+ CertProviderClientSslContextProvider provider =
183+ getSslContextProvider (
184+ "gcp_id" ,
185+ null ,
186+ CommonBootstrapperTestUtils .getTestBootstrapInfo (),
187+ /* alpnProtocols= */ null ,
188+ /* staticCertValidationContext= */ null );
189+
190+ assertThat (provider .savedKey ).isNull ();
191+ assertThat (provider .savedCertChain ).isNull ();
192+ assertThat (provider .savedTrustedRoots ).isNull ();
193+ assertThat (provider .getSslContext ()).isNull ();
194+
195+ // now generate cert update, updates SslContext
196+ watcherCaptor [0 ].updateCertificate (
197+ CommonCertProviderTestUtils .getPrivateKey (CLIENT_KEY_FILE ),
198+ ImmutableList .of (getCertFromResourceName (CLIENT_PEM_FILE )));
199+ assertThat (provider .savedKey ).isNull ();
200+ assertThat (provider .savedCertChain ).isNull ();
201+ assertThat (provider .getSslContext ()).isNotNull ();
202+
203+ TestCallback testCallback =
204+ CommonTlsContextTestsUtil .getValueThruCallback (provider );
205+
206+ doChecksOnSslContext (false , testCallback .updatedSslContext , /* expectedApnProtos= */ null );
207+ TestCallback testCallback1 =
208+ CommonTlsContextTestsUtil .getValueThruCallback (provider );
209+ assertThat (testCallback1 .updatedSslContext ).isSameInstanceAs (testCallback .updatedSslContext );
210+
211+ // just do root cert update: trusted roots is not updated (because of system root certs config)
212+ // and sslContext should still be the same
213+ watcherCaptor [0 ].updateTrustedRoots (
214+ ImmutableList .of (getCertFromResourceName (SERVER_0_PEM_FILE )));
215+ assertThat (provider .savedKey ).isNull ();
216+ assertThat (provider .savedCertChain ).isNull ();
217+ assertThat (provider .savedTrustedRoots ).isNull ();
218+ testCallback1 = CommonTlsContextTestsUtil .getValueThruCallback (provider );
219+ assertThat (testCallback1 .updatedSslContext ).isSameInstanceAs (testCallback .updatedSslContext );
220+
221+ // now update id cert: sslContext should be updated i.e.different from the previous one
222+ watcherCaptor [0 ].updateCertificate (
223+ CommonCertProviderTestUtils .getPrivateKey (SERVER_1_KEY_FILE ),
224+ ImmutableList .of (getCertFromResourceName (SERVER_1_PEM_FILE )));
225+ assertThat (provider .savedKey ).isNull ();
226+ assertThat (provider .savedCertChain ).isNull ();
227+ assertThat (provider .savedTrustedRoots ).isNull ();
228+ assertThat (provider .getSslContext ()).isNotNull ();
229+ testCallback1 = CommonTlsContextTestsUtil .getValueThruCallback (provider );
230+ assertThat (testCallback1 .updatedSslContext ).isNotSameInstanceAs (testCallback .updatedSslContext );
231+ }
232+
176233 @ Test
177234 public void testProviderForClient_mtls_newXds () throws Exception {
178235 final CertificateProvider .DistributorWatcher [] watcherCaptor =
0 commit comments