Skip to content

Commit a9ab5dd

Browse files
committed
Cookie name prefix __Host- is added only when https is used
WE2-967 Signed-off-by: Sven Mitt <svenzik@users.noreply.github.com>
1 parent 65281cf commit a9ab5dd

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
spring.profiles.active=dev
2-
server.servlet.session.cookie.name=__Host-JSESSIONID
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package eu.webeid.example.config;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import jakarta.servlet.ServletContext;
6+
import jakarta.servlet.SessionCookieConfig;
7+
import org.junit.jupiter.api.Test;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
11+
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
12+
import org.springframework.test.context.TestPropertySource;
13+
14+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
15+
@TestPropertySource(properties = {"web-eid-auth-token.validation.local-origin=http://localhost"})
16+
class CookieHttpTest {
17+
18+
@Autowired
19+
private ServletWebServerApplicationContext context;
20+
21+
@Test
22+
void whenLocalOriginStartsWithHttp_thenCookeDoesNotHaveHostPrefix() {
23+
ServletContext servletContext = context.getServletContext();
24+
SessionCookieConfig cookieConfig = servletContext.getSessionCookieConfig();
25+
assertThat(cookieConfig.getName()).isEqualTo("JSESSIONID");
26+
}
27+
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package eu.webeid.example.config;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import jakarta.servlet.ServletContext;
6+
import jakarta.servlet.SessionCookieConfig;
7+
import org.junit.jupiter.api.Test;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
11+
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
12+
import org.springframework.test.context.TestPropertySource;
13+
14+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
15+
@TestPropertySource(properties = {"web-eid-auth-token.validation.local-origin=https://localhost"})
16+
class CookieHttpsTest {
17+
18+
@Autowired
19+
private ServletWebServerApplicationContext context;
20+
21+
@Test
22+
void whenLocalOriginStartsWithHttp_thenCookeDoesNotHaveHostPrefix() {
23+
ServletContext servletContext = context.getServletContext();
24+
SessionCookieConfig cookieConfig = servletContext.getSessionCookieConfig();
25+
assertThat(cookieConfig.getName()).isEqualTo("__Host-JSESSIONID");
26+
}
27+
28+
}

0 commit comments

Comments
 (0)