Search in sources :

Example 1 with RSocket

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

the class PayloadInterceptorRSocketTests method metadataPushWhenSecurityContextThenDelegateContext.

@Test
public void metadataPushWhenSecurityContextThenDelegateContext() {
    TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
    given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
    given(this.delegate.metadataPush(any())).willReturn(this.voidResult.mono());
    RSocket assertAuthentication = new RSocketProxy(this.delegate) {

        @Override
        public Mono<Void> metadataPush(Payload payload) {
            return assertAuthentication(authentication).flatMap((a) -> super.metadataPush(payload));
        }
    };
    PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(assertAuthentication, Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
    StepVerifier.create(interceptor.metadataPush(this.payload)).verifyComplete();
    verify(this.interceptor).intercept(this.exchange.capture(), any());
    assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
    verify(this.delegate).metadataPush(this.payload);
    this.voidResult.assertWasSubscribed();
}
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 2 with RSocket

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

the class PayloadInterceptorRSocketTests method fireAndForgetWhenSecurityContextThenDelegateContext.

@Test
public void fireAndForgetWhenSecurityContextThenDelegateContext() {
    TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
    given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
    given(this.delegate.fireAndForget(any())).willReturn(Mono.empty());
    RSocket assertAuthentication = new RSocketProxy(this.delegate) {

        @Override
        public Mono<Void> fireAndForget(Payload payload) {
            return assertAuthentication(authentication).flatMap((a) -> super.fireAndForget(payload));
        }
    };
    PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(assertAuthentication, Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
    interceptor.fireAndForget(this.payload).block();
    verify(this.interceptor).intercept(this.exchange.capture(), any());
    assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
    verify(this.delegate).fireAndForget(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 3 with RSocket

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

the class PayloadSocketAcceptorTests method captureExchange.

private PayloadExchange captureExchange() {
    given(this.delegate.accept(any(), any())).willReturn(Mono.just(this.rSocket));
    given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
    RSocket result = this.acceptor.accept(this.setupPayload, this.rSocket).block();
    assertThat(result).isInstanceOf(PayloadInterceptorRSocket.class);
    given(this.rSocket.fireAndForget(any())).willReturn(Mono.empty());
    result.fireAndForget(this.payload).block();
    ArgumentCaptor<PayloadExchange> exchangeArg = ArgumentCaptor.forClass(PayloadExchange.class);
    verify(this.interceptor, times(2)).intercept(exchangeArg.capture(), any());
    return exchangeArg.getValue();
}
Also used : PayloadExchange(org.springframework.security.rsocket.api.PayloadExchange) RSocket(io.rsocket.RSocket)

Example 4 with RSocket

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

the class PayloadSocketAcceptorInterceptorTests method captureExchange.

private PayloadExchange captureExchange() {
    given(this.socketAcceptor.accept(any(), any())).willReturn(Mono.just(this.rSocket));
    given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
    SocketAcceptor wrappedAcceptor = this.acceptorInterceptor.apply(this.socketAcceptor);
    RSocket result = wrappedAcceptor.accept(this.setupPayload, this.rSocket).block();
    assertThat(result).isInstanceOf(PayloadInterceptorRSocket.class);
    given(this.rSocket.fireAndForget(any())).willReturn(Mono.empty());
    result.fireAndForget(this.payload).block();
    ArgumentCaptor<PayloadExchange> exchangeArg = ArgumentCaptor.forClass(PayloadExchange.class);
    verify(this.interceptor, times(2)).intercept(exchangeArg.capture(), any());
    return exchangeArg.getValue();
}
Also used : PayloadExchange(org.springframework.security.rsocket.api.PayloadExchange) SocketAcceptor(io.rsocket.SocketAcceptor) RSocket(io.rsocket.RSocket)

Example 5 with RSocket

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

the class PayloadInterceptorRSocketTests method requestResponseWhenSecurityContextThenDelegateContext.

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

        @Override
        public Mono<Payload> requestResponse(Payload payload) {
            return assertAuthentication(authentication).flatMap((a) -> super.requestResponse(payload));
        }
    };
    PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(assertAuthentication, Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
    StepVerifier.create(interceptor.requestResponse(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).requestResponse(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)

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