use preexisiting scope by default but prevent overriding of builder scope and update unit tests

This commit is contained in:
Konstantin Schaper
2020-11-04 09:38:29 +01:00
parent 36b6b221a4
commit b5f042ad15
2 changed files with 14 additions and 6 deletions

View File

@@ -146,13 +146,19 @@ class JwtAccessTokenBuilderTest {
}
@Test
void testSimpleRequest() {
void shouldCreateJwtAndUsePreviousScope() {
JwtAccessTokenBuilder builder = factory.create().subject("dent");
final JwtAccessToken accessToken = builder.build();
assertThat(accessToken).isNotNull();
assertThat(accessToken.getSubject()).isEqualTo("dent");
assertThat((Collection<String>) accessToken.getCustom("scope").get()).containsExactly("dummy:scope:*");
}
@Test
void shouldThrowExceptionWhenScopeAlreadyDefinedInBuilder() {
JwtAccessTokenBuilder builder = factory.create().scope(Scope.valueOf("an:incompatible:scope")).subject("dent");
assertThrows(AuthorizationException.class, builder::build);
}
}
@Nested