Search in sources :

Example 6 with PayloadExchange

use of org.springframework.security.rsocket.api.PayloadExchange in project spring-security by spring-projects.

the class PayloadSocketAcceptorInterceptorTests method acceptWhenDefaultMetadataMimeTypeOverrideThenDefaulted.

@Test
public void acceptWhenDefaultMetadataMimeTypeOverrideThenDefaulted() {
    this.acceptorInterceptor.setDefaultMetadataMimeType(MediaType.APPLICATION_JSON);
    given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
    PayloadExchange exchange = captureExchange();
    assertThat(exchange.getMetadataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
    assertThat(exchange.getDataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
}
Also used : PayloadExchange(org.springframework.security.rsocket.api.PayloadExchange) Test(org.junit.jupiter.api.Test)

Example 7 with PayloadExchange

use of org.springframework.security.rsocket.api.PayloadExchange in project spring-security by spring-projects.

the class AuthenticationPayloadInterceptorTests method interceptWhenAuthenticationSuccessThenChainSubscribedOnce.

@Test
public void interceptWhenAuthenticationSuccessThenChainSubscribedOnce() {
    AuthenticationPayloadInterceptor interceptor = new AuthenticationPayloadInterceptor(this.authenticationManager);
    PayloadExchange exchange = createExchange();
    TestingAuthenticationToken expectedAuthentication = new TestingAuthenticationToken("user", "password");
    given(this.authenticationManager.authenticate(any())).willReturn(Mono.just(expectedAuthentication));
    PublisherProbe<Void> voidResult = PublisherProbe.empty();
    PayloadInterceptorChain chain = mock(PayloadInterceptorChain.class);
    given(chain.next(any())).willReturn(voidResult.mono());
    StepVerifier.create(interceptor.intercept(exchange, chain)).then(() -> assertThat(voidResult.subscribeCount()).isEqualTo(1)).verifyComplete();
}
Also used : DefaultPayloadExchange(org.springframework.security.rsocket.core.DefaultPayloadExchange) PayloadExchange(org.springframework.security.rsocket.api.PayloadExchange) PayloadInterceptorChain(org.springframework.security.rsocket.api.PayloadInterceptorChain) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.jupiter.api.Test)

Example 8 with PayloadExchange

use of org.springframework.security.rsocket.api.PayloadExchange 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 9 with PayloadExchange

use of org.springframework.security.rsocket.api.PayloadExchange in project spring-security by spring-projects.

the class PayloadSocketAcceptorTests method acceptWhenExplicitMimeTypeThenThenOverrideDefault.

@Test
public void acceptWhenExplicitMimeTypeThenThenOverrideDefault() {
    given(this.setupPayload.metadataMimeType()).willReturn(MediaType.TEXT_PLAIN_VALUE);
    given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
    PayloadExchange exchange = captureExchange();
    assertThat(exchange.getMetadataMimeType()).isEqualTo(MediaType.TEXT_PLAIN);
    assertThat(exchange.getDataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
}
Also used : PayloadExchange(org.springframework.security.rsocket.api.PayloadExchange) Test(org.junit.jupiter.api.Test)

Example 10 with PayloadExchange

use of org.springframework.security.rsocket.api.PayloadExchange in project spring-security by spring-projects.

the class PayloadSocketAcceptorTests method acceptWhenDefaultDataMimeTypeThenDefaulted.

@Test
public void acceptWhenDefaultDataMimeTypeThenDefaulted() {
    this.acceptor.setDefaultDataMimeType(MediaType.APPLICATION_JSON);
    PayloadExchange exchange = captureExchange();
    assertThat(exchange.getMetadataMimeType().toString()).isEqualTo(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());
    assertThat(exchange.getDataMimeType()).isEqualTo(MediaType.APPLICATION_JSON);
}
Also used : PayloadExchange(org.springframework.security.rsocket.api.PayloadExchange) Test(org.junit.jupiter.api.Test)

Aggregations

PayloadExchange (org.springframework.security.rsocket.api.PayloadExchange)11 Test (org.junit.jupiter.api.Test)9 RSocket (io.rsocket.RSocket)2 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)2 DefaultPayloadExchange (org.springframework.security.rsocket.core.DefaultPayloadExchange)2 SocketAcceptor (io.rsocket.SocketAcceptor)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 PayloadInterceptorChain (org.springframework.security.rsocket.api.PayloadInterceptorChain)1