-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...r-demo/src/main/java/org/lognet/springboot/grpc/demo/BuggyReactiveGreeterGrpcService.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,33 @@ | ||
package org.lognet.springboot.grpc.demo; | ||
|
||
import io.grpc.examples.reactor.ReactiveHelloRequest; | ||
import io.grpc.examples.reactor.ReactiveHelloResponse; | ||
import io.grpc.examples.reactor.ReactorReactiveGreeterGrpc; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.lognet.springboot.grpc.GRpcService; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.security.access.annotation.Secured; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import reactor.core.publisher.Mono; | ||
|
||
|
||
@GRpcService | ||
@Slf4j | ||
@ConditionalOnClass(Transactional.class) | ||
@Profile("reactive-buggy-security") | ||
public class BuggyReactiveGreeterGrpcService extends ReactorReactiveGreeterGrpc.ReactiveGreeterImplBase { | ||
|
||
|
||
@Override | ||
@Secured({}) | ||
public Mono<ReactiveHelloResponse> greet(Mono<ReactiveHelloRequest> request) { | ||
return super.greet(request); | ||
} | ||
|
||
@Override | ||
@Secured({}) //invalid | ||
public Mono<ReactiveHelloResponse> greet(ReactiveHelloRequest request) { | ||
return super.greet(request); | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
.../src/reactiveTest/java/org/lognet/springboot/grpc/reactive/BaggyReactiveSecurityTest.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,52 @@ | ||
package org.lognet.springboot.grpc.reactive; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.lognet.springboot.grpc.auth.JwtAuthBaseTest; | ||
import org.lognet.springboot.grpc.demo.DemoApp; | ||
import org.lognet.springboot.rules.ExpectedStartupExceptionWithInspector; | ||
import org.lognet.springboot.rules.SpringRunnerWithGlobalExpectedExceptionInspected; | ||
import org.springframework.beans.factory.BeanCreationException; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.core.NestedExceptionUtils; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.util.function.Predicate; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
|
||
@Slf4j | ||
@RunWith(SpringRunnerWithGlobalExpectedExceptionInspected.class) | ||
@SpringBootTest(classes = DemoApp.class) | ||
@ActiveProfiles({"keycloack-test", "r2dbc-test", "reactive-buggy-security"}) | ||
@DirtiesContext | ||
@ExpectedStartupExceptionWithInspector(BaggyReactiveSecurityTest.ExceptionInspector.class) | ||
public class BaggyReactiveSecurityTest extends JwtAuthBaseTest { | ||
|
||
@Test | ||
public void contextStartupFails() { | ||
} | ||
|
||
public static class ExceptionInspector implements Predicate<Throwable> { | ||
|
||
@Override | ||
public boolean test(Throwable throwable) { | ||
|
||
Throwable rootCause = NestedExceptionUtils.getRootCause(throwable); | ||
assertThat(rootCause, instanceOf(BeanCreationException.class)); | ||
BeanCreationException beanCreationException = (BeanCreationException) rootCause; | ||
|
||
assertThat(beanCreationException.getMessage(), allOf( | ||
notNullValue(String.class), | ||
stringContainsInOrder("Ambiguous", "Secured", "method") | ||
)); | ||
|
||
return true; | ||
} | ||
|
||
} | ||
} |