Search in sources :

Example 6 with RSocket

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

the class PayloadInterceptorRSocketTests method requestStreamWhenSecurityContextThenDelegateContext.

@Test
public void requestStreamWhenSecurityContextThenDelegateContext() {
    TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
    given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
    given(this.delegate.requestStream(any())).willReturn(this.payloadResult.flux());
    RSocket assertAuthentication = new RSocketProxy(this.delegate) {

        @Override
        public Flux<Payload> requestStream(Payload payload) {
            return assertAuthentication(authentication).flatMapMany((a) -> super.requestStream(payload));
        }
    };
    PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(assertAuthentication, Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
    StepVerifier.create(interceptor.requestStream(this.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).requestStream(this.payload);
}
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) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.jupiter.api.Test)

Example 7 with RSocket

use of io.rsocket.RSocket 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

RSocket (io.rsocket.RSocket)7 Payload (io.rsocket.Payload)5 ByteBufPayload (io.rsocket.util.ByteBufPayload)5 DefaultPayload (io.rsocket.util.DefaultPayload)5 RSocketProxy (io.rsocket.util.RSocketProxy)5 Test (org.junit.jupiter.api.Test)5 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)5 PayloadExchange (org.springframework.security.rsocket.api.PayloadExchange)2 SocketAcceptor (io.rsocket.SocketAcceptor)1 Publisher (org.reactivestreams.Publisher)1 TestPublisher (reactor.test.publisher.TestPublisher)1