Search in sources :

Example 1 with PushedAuthorizationRequest

use of io.gravitee.am.repository.oauth2.model.PushedAuthorizationRequest in project gravitee-access-management by gravitee-io.

the class PushedAuthorizationRequestServiceTest method shouldPersist_ParametersWithoutRequest.

@Test
public void shouldPersist_ParametersWithoutRequest() {
    final Client client = createClient();
    final LinkedMultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    parameters.add("scope", "openid");
    parameters.add("response_type", "code");
    parameters.add("client_id", client.getClientId());
    final PushedAuthorizationRequest par = new PushedAuthorizationRequest();
    par.setParameters(parameters);
    par.setId("parid");
    par.setClient(client.getId());
    when(repository.create(any())).thenReturn(Single.just(par));
    final TestObserver<PushedAuthorizationRequestResponse> observer = cut.registerParameters(par, client).test();
    observer.awaitTerminalEvent();
    observer.assertNoErrors();
    observer.assertValue(parr -> parr.getExp() > 0 && parr.getRequestUri().equals(PushedAuthorizationRequestService.PAR_URN_PREFIX + par.getId()));
    verify(repository).create(any());
}
Also used : PushedAuthorizationRequest(io.gravitee.am.repository.oauth2.model.PushedAuthorizationRequest) LinkedMultiValueMap(io.gravitee.common.util.LinkedMultiValueMap) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Example 2 with PushedAuthorizationRequest

use of io.gravitee.am.repository.oauth2.model.PushedAuthorizationRequest in project gravitee-access-management by gravitee-io.

the class PushedAuthorizationRequestServiceTest method shouldReadFromURI_ExpiredPAR.

@Test
public void shouldReadFromURI_ExpiredPAR() {
    final String ID = "parid";
    final String requestUri = PushedAuthorizationRequestService.PAR_URN_PREFIX + ID;
    PushedAuthorizationRequest par = new PushedAuthorizationRequest();
    par.setExpireAt(new Date(Instant.now().minusSeconds(10).toEpochMilli()));
    when(repository.findById(ID)).thenReturn(Maybe.just(par));
    final TestObserver<JWT> testObserver = cut.readFromURI(requestUri, createClient(), new OpenIDProviderMetadata()).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertError(InvalidRequestUriException.class);
    verify(repository).findById(eq(ID));
}
Also used : PushedAuthorizationRequest(io.gravitee.am.repository.oauth2.model.PushedAuthorizationRequest) JWT(com.nimbusds.jwt.JWT) SignedJWT(com.nimbusds.jwt.SignedJWT) OpenIDProviderMetadata(io.gravitee.am.gateway.handler.oidc.service.discovery.OpenIDProviderMetadata) Date(java.util.Date) Test(org.junit.Test)

Example 3 with PushedAuthorizationRequest

use of io.gravitee.am.repository.oauth2.model.PushedAuthorizationRequest in project gravitee-access-management by gravitee-io.

the class PushedAuthorizationRequestServiceTest method shouldNotPersist_RequestUriPresent.

@Test
public void shouldNotPersist_RequestUriPresent() {
    final Client client = createClient();
    final LinkedMultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    parameters.add("request_uri", "urn:toto");
    parameters.add("client_id", client.getClientId());
    final PushedAuthorizationRequest par = new PushedAuthorizationRequest();
    par.setParameters(parameters);
    par.setId("parid");
    par.setClient(client.getId());
    final TestObserver<PushedAuthorizationRequestResponse> observer = cut.registerParameters(par, client).test();
    observer.awaitTerminalEvent();
    observer.assertFailure(InvalidRequestException.class);
    verify(repository, never()).create(any());
}
Also used : PushedAuthorizationRequest(io.gravitee.am.repository.oauth2.model.PushedAuthorizationRequest) LinkedMultiValueMap(io.gravitee.common.util.LinkedMultiValueMap) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Example 4 with PushedAuthorizationRequest

use of io.gravitee.am.repository.oauth2.model.PushedAuthorizationRequest in project gravitee-access-management by gravitee-io.

the class PushedAuthorizationRequestServiceTest method shouldNotPersist_RequestMalformed.

@Test
public void shouldNotPersist_RequestMalformed() {
    final Client client = createClient();
    final LinkedMultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    parameters.add("request", "invalid json object");
    parameters.add("client_id", client.getClientId());
    final PushedAuthorizationRequest par = new PushedAuthorizationRequest();
    par.setParameters(parameters);
    par.setId("parid");
    par.setClient(client.getId());
    when(jweService.decrypt(any(), anyBoolean())).thenReturn(Single.error(new ParseException("parse error", 1)));
    final TestObserver<PushedAuthorizationRequestResponse> observer = cut.registerParameters(par, client).test();
    observer.awaitTerminalEvent();
    observer.assertFailure(InvalidRequestObjectException.class);
    verify(repository, never()).create(any());
}
Also used : PushedAuthorizationRequest(io.gravitee.am.repository.oauth2.model.PushedAuthorizationRequest) LinkedMultiValueMap(io.gravitee.common.util.LinkedMultiValueMap) ParseException(java.text.ParseException) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Example 5 with PushedAuthorizationRequest

use of io.gravitee.am.repository.oauth2.model.PushedAuthorizationRequest in project gravitee-access-management by gravitee-io.

the class PushedAuthorizationRequestServiceTest method shouldNotPersist_ClientIdMismatch.

@Test
public void shouldNotPersist_ClientIdMismatch() {
    final Client client = new Client();
    client.setClientId("clientid");
    final PushedAuthorizationRequest par = new PushedAuthorizationRequest();
    final LinkedMultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    parameters.add("scope", "openid");
    parameters.add("response_type", "code");
    parameters.add("client_id", "otherid");
    par.setParameters(parameters);
    final TestObserver<PushedAuthorizationRequestResponse> observer = cut.registerParameters(par, client).test();
    observer.awaitTerminalEvent();
    observer.assertError(InvalidRequestException.class);
    verify(repository, never()).create(any());
}
Also used : PushedAuthorizationRequest(io.gravitee.am.repository.oauth2.model.PushedAuthorizationRequest) LinkedMultiValueMap(io.gravitee.common.util.LinkedMultiValueMap) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Aggregations

PushedAuthorizationRequest (io.gravitee.am.repository.oauth2.model.PushedAuthorizationRequest)15 Test (org.junit.Test)12 LinkedMultiValueMap (io.gravitee.common.util.LinkedMultiValueMap)10 Client (io.gravitee.am.model.oidc.Client)8 Date (java.util.Date)6 JWT (com.nimbusds.jwt.JWT)5 SignedJWT (com.nimbusds.jwt.SignedJWT)5 OpenIDProviderMetadata (io.gravitee.am.gateway.handler.oidc.service.discovery.OpenIDProviderMetadata)5 RandomString (io.gravitee.am.common.utils.RandomString)3 AbstractOAuthTest (io.gravitee.am.repository.oauth2.AbstractOAuthTest)3 InvalidRequestException (io.gravitee.am.common.exception.oauth2.InvalidRequestException)2 InvalidRequestObjectException (io.gravitee.am.common.exception.oauth2.InvalidRequestObjectException)2 ParseException (java.text.ParseException)2 Instant (java.time.Instant)2 List (java.util.List)2 JWSHeader (com.nimbusds.jose.JWSHeader)1 com.nimbusds.jwt (com.nimbusds.jwt)1 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)1 InvalidRequestUriException (io.gravitee.am.common.exception.oauth2.InvalidRequestUriException)1 OAuth2Exception (io.gravitee.am.common.exception.oauth2.OAuth2Exception)1