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());
}
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));
}
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());
}
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());
}
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());
}
Aggregations