|
| 1 | +/* |
| 2 | + * Copyright 2002-2018 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.security.web.server.authentication; |
| 18 | + |
| 19 | +import static org.assertj.core.api.Assertions.*; |
| 20 | + |
| 21 | +import org.junit.Before; |
| 22 | +import org.junit.Test; |
| 23 | + |
| 24 | +import org.springframework.http.HttpStatus; |
| 25 | +import org.springframework.mock.http.server.reactive.MockServerHttpRequest; |
| 26 | +import org.springframework.mock.web.server.MockServerWebExchange; |
| 27 | +import org.springframework.security.core.AuthenticationException; |
| 28 | + |
| 29 | +/** |
| 30 | + * @author Eric Deandrea |
| 31 | + * @since 5.1 |
| 32 | + */ |
| 33 | +public class HttpStatusServerEntryPointTests { |
| 34 | + private MockServerHttpRequest request; |
| 35 | + private MockServerWebExchange exchange; |
| 36 | + private AuthenticationException authException; |
| 37 | + private HttpStatusServerEntryPoint entryPoint; |
| 38 | + |
| 39 | + @Before |
| 40 | + public void setup() { |
| 41 | + this.request = MockServerHttpRequest.get("/").build(); |
| 42 | + this.exchange = MockServerWebExchange.from(this.request); |
| 43 | + this.authException = new AuthenticationException("") { }; |
| 44 | + this.entryPoint = new HttpStatusServerEntryPoint(HttpStatus.UNAUTHORIZED); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void constructorNullStatus() { |
| 49 | + assertThatExceptionOfType(IllegalArgumentException.class) |
| 50 | + .isThrownBy(() -> new HttpStatusServerEntryPoint(null)) |
| 51 | + .withMessage("httpStatus cannot be null"); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void unauthorized() { |
| 56 | + this.entryPoint.commence(this.exchange, this.authException).block(); |
| 57 | + assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); |
| 58 | + } |
| 59 | +} |
0 commit comments