Skip to content

Commit 90fe11d

Browse files
committed
refactor: remove validation reflection by making signUsingEsSha256 package-private
1 parent 8f23285 commit 90fe11d

2 files changed

Lines changed: 3 additions & 21 deletions

File tree

oauth2_http/java/com/google/auth/oauth2/GdchCredentials.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ private void setTransport(String caCertPath) throws IOException {
681681
* @throws IOException If serialization or transcoding fails.
682682
*/
683683
@VisibleForTesting
684-
private static String signUsingEsSha256(
684+
static String signUsingEsSha256(
685685
PrivateKey privateKey,
686686
JsonFactory jsonFactory,
687687
JsonWebSignature.Header header,

oauth2_http/javatests/com/google/auth/oauth2/GdchCredentialsTest.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,17 +1189,8 @@ void signUsingEsSha256_producesVerifiableSignature() throws Exception {
11891189
payload.setIssuer("test-issuer");
11901190
payload.setAudience("test-audience");
11911191

1192-
// Use reflection to call the private method.
1193-
Method signMethod =
1194-
GdchCredentials.class.getDeclaredMethod(
1195-
"signUsingEsSha256",
1196-
PrivateKey.class,
1197-
JsonFactory.class,
1198-
JsonWebSignature.Header.class,
1199-
JsonWebToken.Payload.class);
1200-
signMethod.setAccessible(true);
12011192
String signedJws =
1202-
(String) signMethod.invoke(null, keyPair.getPrivate(), jsonFactory, header, payload);
1193+
GdchCredentials.signUsingEsSha256(keyPair.getPrivate(), jsonFactory, header, payload);
12031194

12041195
// Verify the signature.
12051196
JsonWebSignature jws = JsonWebSignature.parse(jsonFactory, signedJws);
@@ -1224,16 +1215,7 @@ void signUsingEsSha256_validStructure() throws Exception {
12241215
payload.setIssuedAtTimeSeconds(1000L);
12251216
payload.setExpirationTimeSeconds(2000L);
12261217

1227-
// Reflectively call the private signUsingEsSha256 method
1228-
Method signMethod =
1229-
GdchCredentials.class.getDeclaredMethod(
1230-
"signUsingEsSha256",
1231-
PrivateKey.class,
1232-
JsonFactory.class,
1233-
JsonWebSignature.Header.class,
1234-
JsonWebToken.Payload.class);
1235-
signMethod.setAccessible(true);
1236-
String signedJws = (String) signMethod.invoke(null, privateKey, jsonFactory, header, payload);
1218+
String signedJws = GdchCredentials.signUsingEsSha256(privateKey, jsonFactory, header, payload);
12371219

12381220
// Verify JWS structure
12391221
String[] parts = signedJws.split("\\.");

0 commit comments

Comments
 (0)