|
1 | 1 | package org.keycloak.tests.oauth; |
2 | 2 |
|
| 3 | +import java.util.Collections; |
3 | 4 | import java.util.List; |
4 | 5 |
|
5 | 6 | import org.keycloak.OAuth2Constants; |
|
11 | 12 | import org.keycloak.representations.AccessToken; |
12 | 13 | import org.keycloak.representations.IDToken; |
13 | 14 | import org.keycloak.representations.JsonWebToken; |
| 15 | +import org.keycloak.representations.idm.UserRepresentation; |
14 | 16 | import org.keycloak.testframework.events.EventAssertion; |
15 | 17 | import org.keycloak.testframework.oauth.OAuthIdentityProvider; |
16 | 18 | import org.keycloak.testsuite.util.oauth.AccessTokenResponse; |
@@ -309,4 +311,33 @@ public void testDisabledIdentityProvider() { |
309 | 311 | AccessTokenResponse response = oAuthClient.jwtAuthorizationGrantRequest(jwt).send(); |
310 | 312 | assertFailure("Identity Provider is not enabled", response, events.poll()); |
311 | 313 | } |
| 314 | + |
| 315 | + @Test |
| 316 | + public void testUserDisabled() { |
| 317 | + UserRepresentation userRep = user.admin().toRepresentation(); |
| 318 | + userRep.setEnabled(false); |
| 319 | + user.admin().update(userRep); |
| 320 | + |
| 321 | + String jwt = getIdentityProvider().encodeToken(createDefaultAuthorizationGrantToken()); |
| 322 | + AccessTokenResponse response = oAuthClient.jwtAuthorizationGrantRequest(jwt).send(); |
| 323 | + assertFailure("User is not enabled", response, events.poll()); |
| 324 | + |
| 325 | + userRep.setEnabled(true); |
| 326 | + user.admin().update(userRep); |
| 327 | + } |
| 328 | + |
| 329 | + @Test |
| 330 | + public void testUserWithRequiredAction() { |
| 331 | + UserRepresentation userRep = user.admin().toRepresentation(); |
| 332 | + userRep.setRequiredActions(Collections.singletonList("UPDATE_PASSWORD")); |
| 333 | + user.admin().update(userRep); |
| 334 | + |
| 335 | + String jwt = getIdentityProvider().encodeToken(createDefaultAuthorizationGrantToken()); |
| 336 | + AccessTokenResponse response = oAuthClient.jwtAuthorizationGrantRequest(jwt).send(); |
| 337 | + assertFailure("Account is not fully set up", response, events.poll()); |
| 338 | + |
| 339 | + userRep = user.admin().toRepresentation(); |
| 340 | + userRep.setRequiredActions(Collections.emptyList()); |
| 341 | + user.admin().update(userRep); |
| 342 | + } |
312 | 343 | } |
0 commit comments