From cf3e2c4ef17e733dd97d9b8dca04e040ab4d29dd Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Thu, 12 Sep 2019 13:17:35 -0700 Subject: [PATCH] auth: Avoid com.auth0:java-jwt dependency in test --- auth/build.gradle | 3 +-- .../GoogleAuthLibraryCallCredentialsTest.java | 21 +++++++++++-------- build.gradle | 1 - 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/auth/build.gradle b/auth/build.gradle index 0d1ad372d7..09619ea562 100644 --- a/auth/build.gradle +++ b/auth/build.gradle @@ -3,8 +3,7 @@ dependencies { compile project(':grpc-api'), libraries.google_auth_credentials testCompile project(':grpc-testing'), - libraries.google_auth_oauth2_http, - libraries.jwt + libraries.google_auth_oauth2_http signature "org.codehaus.mojo.signature:java17:1.0@signature" signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature" } diff --git a/auth/src/test/java/io/grpc/auth/GoogleAuthLibraryCallCredentialsTest.java b/auth/src/test/java/io/grpc/auth/GoogleAuthLibraryCallCredentialsTest.java index fed11b70ee..bb1a569abf 100644 --- a/auth/src/test/java/io/grpc/auth/GoogleAuthLibraryCallCredentialsTest.java +++ b/auth/src/test/java/io/grpc/auth/GoogleAuthLibraryCallCredentialsTest.java @@ -28,8 +28,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.auth0.jwt.JWT; -import com.auth0.jwt.interfaces.DecodedJWT; import com.google.auth.Credentials; import com.google.auth.RequestMetadataCallback; import com.google.auth.oauth2.AccessToken; @@ -40,6 +38,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.ListMultimap; import com.google.common.collect.Multimaps; +import com.google.common.io.BaseEncoding; import io.grpc.Attributes; import io.grpc.CallCredentials; import io.grpc.CallCredentials.MetadataApplier; @@ -47,6 +46,7 @@ import io.grpc.Metadata; import io.grpc.MethodDescriptor; import io.grpc.SecurityLevel; import io.grpc.Status; +import io.grpc.internal.JsonParser; import io.grpc.testing.TestMethodDescriptors; import java.io.IOException; import java.net.URI; @@ -408,13 +408,16 @@ public class GoogleAuthLibraryCallCredentialsTest { verify(applier).apply(headersCaptor.capture()); Metadata headers = headersCaptor.getValue(); String token = - Iterables.getOnlyElement(headers.getAll(AUTHORIZATION)).substring("Bearer".length()); - DecodedJWT decoded = JWT.decode(token); - assertEquals("test-private-key-id", decoded.getKeyId()); - assertEquals("https://example.com:123/a.service", - Iterables.getOnlyElement(decoded.getAudience())); - assertEquals("test-email@example.com", decoded.getIssuer()); - assertEquals("test-email@example.com", decoded.getSubject()); + Iterables.getOnlyElement(headers.getAll(AUTHORIZATION)).substring("Bearer ".length()); + String[] parts = token.split("\\.", 3); + String jsonHeader = new String(BaseEncoding.base64Url().decode(parts[0]), US_ASCII); + String jsonPayload = new String(BaseEncoding.base64Url().decode(parts[1]), US_ASCII); + Map header = (Map) JsonParser.parse(jsonHeader); + assertEquals("test-private-key-id", header.get("kid")); + Map payload = (Map) JsonParser.parse(jsonPayload); + assertEquals("https://example.com:123/a.service", payload.get("aud")); + assertEquals("test-email@example.com", payload.get("iss")); + assertEquals("test-email@example.com", payload.get("sub")); } private int runPendingRunnables() { diff --git a/build.gradle b/build.gradle index 55f8cc88a7..8336fb222f 100644 --- a/build.gradle +++ b/build.gradle @@ -191,7 +191,6 @@ subprojects { hpack: 'com.twitter:hpack:0.10.1', javax_annotation: 'javax.annotation:javax.annotation-api:1.2', jsr305: 'com.google.code.findbugs:jsr305:3.0.2', - jwt: 'com.auth0:java-jwt:3.8.2', google_api_protos: 'com.google.api.grpc:proto-google-common-protos:1.12.0', google_auth_credentials: "com.google.auth:google-auth-library-credentials:${googleauthVersion}", google_auth_oauth2_http: "com.google.auth:google-auth-library-oauth2-http:${googleauthVersion}",