auth: Small improvement to test coverage

This removes an impossible condition and adds a test for another
condition.
This commit is contained in:
Eric Anderson 2018-07-31 14:04:51 -07:00
parent 5878b6ddca
commit 696082f52e
2 changed files with 20 additions and 3 deletions

View File

@ -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;

View File

@ -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 =