use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class ReactiveCloudFoundrySecurityInterceptorTests method preHandleSuccessfulWithFullAccess.
@Test
void preHandleSuccessfulWithFullAccess() {
String accessToken = mockAccessToken();
given(this.securityService.getAccessLevel(accessToken, "my-app-id")).willReturn(Mono.just(AccessLevel.FULL));
given(this.tokenValidator.validate(any())).willReturn(Mono.empty());
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/a").header(HttpHeaders.AUTHORIZATION, "bearer " + mockAccessToken()).build());
StepVerifier.create(this.interceptor.preHandle(exchange, "/a")).consumeNextWith((response) -> {
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK);
assertThat((AccessLevel) exchange.getAttribute("cloudFoundryAccessLevel")).isEqualTo(AccessLevel.FULL);
}).verifyComplete();
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class ReactiveCloudFoundrySecurityInterceptorTests method preHandleWhenTokenIsMissingShouldReturnMissingAuthorization.
@Test
void preHandleWhenTokenIsMissingShouldReturnMissingAuthorization() {
MockServerWebExchange request = MockServerWebExchange.from(MockServerHttpRequest.get("/a").build());
StepVerifier.create(this.interceptor.preHandle(request, "/a")).consumeNextWith((response) -> assertThat(response.getStatus()).isEqualTo(Reason.MISSING_AUTHORIZATION.getStatus())).verifyComplete();
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class ReactiveCloudFoundrySecurityInterceptorTests method preHandleWhenApplicationIdIsNullShouldReturnError.
@Test
void preHandleWhenApplicationIdIsNullShouldReturnError() {
this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, this.securityService, null);
MockServerWebExchange request = MockServerWebExchange.from(MockServerHttpRequest.get("/a").header(HttpHeaders.AUTHORIZATION, "bearer " + mockAccessToken()).build());
StepVerifier.create(this.interceptor.preHandle(request, "/a")).consumeErrorWith((ex) -> assertThat(((CloudFoundryAuthorizationException) ex).getReason()).isEqualTo(Reason.SERVICE_UNAVAILABLE)).verify();
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class ReactiveCloudFoundrySecurityInterceptorTests method preHandleWhenRequestIsPreFlightShouldBeOk.
@Test
void preHandleWhenRequestIsPreFlightShouldBeOk() {
MockServerWebExchange request = MockServerWebExchange.from(MockServerHttpRequest.options("/a").header(HttpHeaders.ORIGIN, "https://example.com").header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET").build());
StepVerifier.create(this.interceptor.preHandle(request, "/a")).consumeNextWith((response) -> assertThat(response.getStatus()).isEqualTo(HttpStatus.OK)).verifyComplete();
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class WebFluxAutoConfigurationTests method whenAcceptHeaderLocaleContextResolverIsUsedThenAcceptLanguagesHeaderIsHonoured.
@Test
void whenAcceptHeaderLocaleContextResolverIsUsedThenAcceptLanguagesHeaderIsHonoured() {
this.contextRunner.withPropertyValues("spring.web.locale:en_UK").run((context) -> {
MockServerHttpRequest request = MockServerHttpRequest.get("/").acceptLanguageAsLocales(StringUtils.parseLocaleString("nl_NL")).build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
LocaleContextResolver localeContextResolver = context.getBean(LocaleContextResolver.class);
assertThat(localeContextResolver).isInstanceOf(AcceptHeaderLocaleContextResolver.class);
LocaleContext localeContext = localeContextResolver.resolveLocaleContext(exchange);
assertThat(localeContext.getLocale()).isEqualTo(StringUtils.parseLocaleString("nl_NL"));
});
}
Aggregations