Skip to content

Commit 3b7d9f3

Browse files
mindhaqrwinch
authored andcommitted
#3299: adjust test so that it fails when username contains a special character
1 parent 40a8f55 commit 3b7d9f3

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
spring.security.user.name=rüdiger
12
spring.security.user.password=password
23
spring.session.jdbc.schema=classpath:schema.sql
34
spring.session.jdbc.initialize-schema=always

spring-session-samples/spring-session-sample-boot-jdbc-json-attribute/src/test/java/sample/JdbcJsonAttributeTests.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void setup() {
5151

5252
@Test
5353
void loginShouldSaveSecurityContextAsJson() throws Exception {
54-
Cookie sessionCookie = this.mvc.perform(formLogin().user("user").password("password"))
54+
Cookie sessionCookie = this.mvc.perform(formLogin().user("rüdiger").password("password"))
5555
.andExpect(authenticated())
5656
.andReturn()
5757
.getResponse()
@@ -66,20 +66,20 @@ void loginShouldSaveSecurityContextAsJson() throws Exception {
6666
SecurityContext securityContext = this.objectMapperWithModules.readValue((String) attributeBytes,
6767
SecurityContext.class);
6868
assertThat(securityContext).isNotNull();
69-
assertThat(securityContext.getAuthentication().getName()).isEqualTo("user");
69+
assertThat(securityContext.getAuthentication().getName()).isEqualTo("rüdiger");
7070
}
7171

7272
@Test
7373
void loginWhenQueryUsingJsonbOperatorThenReturns() throws Exception {
74-
this.mvc.perform(formLogin().user("user").password("password")).andExpect(authenticated());
74+
this.mvc.perform(formLogin().user("rüdiger").password("password")).andExpect(authenticated());
7575
Object attributeBytes = this.jdbcClient.sql("""
7676
SELECT attribute_bytes::text FROM spring_session_attributes
77-
WHERE attribute_bytes -> 'authentication' -> 'principal' ->> 'username' = 'user'
77+
WHERE attribute_bytes -> 'authentication' -> 'principal' ->> 'username' = 'rüdiger'
7878
""").query().singleValue();
7979
SecurityContext securityContext = this.objectMapperWithModules.readValue((String) attributeBytes,
8080
SecurityContext.class);
8181
assertThat(securityContext).isNotNull();
82-
assertThat(securityContext.getAuthentication().getName()).isEqualTo("user");
82+
assertThat(securityContext.getAuthentication().getName()).isEqualTo("rüdiger");
8383
}
8484

8585
}

0 commit comments

Comments
 (0)