Fix OAuth2 multitenancy sample

Allowing requests with valid tokens, and fixed documentation.

Fixes: gh-6834
This commit is contained in:
Eleftheria Stein
2019-05-02 16:21:10 -04:00
committed by Josh Cummings
parent 5aa50500cf
commit c4b6cdea3f
3 changed files with 86 additions and 12 deletions

View File

@@ -62,6 +62,15 @@ public class OAuth2ResourceServerApplicationITests {
.andExpect(content().string(containsString("Hello, subject for tenantOne!")));
}
@Test
public void tenantOnePerformWhenValidBearerTokenWithServletPathThenAllows()
throws Exception {
this.mvc.perform(get("/tenantOne").servletPath("/tenantOne").with(bearerToken(this.tenantOneNoScopesToken)))
.andExpect(status().isOk())
.andExpect(content().string(containsString("Hello, subject for tenantOne!")));
}
// -- tests with scopes
@Test
@@ -113,6 +122,13 @@ public class OAuth2ResourceServerApplicationITests {
containsString("Bearer error=\"insufficient_scope\"")));
}
@Test(expected = IllegalArgumentException.class)
public void invalidTenantPerformWhenValidBearerTokenThenThrowsException()
throws Exception {
this.mvc.perform(get("/tenantThree").with(bearerToken(this.tenantOneNoScopesToken)));
}
private static class BearerTokenRequestPostProcessor implements RequestPostProcessor {
private String token;