|
|
|
@ -47,6 +47,7 @@ public class WithMockUserSecurityContextFactoryTests { |
|
|
|
when(withUser.value()).thenReturn("valueUser"); |
|
|
|
when(withUser.value()).thenReturn("valueUser"); |
|
|
|
when(withUser.password()).thenReturn("password"); |
|
|
|
when(withUser.password()).thenReturn("password"); |
|
|
|
when(withUser.roles()).thenReturn(new String[] { "USER" }); |
|
|
|
when(withUser.roles()).thenReturn(new String[] { "USER" }); |
|
|
|
|
|
|
|
when(withUser.authorities()).thenReturn(new String[] {}); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(factory.createSecurityContext(withUser).getAuthentication().getName()) |
|
|
|
assertThat(factory.createSecurityContext(withUser).getAuthentication().getName()) |
|
|
|
.isEqualTo(withUser.value()); |
|
|
|
.isEqualTo(withUser.value()); |
|
|
|
@ -58,6 +59,7 @@ public class WithMockUserSecurityContextFactoryTests { |
|
|
|
when(withUser.username()).thenReturn("customUser"); |
|
|
|
when(withUser.username()).thenReturn("customUser"); |
|
|
|
when(withUser.password()).thenReturn("password"); |
|
|
|
when(withUser.password()).thenReturn("password"); |
|
|
|
when(withUser.roles()).thenReturn(new String[] { "USER" }); |
|
|
|
when(withUser.roles()).thenReturn(new String[] { "USER" }); |
|
|
|
|
|
|
|
when(withUser.authorities()).thenReturn(new String[] {}); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(factory.createSecurityContext(withUser).getAuthentication().getName()) |
|
|
|
assertThat(factory.createSecurityContext(withUser).getAuthentication().getName()) |
|
|
|
.isEqualTo(withUser.username()); |
|
|
|
.isEqualTo(withUser.username()); |
|
|
|
@ -68,6 +70,7 @@ public class WithMockUserSecurityContextFactoryTests { |
|
|
|
when(withUser.value()).thenReturn("valueUser"); |
|
|
|
when(withUser.value()).thenReturn("valueUser"); |
|
|
|
when(withUser.password()).thenReturn("password"); |
|
|
|
when(withUser.password()).thenReturn("password"); |
|
|
|
when(withUser.roles()).thenReturn(new String[] { "USER", "CUSTOM" }); |
|
|
|
when(withUser.roles()).thenReturn(new String[] { "USER", "CUSTOM" }); |
|
|
|
|
|
|
|
when(withUser.authorities()).thenReturn(new String[] {}); |
|
|
|
|
|
|
|
|
|
|
|
assertThat( |
|
|
|
assertThat( |
|
|
|
factory.createSecurityContext(withUser).getAuthentication() |
|
|
|
factory.createSecurityContext(withUser).getAuthentication() |
|
|
|
@ -75,11 +78,35 @@ public class WithMockUserSecurityContextFactoryTests { |
|
|
|
"ROLE_USER", "ROLE_CUSTOM"); |
|
|
|
"ROLE_USER", "ROLE_CUSTOM"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void authoritiesWorks() { |
|
|
|
|
|
|
|
when(withUser.value()).thenReturn("valueUser"); |
|
|
|
|
|
|
|
when(withUser.password()).thenReturn("password"); |
|
|
|
|
|
|
|
when(withUser.roles()).thenReturn(new String[] { "USER" }); |
|
|
|
|
|
|
|
when(withUser.authorities()).thenReturn(new String[] { "USER", "CUSTOM" }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat( |
|
|
|
|
|
|
|
factory.createSecurityContext(withUser).getAuthentication() |
|
|
|
|
|
|
|
.getAuthorities()).onProperty("authority").containsOnly( |
|
|
|
|
|
|
|
"USER", "CUSTOM"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class) |
|
|
|
|
|
|
|
public void authoritiesAndRolesInvalid() { |
|
|
|
|
|
|
|
when(withUser.value()).thenReturn("valueUser"); |
|
|
|
|
|
|
|
when(withUser.password()).thenReturn("password"); |
|
|
|
|
|
|
|
when(withUser.roles()).thenReturn(new String[] { "CUSTOM" }); |
|
|
|
|
|
|
|
when(withUser.authorities()).thenReturn(new String[] { "USER", "CUSTOM" }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
factory.createSecurityContext(withUser); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = IllegalArgumentException.class) |
|
|
|
@Test(expected = IllegalArgumentException.class) |
|
|
|
public void rolesWithRolePrefixFails() { |
|
|
|
public void rolesWithRolePrefixFails() { |
|
|
|
when(withUser.value()).thenReturn("valueUser"); |
|
|
|
when(withUser.value()).thenReturn("valueUser"); |
|
|
|
when(withUser.password()).thenReturn("password"); |
|
|
|
when(withUser.password()).thenReturn("password"); |
|
|
|
when(withUser.roles()).thenReturn(new String[] { "ROLE_FAIL" }); |
|
|
|
when(withUser.roles()).thenReturn(new String[] { "ROLE_FAIL" }); |
|
|
|
|
|
|
|
when(withUser.authorities()).thenReturn(new String[] {}); |
|
|
|
|
|
|
|
|
|
|
|
factory.createSecurityContext(withUser); |
|
|
|
factory.createSecurityContext(withUser); |
|
|
|
} |
|
|
|
} |
|
|
|
|