Skip to content

Commit 4546983

Browse files
committed
chore(bq jdbc): fix p12 unittest resource access
1 parent cbb2a7a commit 4546983

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

java-bigquery/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOAuthUtilityTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@
2929
import com.google.auth.oauth2.UserCredentials;
3030
import com.google.cloud.bigquery.exception.BigQueryJdbcRuntimeException;
3131
import java.io.IOException;
32+
import java.io.InputStream;
3233
import java.net.URI;
3334
import java.net.URISyntaxException;
3435
import java.net.URL;
35-
import java.nio.file.Files;
36-
import java.nio.file.Paths;
3736
import java.security.PrivateKey;
3837
import java.util.Collections;
3938
import java.util.HashMap;
@@ -503,11 +502,12 @@ public void testPrivateKeyFromPkcs8_wrong() {
503502
// -keypass notasecret -storetype pkcs12 -keystore ./fake.p12
504503
@Test
505504
public void testPrivateKeyFromP12Bytes() {
506-
URL resource = BigQueryJdbcOAuthUtilityTest.class.getResource("/fake.p12");
505+
InputStream stream = BigQueryJdbcOAuthUtilityTest.class.getResourceAsStream("/fake.p12");
507506
try {
508-
PrivateKey pk =
509-
BigQueryJdbcOAuthUtility.privateKeyFromP12Bytes(
510-
Files.readAllBytes(Paths.get(resource.toURI())), "notasecret");
507+
int size = 16 * 1024;
508+
byte[] data = new byte[size];
509+
stream.read(data, 0, data.length);
510+
PrivateKey pk = BigQueryJdbcOAuthUtility.privateKeyFromP12Bytes(data, "notasecret");
511511
assertNotNull(pk);
512512
} catch (Exception e) {
513513
assertTrue(false);
@@ -516,11 +516,12 @@ public void testPrivateKeyFromP12Bytes() {
516516

517517
@Test
518518
public void testPrivateKeyFromP12Bytes_wrong_password() {
519-
URL resource = BigQueryJdbcOAuthUtilityTest.class.getResource("/fake.p12");
519+
InputStream stream = BigQueryJdbcOAuthUtilityTest.class.getResourceAsStream("/fake.p12");
520520
try {
521-
PrivateKey pk =
522-
BigQueryJdbcOAuthUtility.privateKeyFromP12Bytes(
523-
Files.readAllBytes(Paths.get(resource.toURI())), "fake");
521+
int size = 16 * 1024;
522+
byte[] data = new byte[size];
523+
stream.read(data, 0, data.length);
524+
PrivateKey pk = BigQueryJdbcOAuthUtility.privateKeyFromP12Bytes(data, "fake");
524525
assertNull(pk);
525526
} catch (Exception e) {
526527
assertTrue(false);

0 commit comments

Comments
 (0)