Search in sources :

Example 1 with RSocketProxy

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

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

use of io.rsocket.util.RSocketProxy 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)

Example 4 with RSocketProxy

use of io.rsocket.util.RSocketProxy 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 5 with RSocketProxy

use of io.rsocket.util.RSocketProxy 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)5 RSocket (io.rsocket.RSocket)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 Publisher (org.reactivestreams.Publisher)1 TestPublisher (reactor.test.publisher.TestPublisher)1