-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block onHalfClose if onMessage was blocked (#241)
* test that SecurityInterceptor does not propagate onHalfClose after closing the request * set the locale in ValidationTest so it passes on non-English systems * test that ValidatingInterceptor does not propagate onHalfClose after closing the request * also block onHalfClose after blocking onMessage fixes #240
- Loading branch information
Showing
6 changed files
with
140 additions
and
23 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...ring-boot-starter-demo/src/test/java/org/lognet/springboot/grpc/HalfCloseInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.lognet.springboot.grpc; | ||
|
||
import io.grpc.ForwardingServerCallListener; | ||
import io.grpc.Metadata; | ||
import io.grpc.ServerCall; | ||
import io.grpc.ServerCallHandler; | ||
import io.grpc.ServerInterceptor; | ||
|
||
@GRpcGlobalInterceptor | ||
public class HalfCloseInterceptor implements ServerInterceptor { | ||
@Override | ||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall( | ||
ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next | ||
) { | ||
return new ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT>(next.startCall(call, headers)) { | ||
@Override | ||
public void onHalfClose() { | ||
HalfCloseInterceptor.this.onHalfClose(); | ||
super.onHalfClose(); | ||
} | ||
}; | ||
} | ||
|
||
public void onHalfClose() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...r-demo/src/test/java/org/lognet/springboot/grpc/auth/FailLateSecurityInterceptorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.lognet.springboot.grpc.auth; | ||
|
||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import com.google.protobuf.Empty; | ||
import io.grpc.Status; | ||
import io.grpc.StatusRuntimeException; | ||
import io.grpc.examples.SecuredGreeterGrpc; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.lognet.springboot.grpc.GrpcServerTestBase; | ||
import org.lognet.springboot.grpc.HalfCloseInterceptor; | ||
import org.lognet.springboot.grpc.demo.DemoApp; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.SpyBean; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
@SpringBootTest( | ||
classes = DemoApp.class, | ||
properties = "grpc.security.auth.fail-fast=false" | ||
) | ||
@RunWith(SpringRunner.class) | ||
public class FailLateSecurityInterceptorTest extends GrpcServerTestBase { | ||
@SpyBean | ||
HalfCloseInterceptor halfCloseInterceptor; | ||
|
||
@Test | ||
public void noHalfCloseOnFailedAuth() { | ||
final StatusRuntimeException statusRuntimeException = assertThrows( | ||
StatusRuntimeException.class, | ||
() -> SecuredGreeterGrpc.newBlockingStub(selectedChanel).sayAuthHello2(Empty.newBuilder().build()).getMessage() | ||
); | ||
assertThat(statusRuntimeException.getStatus().getCode(), Matchers.is(Status.Code.UNAUTHENTICATED)); | ||
verify(halfCloseInterceptor, never()).onHalfClose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters