### Question:
OpenIdConnectAuthorizeRequestValidator implements AuthorizeRequestValidator { public void validateRequest(OAuth2Request request) throws BadRequestException, InvalidRequestException, InvalidClientException, InvalidScopeException, NotFoundException { validateOpenIdScope(request); try { OpenIdPrompt prompt = new OpenIdPrompt(request); Reject.ifFalse(prompt.isValid(), "Prompt parameter " + prompt.getOriginalValue() + " is invalid or unsupported"); } catch (IllegalArgumentException e) { throw new BadRequestException(e.getMessage()); } } @Inject  OpenIdConnectAuthorizeRequestValidator(ClientRegistrationStore clientRegistrationStore); void validateRequest(OAuth2Request request);  }### Answer:
@Test public void validateShouldPassForRequestWithOpenidScopeOnOidcClient() throws Exception { OAuth2Request request = mock(OAuth2Request.class); given(clientRegistration.getAllowedScopes()).willReturn(Collections.singleton("openid")); given(request.getParameter("client_id")).willReturn("CLIENT_ID"); given(request.getParameter("scope")).willReturn("openid"); given(request.getParameter("prompt")).willReturn("consent"); given(request.getParameter("nonce")).willReturn("12345"); requestValidator.validateRequest(request); }
@Test (expectedExceptions = BadRequestException.class) public void validateShouldFailForInvalidPrompt() throws Exception { OAuth2Request request = mock(OAuth2Request.class); given(clientRegistration.getAllowedScopes()).willReturn(Collections.singleton("openid")); given(request.getParameter("client_id")).willReturn("CLIENT_ID"); given(request.getParameter("scope")).willReturn("openid"); given(request.getParameter("prompt")).willReturn("select_account"); given(request.getParameter("nonce")).willReturn("12345"); requestValidator.validateRequest(request); }
@Test (expectedExceptions = InvalidRequestException.class) public void validateShouldFailForRequestWithNoOpenidScopeOnOidcClient() throws Exception { OAuth2Request request = mock(OAuth2Request.class); given(clientRegistration.getAllowedScopes()).willReturn(Collections.singleton("openid")); given(request.getParameter("client_id")).willReturn("CLIENT_ID"); given(request.getParameter("scope")).willReturn("nothing"); requestValidator.validateRequest(request); }
@Test public void validateShouldFailWithInvalidRequestExceptionAndFragmentParameters() throws Exception { OAuth2Request request = mock(OAuth2Request.class); given(clientRegistration.getAllowedScopes()).willReturn(Collections.singleton("openid")); given(request.getParameter("client_id")).willReturn("CLIENT_ID"); given(request.getParameter("scope")).willReturn("nothing"); given(request.getParameter("response_type")).willReturn("id_token"); try { requestValidator.validateRequest(request); fail(); } catch (InvalidRequestException e) { assertEquals(e.getParameterLocation(), OAuth2Constants.UrlLocation.FRAGMENT); } }
@Test public void validateShouldFailWithInvalidRequestExceptionAndQueryParameters() throws Exception { OAuth2Request request = mock(OAuth2Request.class); given(clientRegistration.getAllowedScopes()).willReturn(Collections.singleton("openid")); given(request.getParameter("client_id")).willReturn("CLIENT_ID"); given(request.getParameter("scope")).willReturn("nothing"); given(request.getParameter("response_type")).willReturn("code"); try { requestValidator.validateRequest(request); fail(); } catch (InvalidRequestException e) { assertEquals(e.getParameterLocation(), OAuth2Constants.UrlLocation.QUERY); } }
@Test (expectedExceptions = InvalidRequestException.class) public void validateShouldFailNonceCheck() throws Exception { OAuth2Request request = mock(OAuth2Request.class); given(clientRegistration.getAllowedScopes()).willReturn(Collections.singleton("openid")); given(request.getParameter("client_id")).willReturn("CLIENT_ID"); given(request.getParameter("scope")).willReturn("openid"); given(request.getParameter("response_type")).willReturn("id_token"); requestValidator.validateRequest(request); }