Search in sources :

Example 26 with Payload

use of io.rsocket.Payload in project spring-security by spring-projects.

the class PayloadInterceptorRSocketTests method requestChannelWhenSecurityContextThenDelegateContext.

@Test
public void requestChannelWhenSecurityContextThenDelegateContext() {
    Mono<Payload> payload = Mono.just(this.payload);
    TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
    given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
    given(this.delegate.requestChannel(any())).willReturn(this.payloadResult.flux());
    RSocket assertAuthentication = new RSocketProxy(this.delegate) {

        @Override
        public Flux<Payload> requestChannel(Publisher<Payload> payload) {
            return assertAuthentication(authentication).flatMapMany((a) -> super.requestChannel(payload));
        }
    };
    PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(assertAuthentication, Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
    StepVerifier.create(interceptor.requestChannel(payload)).then(() -> this.payloadResult.assertSubscribers()).then(() -> this.payloadResult.emit(this.payload)).expectNext(this.payload).verifyComplete();
    verify(this.interceptor).intercept(this.exchange.capture(), any());
    assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
    verify(this.delegate).requestChannel(any());
}
Also used : RSocketProxy(io.rsocket.util.RSocketProxy) RSocket(io.rsocket.RSocket) DefaultPayload(io.rsocket.util.DefaultPayload) ByteBufPayload(io.rsocket.util.ByteBufPayload) Payload(io.rsocket.Payload) TestPublisher(reactor.test.publisher.TestPublisher) Publisher(org.reactivestreams.Publisher) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.jupiter.api.Test)

Aggregations

Payload (io.rsocket.Payload)26 Test (org.junit.jupiter.api.Test)23 DefaultPayload (io.rsocket.util.DefaultPayload)16 ByteBufPayload (io.rsocket.util.ByteBufPayload)14 DataBuffer (org.springframework.core.io.buffer.DataBuffer)12 NettyDataBuffer (org.springframework.core.io.buffer.NettyDataBuffer)9 RSocket (io.rsocket.RSocket)7 RSocketProxy (io.rsocket.util.RSocketProxy)6 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)6 DefaultDataBuffer (org.springframework.core.io.buffer.DefaultDataBuffer)5 MimeType (org.springframework.util.MimeType)5 WellKnownMimeType (io.rsocket.metadata.WellKnownMimeType)4 Publisher (org.reactivestreams.Publisher)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 RSocketConnector (io.rsocket.core.RSocketConnector)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Flux (reactor.core.publisher.Flux)2 Mono (reactor.core.publisher.Mono)2