Add principal name to oauth2Client Test Support
Fixes gh-8054
This commit is contained in:
@@ -134,6 +134,16 @@ public class SecurityMockServerConfigurersOAuth2ClientTests extends AbstractMock
|
||||
assertThat(client.getRefreshToken()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oauth2ClientWhenPrincipalNameThenUses() throws Exception {
|
||||
this.client.mutateWith(mockOAuth2Client("registration-id")
|
||||
.principalName("test-subject"))
|
||||
.get().uri("/client")
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody(String.class).isEqualTo("test-subject");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oauth2ClientWhenAccessTokenThenUses()
|
||||
throws Exception {
|
||||
|
||||
@@ -123,6 +123,13 @@ public class SecurityMockMvcRequestPostProcessorsOAuth2ClientTests {
|
||||
.andExpect(content().string("client-id"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oauth2ClientWhenPrincipalNameThenUses() throws Exception {
|
||||
this.mvc.perform(get("/principal-name")
|
||||
.with(oauth2Client("registration-id").principalName("test-subject")))
|
||||
.andExpect(content().string("test-subject"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oauth2ClientWhenAccessTokenThenUses() throws Exception {
|
||||
OAuth2AccessToken accessToken = noScopes();
|
||||
@@ -161,6 +168,11 @@ public class SecurityMockMvcRequestPostProcessorsOAuth2ClientTests {
|
||||
return authorizedClient.getAccessToken().getTokenValue();
|
||||
}
|
||||
|
||||
@GetMapping("/principal-name")
|
||||
String principalName(@RegisteredOAuth2AuthorizedClient("registration-id") OAuth2AuthorizedClient authorizedClient) {
|
||||
return authorizedClient.getPrincipalName();
|
||||
}
|
||||
|
||||
@GetMapping("/client-id")
|
||||
String clientId(@RegisteredOAuth2AuthorizedClient("registration-id") OAuth2AuthorizedClient authorizedClient) {
|
||||
return authorizedClient.getClientRegistration().getClientId();
|
||||
|
||||
Reference in New Issue
Block a user