Skip to content

Commit caefb6d

Browse files
committed
test(pqc): add unit tests for PQC Conscrypt transport configuration in GAX and Core HTTP
1 parent ed56e4a commit caefb6d

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

sdk-platform-java/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/InstantiatingHttpJsonChannelProviderTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,14 @@ protected Object getMtlsObjectFromTransportChannel(
198198
}
199199

200200
@Test
201-
void testCreateHttpTransport_returnsValidTransport() throws Exception {
201+
void testCreateHttpTransport_pqcConfigured() throws Exception {
202+
boolean conscryptAvailable = false;
203+
try {
204+
org.conscrypt.Conscrypt.newProvider();
205+
conscryptAvailable = org.conscrypt.Conscrypt.isAvailable();
206+
} catch (Throwable t) {
207+
// Conscrypt JNI native shared library is not available on this host environment
208+
}
202209
InstantiatingHttpJsonChannelProvider channelProvider =
203210
InstantiatingHttpJsonChannelProvider.newBuilder()
204211
.setEndpoint("localhost:8080")
@@ -207,6 +214,14 @@ void testCreateHttpTransport_returnsValidTransport() throws Exception {
207214
.build();
208215
NetHttpTransport transport = (NetHttpTransport) channelProvider.createHttpTransport();
209216
assertThat(transport).isNotNull();
217+
if (conscryptAvailable) {
218+
Object factory = getPrivateField(transport, "sslSocketFactory");
219+
assertThat(factory).isNotNull();
220+
assertThat(factory.getClass().getName())
221+
.isEqualTo("com.google.api.client.http.javanet.ConfigurableSSLSocketFactory");
222+
Object configurator = getPrivateField(factory, "configurator");
223+
assertThat(configurator).isNotNull();
224+
}
210225
}
211226

212227
@Test
@@ -216,4 +231,10 @@ void testDefaultPqcGroups_containsExpectedGroups() {
216231
.containsExactly("X25519MLKEM768", "SecP256r1MLKEM768", "X25519")
217232
.inOrder();
218233
}
234+
235+
private static Object getPrivateField(Object obj, String fieldName) throws Exception {
236+
java.lang.reflect.Field field = obj.getClass().getDeclaredField(fieldName);
237+
field.setAccessible(true);
238+
return field.get(obj);
239+
}
219240
}

sdk-platform-java/java-core/google-cloud-core-http/src/test/java/com/google/cloud/http/HttpTransportOptionsTest.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,30 @@ void testBuilder() {
118118
assertEquals(-1, DEFAULT_OPTIONS.getReadTimeout());
119119
}
120120

121+
@Test
122+
void testDefaultHttpTransportFactory_createPqcConfiguredTransport() throws Exception {
123+
boolean conscryptAvailable = false;
124+
try {
125+
org.conscrypt.Conscrypt.newProvider();
126+
conscryptAvailable = org.conscrypt.Conscrypt.isAvailable();
127+
} catch (Throwable t) {
128+
// Conscrypt JNI native shared library is not available on this host environment
129+
}
130+
DefaultHttpTransportFactory factory = new DefaultHttpTransportFactory();
131+
HttpTransport transport = factory.create();
132+
assertTrue(transport instanceof com.google.api.client.http.javanet.NetHttpTransport);
133+
if (conscryptAvailable) {
134+
java.lang.reflect.Field field =
135+
com.google.api.client.http.javanet.NetHttpTransport.class.getDeclaredField(
136+
"sslSocketFactory");
137+
field.setAccessible(true);
138+
Object sslSocketFactory = field.get(transport);
139+
assertEquals(
140+
"com.google.api.client.http.javanet.ConfigurableSSLSocketFactory",
141+
sslSocketFactory.getClass().getName());
142+
}
143+
}
144+
121145
@Test
122146
void testBaseEquals() {
123147
assertEquals(OPTIONS, OPTIONS_COPY);
@@ -166,7 +190,9 @@ void testHttpRequestInitializer_defaultUniverseDomainSettings_customCredentials(
166190
UnauthenticatedException.class,
167191
() -> httpRequestInitializer.initialize(defaultHttpRequest));
168192
assertEquals(
169-
"The configured universe domain (googleapis.com) does not match the universe domain found in the credentials (random.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default.",
193+
"The configured universe domain (googleapis.com) does not match the universe domain found"
194+
+ " in the credentials (random.com). If you haven't configured the universe domain"
195+
+ " explicitly, `googleapis.com` is the default.",
170196
exception.getCause().getMessage());
171197
}
172198

@@ -181,7 +207,9 @@ void testHttpRequestInitializer_customUniverseDomainSettings_defaultCredentials(
181207
UnauthenticatedException.class,
182208
() -> httpRequestInitializer.initialize(defaultHttpRequest));
183209
assertEquals(
184-
"The configured universe domain (random.com) does not match the universe domain found in the credentials (googleapis.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default.",
210+
"The configured universe domain (random.com) does not match the universe domain found in"
211+
+ " the credentials (googleapis.com). If you haven't configured the universe domain"
212+
+ " explicitly, `googleapis.com` is the default.",
185213
exception.getCause().getMessage());
186214
}
187215

@@ -219,7 +247,9 @@ void testHttpRequestInitializer_customUniverseDomainSettings_noCredentials() {
219247
UnauthenticatedException.class,
220248
() -> httpRequestInitializer.initialize(defaultHttpRequest));
221249
assertEquals(
222-
"The configured universe domain (random.com) does not match the universe domain found in the credentials (googleapis.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default.",
250+
"The configured universe domain (random.com) does not match the universe domain found in"
251+
+ " the credentials (googleapis.com). If you haven't configured the universe domain"
252+
+ " explicitly, `googleapis.com` is the default.",
223253
exception.getCause().getMessage());
224254
}
225255

0 commit comments

Comments
 (0)