Skip to content

Commit 6b09815

Browse files
buzzerrookieeleftherias
authored andcommitted
Add test for details deserialization
1 parent 156fc29 commit 6b09815

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

core/src/test/java/org/springframework/security/jackson2/UsernamePasswordAuthenticationTokenMixinTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixin
6464
+ "}";
6565
// @formatter:on
6666

67+
// @formatter:off
68+
private static final String AUTHENTICATED_STRINGDETAILS_JSON = AUTHENTICATED_JSON.replace("\"details\": null, ", "\"details\": \"details\", ");
69+
// @formatter:on
70+
6771
// @formatter:off
6872
private static final String AUTHENTICATED_NON_USER_PRINCIPAL_JSON = AUTHENTICATED_JSON
6973
.replace(UserDeserializerTests.USER_JSON, NON_USER_PRINCIPAL_JSON)
@@ -155,6 +159,18 @@ public void deserializeAuthenticatedUsernamePasswordAuthenticationTokenWithNonUs
155159
assertThat(token.getPrincipal()).isNotNull().isInstanceOf(NonUserPrincipal.class);
156160
}
157161

162+
@Test
163+
public void deserializeAuthenticatedUsernamePasswordAuthenticationTokenWithDetailsTest() throws IOException {
164+
UsernamePasswordAuthenticationToken token = mapper
165+
.readValue(AUTHENTICATED_STRINGDETAILS_JSON, UsernamePasswordAuthenticationToken.class);
166+
assertThat(token).isNotNull();
167+
assertThat(token.getPrincipal()).isNotNull().isInstanceOf(User.class);
168+
assertThat(((User) token.getPrincipal()).getAuthorities()).isNotNull().hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER"));
169+
assertThat(token.isAuthenticated()).isEqualTo(true);
170+
assertThat(token.getAuthorities()).hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER"));
171+
assertThat(token.getDetails()).isExactlyInstanceOf(String.class);
172+
}
173+
158174
@Test
159175
public void serializingThenDeserializingWithNoCredentialsOrDetailsShouldWork() throws IOException {
160176
// given

0 commit comments

Comments
 (0)