Isolate Jwt Test Support

Isolating Jwt test support inside JwtRequestPostProcessor and
JwtMutator.

Fixes gh-7641
This commit is contained in:
Josh Cummings
2019-11-22 12:38:01 -07:00
parent 8a95e5798d
commit 7cbd1665a6
8 changed files with 107 additions and 136 deletions

View File

@@ -47,13 +47,13 @@ public class OAuth2ResourceServerControllerTests {
@Test
public void indexGreetsAuthenticatedUser() throws Exception {
mockMvc.perform(get("/").with(jwt(jwt -> jwt.subject("ch4mpy"))))
mockMvc.perform(get("/").with(jwt().jwt(jwt -> jwt.subject("ch4mpy"))))
.andExpect(content().string(is("Hello, ch4mpy!")));
}
@Test
public void messageCanBeReadWithScopeMessageReadAuthority() throws Exception {
mockMvc.perform(get("/message").with(jwt(jwt -> jwt.claim("scope", "message:read"))))
mockMvc.perform(get("/message").with(jwt().jwt(jwt -> jwt.claim("scope", "message:read"))))
.andExpect(content().string(is("secret message")));
mockMvc.perform(get("/message")
@@ -79,7 +79,7 @@ public class OAuth2ResourceServerControllerTests {
public void messageCanNotBeCreatedWithScopeMessageReadAuthority() throws Exception {
mockMvc.perform(post("/message")
.content("Hello message")
.with(jwt(jwt -> jwt.claim("scope", "message:read"))))
.with(jwt().jwt(jwt -> jwt.claim("scope", "message:read"))))
.andExpect(status().isForbidden());
}
@@ -88,7 +88,7 @@ public class OAuth2ResourceServerControllerTests {
throws Exception {
mockMvc.perform(post("/message")
.content("Hello message")
.with(jwt(jwt -> jwt.claim("scope", "message:write"))))
.with(jwt().jwt(jwt -> jwt.claim("scope", "message:write"))))
.andExpect(status().isOk())
.andExpect(content().string(is("Message was created. Content: Hello message")));
}