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);
}
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();
}
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();
}
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);
}
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);
}
Aggregations