parent
a3227f041c
commit
c7ea8c6ac7
|
@ -37,16 +37,16 @@ public class OAuth2AuthorizationManagersTests {
|
||||||
void hasScopeWhenInvalidScopeThenThrowIllegalArgument() {
|
void hasScopeWhenInvalidScopeThenThrowIllegalArgument() {
|
||||||
String scope = "SCOPE_invalid";
|
String scope = "SCOPE_invalid";
|
||||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||||
.isThrownBy(() -> OAuth2AuthorizationManagers.hasScope(scope))
|
.isThrownBy(() -> OAuth2AuthorizationManagers.hasScope(scope))
|
||||||
.withMessageContaining("SCOPE_invalid should not start with SCOPE_");
|
.withMessageContaining("SCOPE_invalid should not start with SCOPE_");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void hasAnyScopeWhenInvalidScopeThenThrowIllegalArgument() {
|
void hasAnyScopeWhenInvalidScopeThenThrowIllegalArgument() {
|
||||||
String[] scopes = { "read", "write", "SCOPE_invalid" };
|
String[] scopes = { "read", "write", "SCOPE_invalid" };
|
||||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||||
.isThrownBy(() -> OAuth2AuthorizationManagers.hasAnyScope(scopes))
|
.isThrownBy(() -> OAuth2AuthorizationManagers.hasAnyScope(scopes))
|
||||||
.withMessageContaining("SCOPE_invalid should not start with SCOPE_");
|
.withMessageContaining("SCOPE_invalid should not start with SCOPE_");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -55,7 +55,7 @@ public class OAuth2AuthorizationManagersTests {
|
||||||
AuthorizationManager<Object> authorizationManager = OAuth2AuthorizationManagers.hasScope(scope);
|
AuthorizationManager<Object> authorizationManager = OAuth2AuthorizationManagers.hasScope(scope);
|
||||||
authorizationManager.verify(() -> hasScope(scope), new Object());
|
authorizationManager.verify(() -> hasScope(scope), new Object());
|
||||||
assertThatExceptionOfType(AccessDeniedException.class)
|
assertThatExceptionOfType(AccessDeniedException.class)
|
||||||
.isThrownBy(() -> authorizationManager.verify(() -> hasScope("wrong"), new Object()));
|
.isThrownBy(() -> authorizationManager.verify(() -> hasScope("wrong"), new Object()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -66,7 +66,7 @@ public class OAuth2AuthorizationManagersTests {
|
||||||
authorizationManager.verify(() -> hasScope(scope), new Object());
|
authorizationManager.verify(() -> hasScope(scope), new Object());
|
||||||
}
|
}
|
||||||
assertThatExceptionOfType(AccessDeniedException.class)
|
assertThatExceptionOfType(AccessDeniedException.class)
|
||||||
.isThrownBy(() -> authorizationManager.verify(() -> hasScope("wrong"), new Object()));
|
.isThrownBy(() -> authorizationManager.verify(() -> hasScope("wrong"), new Object()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Authentication hasScope(String scope) {
|
Authentication hasScope(String scope) {
|
||||||
|
|
|
@ -37,16 +37,16 @@ public class OAuth2ReactiveAuthorizationManagersTests {
|
||||||
void hasScopeWhenInvalidScopeThenThrowIllegalArgument() {
|
void hasScopeWhenInvalidScopeThenThrowIllegalArgument() {
|
||||||
String scope = "SCOPE_invalid";
|
String scope = "SCOPE_invalid";
|
||||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||||
.isThrownBy(() -> OAuth2ReactiveAuthorizationManagers.hasScope(scope))
|
.isThrownBy(() -> OAuth2ReactiveAuthorizationManagers.hasScope(scope))
|
||||||
.withMessageContaining("SCOPE_invalid should not start with SCOPE_");
|
.withMessageContaining("SCOPE_invalid should not start with SCOPE_");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void hasAnyScopeWhenInvalidScopeThenThrowIllegalArgument() {
|
void hasAnyScopeWhenInvalidScopeThenThrowIllegalArgument() {
|
||||||
String[] scopes = { "read", "write", "SCOPE_invalid" };
|
String[] scopes = { "read", "write", "SCOPE_invalid" };
|
||||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||||
.isThrownBy(() -> OAuth2ReactiveAuthorizationManagers.hasAnyScope(scopes))
|
.isThrownBy(() -> OAuth2ReactiveAuthorizationManagers.hasAnyScope(scopes))
|
||||||
.withMessageContaining("SCOPE_invalid should not start with SCOPE_");
|
.withMessageContaining("SCOPE_invalid should not start with SCOPE_");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -55,19 +55,19 @@ public class OAuth2ReactiveAuthorizationManagersTests {
|
||||||
ReactiveAuthorizationManager<Object> authorizationManager = OAuth2ReactiveAuthorizationManagers.hasScope(scope);
|
ReactiveAuthorizationManager<Object> authorizationManager = OAuth2ReactiveAuthorizationManagers.hasScope(scope);
|
||||||
authorizationManager.verify(hasScope(scope), new Object()).block();
|
authorizationManager.verify(hasScope(scope), new Object()).block();
|
||||||
assertThatExceptionOfType(AccessDeniedException.class)
|
assertThatExceptionOfType(AccessDeniedException.class)
|
||||||
.isThrownBy(() -> authorizationManager.verify(hasScope("wrong"), new Object()).block());
|
.isThrownBy(() -> authorizationManager.verify(hasScope("wrong"), new Object()).block());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void hasAnyScopeWhenValidScopesThenAuthorizationManager() {
|
void hasAnyScopeWhenValidScopesThenAuthorizationManager() {
|
||||||
String[] scopes = { "read", "write" };
|
String[] scopes = { "read", "write" };
|
||||||
ReactiveAuthorizationManager<Object> authorizationManager = OAuth2ReactiveAuthorizationManagers
|
ReactiveAuthorizationManager<Object> authorizationManager = OAuth2ReactiveAuthorizationManagers
|
||||||
.hasAnyScope(scopes);
|
.hasAnyScope(scopes);
|
||||||
for (String scope : scopes) {
|
for (String scope : scopes) {
|
||||||
authorizationManager.verify(hasScope(scope), new Object()).block();
|
authorizationManager.verify(hasScope(scope), new Object()).block();
|
||||||
}
|
}
|
||||||
assertThatExceptionOfType(AccessDeniedException.class)
|
assertThatExceptionOfType(AccessDeniedException.class)
|
||||||
.isThrownBy(() -> authorizationManager.verify(hasScope("wrong"), new Object()).block());
|
.isThrownBy(() -> authorizationManager.verify(hasScope("wrong"), new Object()).block());
|
||||||
}
|
}
|
||||||
|
|
||||||
Mono<Authentication> hasScope(String scope) {
|
Mono<Authentication> hasScope(String scope) {
|
||||||
|
|
Loading…
Reference in New Issue