From 696082f52ebad64bcc89dee5dc1d02b10965cfcf Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 31 Jul 2018 14:04:51 -0700 Subject: [PATCH] auth: Small improvement to test coverage This removes an impossible condition and adds a test for another condition. --- .../GoogleAuthLibraryCallCredentials.java | 3 --- .../GoogleAuthLibraryCallCredentialsTest.java | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/auth/src/main/java/io/grpc/auth/GoogleAuthLibraryCallCredentials.java b/auth/src/main/java/io/grpc/auth/GoogleAuthLibraryCallCredentials.java index 668db152bd..c258db1bc3 100644 --- a/auth/src/main/java/io/grpc/auth/GoogleAuthLibraryCallCredentials.java +++ b/auth/src/main/java/io/grpc/auth/GoogleAuthLibraryCallCredentials.java @@ -163,9 +163,6 @@ final class GoogleAuthLibraryCallCredentials implements CallCredentials { */ private static URI serviceUri(String authority, MethodDescriptor method) throws StatusException { - if (authority == null) { - throw Status.UNAUTHENTICATED.withDescription("Channel has no authority").asException(); - } // Always use HTTPS, by definition. final String scheme = "https"; final int defaultPort = 443; diff --git a/auth/src/test/java/io/grpc/auth/GoogleAuthLibraryCallCredentialsTest.java b/auth/src/test/java/io/grpc/auth/GoogleAuthLibraryCallCredentialsTest.java index 5104ceaa28..1b60567316 100644 --- a/auth/src/test/java/io/grpc/auth/GoogleAuthLibraryCallCredentialsTest.java +++ b/auth/src/test/java/io/grpc/auth/GoogleAuthLibraryCallCredentialsTest.java @@ -311,6 +311,26 @@ public class GoogleAuthLibraryCallCredentialsTest { assertEquals(Status.Code.UNAUTHENTICATED, status.getCode()); } + @Test + public void googleCredential_nullSecurityDenied() { + final AccessToken token = new AccessToken("allyourbase", new Date(Long.MAX_VALUE)); + final Credentials credentials = GoogleCredentials.create(token); + // Null should not (for the moment) crash in horrible ways. In the future this could be changed, + // since it technically isn't allowed per the API. + Attributes integrity = attrs.toBuilder() + .set(CallCredentials.ATTR_SECURITY_LEVEL, null) + .build(); + + GoogleAuthLibraryCallCredentials callCredentials = + new GoogleAuthLibraryCallCredentials(credentials); + callCredentials.applyRequestMetadata(method, integrity, executor, applier); + runPendingRunnables(); + + verify(applier).fail(statusCaptor.capture()); + Status status = statusCaptor.getValue(); + assertEquals(Status.Code.UNAUTHENTICATED, status.getCode()); + } + @Test public void serviceUri() throws Exception { GoogleAuthLibraryCallCredentials callCredentials =