Search in sources :

Example 6 with SecurityResponse

use of org.springframework.boot.actuate.autoconfigure.cloudfoundry.SecurityResponse in project spring-boot by spring-projects.

the class CloudFoundrySecurityInterceptorTests method preHandleWhenRequestIsPreFlightShouldReturnTrue.

@Test
void preHandleWhenRequestIsPreFlightShouldReturnTrue() {
    this.request.setMethod("OPTIONS");
    this.request.addHeader(HttpHeaders.ORIGIN, "https://example.com");
    this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
    SecurityResponse response = this.interceptor.preHandle(this.request, EndpointId.of("test"));
    assertThat(response.getStatus()).isEqualTo(HttpStatus.OK);
}
Also used : SecurityResponse(org.springframework.boot.actuate.autoconfigure.cloudfoundry.SecurityResponse) Test(org.junit.jupiter.api.Test)

Example 7 with SecurityResponse

use of org.springframework.boot.actuate.autoconfigure.cloudfoundry.SecurityResponse in project spring-boot by spring-projects.

the class CloudFoundrySecurityInterceptorTests method preHandleWhenAccessIsNotAllowedShouldReturnFalse.

@Test
void preHandleWhenAccessIsNotAllowedShouldReturnFalse() {
    String accessToken = mockAccessToken();
    this.request.addHeader("Authorization", "bearer " + accessToken);
    given(this.securityService.getAccessLevel(accessToken, "my-app-id")).willReturn(AccessLevel.RESTRICTED);
    SecurityResponse response = this.interceptor.preHandle(this.request, EndpointId.of("test"));
    assertThat(response.getStatus()).isEqualTo(Reason.ACCESS_DENIED.getStatus());
}
Also used : SecurityResponse(org.springframework.boot.actuate.autoconfigure.cloudfoundry.SecurityResponse) Test(org.junit.jupiter.api.Test)

Example 8 with SecurityResponse

use of org.springframework.boot.actuate.autoconfigure.cloudfoundry.SecurityResponse in project spring-boot by spring-projects.

the class CloudFoundrySecurityInterceptorTests method preHandleWhenTokenIsNotBearerShouldReturnFalse.

@Test
void preHandleWhenTokenIsNotBearerShouldReturnFalse() {
    this.request.addHeader("Authorization", mockAccessToken());
    SecurityResponse response = this.interceptor.preHandle(this.request, EndpointId.of("test"));
    assertThat(response.getStatus()).isEqualTo(Reason.MISSING_AUTHORIZATION.getStatus());
}
Also used : SecurityResponse(org.springframework.boot.actuate.autoconfigure.cloudfoundry.SecurityResponse) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)8 SecurityResponse (org.springframework.boot.actuate.autoconfigure.cloudfoundry.SecurityResponse)8 Token (org.springframework.boot.actuate.autoconfigure.cloudfoundry.Token)2