Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,7 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
try {
authStatus = Futures.getDone(authStatusFuture);
} catch (ExecutionException | CancellationException e) {
// Failed futures are treated as an internal error rather than a security rejection.
authStatus = Status.INTERNAL.withCause(e);
@Nullable String message = e.getMessage();
if (message != null) {
authStatus = authStatus.withDescription(message);
}
authStatus = statusFromFailedAuthorizationFuture(e);
}

if (authStatus.isOk()) {
Expand Down Expand Up @@ -147,14 +142,19 @@ public void onSuccess(Status authStatus) {

@Override
public void onFailure(Throwable t) {
call.close(
Status.INTERNAL.withCause(t).withDescription("Authorization future failed"),
new Metadata());
call.close(statusFromFailedAuthorizationFuture(t), new Metadata());
}
},
executor);
return listener;
}

private static Status statusFromFailedAuthorizationFuture(Throwable t) {
// The actual failure is retained as the cause for debugging, but peers should see a
// uniform transport-level failure instead of the underlying exception message.
Throwable cause = t instanceof ExecutionException && t.getCause() != null ? t.getCause() : t;
return Status.INTERNAL.withCause(cause).withDescription("Authorization future failed");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,23 @@ public void testAsyncServerSecurityPolicy_failedFuture_failsWithCodeInternal() t
ListenableFuture<Status> status = makeCall();
statusesToSet.take().setException(new IllegalStateException("oops"));

assertThat(status.get().getCode()).isEqualTo(Status.Code.INTERNAL);
Status failureStatus = status.get();
assertThat(failureStatus.getCode()).isEqualTo(Status.Code.INTERNAL);
assertThat(failureStatus.getDescription()).isEqualTo("Authorization future failed");
}

@Test
public void testAsyncServerSecurityPolicy_failedFuture_cachedFailureIsOpaque() throws Exception {
ListenableFuture<Status> firstStatusFuture = makeCall();
statusesToSet.take().setException(new IOException("ouch"));

Status firstStatus = firstStatusFuture.get();
assertThat(firstStatus.getCode()).isEqualTo(Status.Code.INTERNAL);
assertThat(firstStatus.getDescription()).isEqualTo("Authorization future failed");

Status secondStatus = makeCall().get();
assertThat(secondStatus.getCode()).isEqualTo(Status.Code.INTERNAL);
assertThat(secondStatus.getDescription()).isEqualTo("Authorization future failed");
}

@Test
Expand Down
Loading