Skip to content

Commit

Permalink
spring-projects#3299: adjust test so that it fails when username cont…
Browse files Browse the repository at this point in the history
…ains a special character
  • Loading branch information
mindhaq committed Jan 7, 2025
1 parent 3c5da80 commit f4cd1d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
spring.security.user.name=rüdiger
spring.security.user.password=password
spring.session.jdbc.schema=classpath:schema.sql
spring.session.jdbc.initialize-schema=always
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void setup() {

@Test
void loginShouldSaveSecurityContextAsJson() throws Exception {
Cookie sessionCookie = this.mvc.perform(formLogin().user("user").password("password"))
Cookie sessionCookie = this.mvc.perform(formLogin().user("rüdiger").password("password"))
.andExpect(authenticated())
.andReturn()
.getResponse()
Expand All @@ -62,20 +62,20 @@ void loginShouldSaveSecurityContextAsJson() throws Exception {
SecurityContext securityContext = this.objectMapperWithModules.readValue((String) attributeBytes,
SecurityContext.class);
assertThat(securityContext).isNotNull();
assertThat(securityContext.getAuthentication().getName()).isEqualTo("user");
assertThat(securityContext.getAuthentication().getName()).isEqualTo("rüdiger");
}

@Test
void loginWhenQueryUsingJsonbOperatorThenReturns() throws Exception {
this.mvc.perform(formLogin().user("user").password("password")).andExpect(authenticated());
this.mvc.perform(formLogin().user("rüdiger").password("password")).andExpect(authenticated());
Object attributeBytes = this.jdbcClient.queryForObject("""
SELECT attribute_bytes::text FROM spring_session_attributes
WHERE attribute_bytes -> 'authentication' -> 'principal' ->> 'username' = 'user'
WHERE attribute_bytes -> 'authentication' -> 'principal' ->> 'username' = 'rüdiger'
""", Object.class);
SecurityContext securityContext = this.objectMapperWithModules.readValue((String) attributeBytes,
SecurityContext.class);
assertThat(securityContext).isNotNull();
assertThat(securityContext.getAuthentication().getName()).isEqualTo("user");
assertThat(securityContext.getAuthentication().getName()).isEqualTo("rüdiger");
}

}

0 comments on commit f4cd1d0

Please sign in to comment.