Add principal name to oauth2Client Test Support

Fixes gh-8054
This commit is contained in:
Josh Cummings
2020-03-02 21:12:31 -07:00
parent 3bc1b7a933
commit 2064214f39
4 changed files with 52 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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();