1 // Copyright 2024 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 //////////////////////////////////////////////////////////////////////////////// 16 17 package com.google.crypto.tink.internal; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import com.google.crypto.tink.testing.TestUtil; 22 import java.security.Provider; 23 import org.conscrypt.Conscrypt; 24 import org.junit.Test; 25 import org.junit.runner.RunWith; 26 import org.junit.runners.JUnit4; 27 28 @RunWith(JUnit4.class) 29 public final class ConscryptUtilWithoutInstallingConscryptTest { 30 31 @Test providerOrNull_returnsProviderOnlyOnAndroid()32 public void providerOrNull_returnsProviderOnlyOnAndroid() throws Exception { 33 if (TestUtil.isAndroid()) { 34 // Android uses Conscrypt by default. 35 Provider provider = ConscryptUtil.providerOrNull(); 36 assertThat(provider).isNotNull(); 37 assertThat(ConscryptUtil.isConscryptProvider(provider)).isTrue(); 38 } else { 39 // Conscrypt is not installed. 40 Provider provider = ConscryptUtil.providerOrNull(); 41 assertThat(provider).isNull(); 42 } 43 } 44 45 @Test providerWithReflectionOrNull_returnsProviderIfNotOnAndroid()46 public void providerWithReflectionOrNull_returnsProviderIfNotOnAndroid() throws Exception { 47 if (TestUtil.isAndroid()) { 48 // providerWithReflectionOrNull does not work on Android 49 Provider provider = ConscryptUtil.providerWithReflectionOrNull(); 50 assertThat(provider).isNull(); 51 } else { 52 Provider provider = ConscryptUtil.providerWithReflectionOrNull(); 53 assertThat(provider).isNotNull(); 54 assertThat(ConscryptUtil.isConscryptProvider(provider)).isTrue(); 55 56 // Make a call to Conscrypt to make sure it is present in the binary. 57 // But we don't install it. 58 Conscrypt.checkAvailability(); 59 } 60 } 61 } 62