use of io.vertx.reactivex.ext.auth.User in project gravitee-access-management by gravitee-io.
the class AuthorizationEndpointTest method shouldNotInvokeAuthorizationEndpoint_noUser_code_challenge_valid_s256.
@Test
public void shouldNotInvokeAuthorizationEndpoint_noUser_code_challenge_valid_s256() throws Exception {
final Client client = new Client();
client.setId("client-id");
client.setClientId("client-id");
client.setRedirectUris(Collections.singletonList("http://localhost:9999/callback"));
AuthorizationRequest authorizationRequest = new AuthorizationRequest();
authorizationRequest.setApproved(true);
authorizationRequest.setResponseType(ResponseType.CODE);
authorizationRequest.setRedirectUri("http://localhost:9999/callback");
AuthorizationResponse authorizationResponse = new AuthorizationCodeResponse();
authorizationResponse.setRedirectUri(authorizationRequest.getRedirectUri());
((AuthorizationCodeResponse) authorizationResponse).setCode("test-code");
router.route().order(-1).handler(new Handler<RoutingContext>() {
@Override
public void handle(RoutingContext routingContext) {
routingContext.setUser(new User(new io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User(new io.gravitee.am.model.User())));
routingContext.next();
}
});
when(clientSyncService.findByClientId("client-id")).thenReturn(Maybe.just(client));
when(flow.run(any(), any(), any())).thenReturn(Single.just(authorizationResponse));
testRequest(HttpMethod.GET, "/oauth/authorize?response_type=code&client_id=client-id&redirect_uri=http://localhost:9999/callback&code_challenge_method=S256&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM", null, resp -> {
String location = resp.headers().get("location");
assertNotNull(location);
assertEquals("http://localhost:9999/callback?code=test-code", location);
}, HttpStatusCode.FOUND_302, "Found", null);
}
use of io.vertx.reactivex.ext.auth.User in project gravitee-access-management by gravitee-io.
the class AuthorizationEndpointTest method shouldNotInvokeAuthorizationEndpoint_invalidScope.
@Test
public void shouldNotInvokeAuthorizationEndpoint_invalidScope() throws Exception {
final Client client = new Client();
client.setId("client-id");
client.setClientId("client-id");
client.setScopeSettings(Collections.singletonList(new ApplicationScopeSettings("read")));
client.setRedirectUris(Collections.singletonList("http://localhost:9999/callback"));
router.route().order(-1).handler(routingContext -> {
routingContext.setUser(new User(new io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User(new io.gravitee.am.model.User())));
routingContext.next();
});
when(clientSyncService.findByClientId("client-id")).thenReturn(Maybe.just(client));
testRequest(HttpMethod.GET, "/oauth/authorize?response_type=code&client_id=client-id&redirect_uri=http://localhost:9999/callback&scope=unknown", null, resp -> {
String location = resp.headers().get("location");
assertNotNull(location);
assertEquals("http://localhost:9999/callback?error=invalid_scope&error_description=Invalid+scope%2528s%2529%253A+unknown", location);
}, HttpStatusCode.FOUND_302, "Found", null);
}
use of io.vertx.reactivex.ext.auth.User in project gravitee-access-management by gravitee-io.
the class AuthorizationEndpointTest method shouldInvokeAuthorizationEndpoint_prompt_login_consent_step.
@Test
public void shouldInvokeAuthorizationEndpoint_prompt_login_consent_step() throws Exception {
final Client client = new Client();
client.setId("client-id");
client.setClientId("client-id");
client.setScopeSettings(Collections.singletonList(new ApplicationScopeSettings("read")));
client.setRedirectUris(Collections.singletonList("http://localhost:9999/callback"));
AuthorizationRequest authorizationRequest = new AuthorizationRequest();
authorizationRequest.setApproved(true);
authorizationRequest.setResponseType(ResponseType.CODE);
authorizationRequest.setRedirectUri("http://localhost:9999/callback");
AuthorizationResponse authorizationResponse = new AuthorizationCodeResponse();
authorizationResponse.setRedirectUri(authorizationRequest.getRedirectUri());
((AuthorizationCodeResponse) authorizationResponse).setCode("test-code");
router.route().order(-1).handler(routingContext -> {
routingContext.session().put(ConstantKeys.USER_LOGIN_COMPLETED_KEY, true);
routingContext.setUser(new User(new io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User(new io.gravitee.am.model.User())));
routingContext.next();
});
when(clientSyncService.findByClientId("client-id")).thenReturn(Maybe.just(client));
when(flow.run(any(), any(), any())).thenReturn(Single.just(authorizationResponse));
testRequest(HttpMethod.GET, "/oauth/authorize?response_type=code&client_id=client-id&redirect_uri=http://localhost:9999/callback&prompt=login", null, resp -> {
String location = resp.headers().get("location");
assertNotNull(location);
assertEquals("http://localhost:9999/callback?code=test-code", location);
}, HttpStatusCode.FOUND_302, "Found", null);
}
use of io.vertx.reactivex.ext.auth.User in project gravitee-access-management by gravitee-io.
the class AuthorizationEndpointTest method shouldNotInvokeAuthorizationEndpoint_forcePKCE_noCodeChallenge.
@Test
public void shouldNotInvokeAuthorizationEndpoint_forcePKCE_noCodeChallenge() throws Exception {
final Client client = new Client();
client.setId("client-id");
client.setClientId("client-id");
client.setRedirectUris(Collections.singletonList("http://localhost:9999/callback"));
client.setForcePKCE(true);
router.route().order(-1).handler(routingContext -> {
routingContext.setUser(new User(new io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User(new io.gravitee.am.model.User())));
routingContext.next();
});
when(clientSyncService.findByClientId("client-id")).thenReturn(Maybe.just(client));
testRequest(HttpMethod.GET, "/oauth/authorize?response_type=code&client_id=client-id&redirect_uri=http://localhost:9999/callback", null, resp -> {
String location = resp.headers().get("location");
assertNotNull(location);
assertEquals("http://localhost:9999/callback?error=invalid_request&error_description=Missing+parameter%253A+code_challenge", location);
}, HttpStatusCode.FOUND_302, "Found", null);
}
use of io.vertx.reactivex.ext.auth.User in project gravitee-access-management by gravitee-io.
the class AuthorizationEndpointTest method shouldInvokeAuthorizationEndpoint_prompt_login_social_auth_step.
@Test
public void shouldInvokeAuthorizationEndpoint_prompt_login_social_auth_step() throws Exception {
final Client client = new Client();
client.setId("client-id");
client.setClientId("client-id");
client.setScopeSettings(Collections.singletonList(new ApplicationScopeSettings("read")));
client.setRedirectUris(Collections.singletonList("http://localhost:9999/callback"));
AuthorizationRequest authorizationRequest = new AuthorizationRequest();
authorizationRequest.setApproved(true);
authorizationRequest.setResponseType(ResponseType.CODE);
authorizationRequest.setRedirectUri("http://localhost:9999/callback");
AuthorizationResponse authorizationResponse = new AuthorizationCodeResponse();
authorizationResponse.setRedirectUri(authorizationRequest.getRedirectUri());
((AuthorizationCodeResponse) authorizationResponse).setCode("test-code");
router.route().order(-1).handler(routingContext -> {
routingContext.session().put(ConstantKeys.USER_LOGIN_COMPLETED_KEY, true);
routingContext.setUser(new User(new io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User(new io.gravitee.am.model.User())));
routingContext.next();
});
when(clientSyncService.findByClientId("client-id")).thenReturn(Maybe.just(client));
when(flow.run(any(), any(), any())).thenReturn(Single.just(authorizationResponse));
testRequest(HttpMethod.GET, "/oauth/authorize?response_type=code&client_id=client-id&redirect_uri=http://localhost:9999/callback&prompt=login", null, resp -> {
String location = resp.headers().get("location");
assertNotNull(location);
assertEquals("http://localhost:9999/callback?code=test-code", location);
}, HttpStatusCode.FOUND_302, "Found", null);
}
Aggregations