|
| 1 | +/* |
| 2 | + * Copyright 2002-2017 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 | +package org.springframework.web.server.session; |
| 17 | + |
| 18 | +import org.junit.Test; |
| 19 | + |
| 20 | +import org.springframework.http.ResponseCookie; |
| 21 | +import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; |
| 22 | +import org.springframework.mock.web.test.server.MockServerWebExchange; |
| 23 | +import org.springframework.util.MultiValueMap; |
| 24 | + |
| 25 | +import static org.junit.Assert.assertEquals; |
| 26 | +import static org.junit.Assert.assertNotNull; |
| 27 | + |
| 28 | +/** |
| 29 | + * Unit tests for {@link CookieWebSessionIdResolver}. |
| 30 | + * @author Rossen Stoyanchev |
| 31 | + */ |
| 32 | +public class CookieWebSessionIdResolverTests { |
| 33 | + |
| 34 | + private final CookieWebSessionIdResolver resolver = new CookieWebSessionIdResolver(); |
| 35 | + |
| 36 | + |
| 37 | + @Test |
| 38 | + public void setSessionId() throws Exception { |
| 39 | + MockServerHttpRequest request = MockServerHttpRequest.get("https://example.org/path").build(); |
| 40 | + MockServerWebExchange exchange = MockServerWebExchange.from(request); |
| 41 | + this.resolver.setSessionId(exchange, "123"); |
| 42 | + |
| 43 | + MultiValueMap<String, ResponseCookie> cookies = exchange.getResponse().getCookies(); |
| 44 | + assertEquals(1, cookies.size()); |
| 45 | + ResponseCookie cookie = cookies.getFirst(this.resolver.getCookieName()); |
| 46 | + assertNotNull(cookie); |
| 47 | + assertEquals("SESSION=123; Path=/; Secure; HttpOnly", cookie.toString()); |
| 48 | + } |
| 49 | +} |
0 commit comments