### Question:
SamlFederationResource { @GET @Path("sso/artifact") public Response processArtifactBinding(@Context HttpServletRequest request, @Context UriInfo uriInfo) { String artifact = request.getParameter("SAMLart"); String realmId = request.getParameter("RelayState"); if (artifact == null) { throw new APIAccessDeniedException("No artifact provided by the IdP"); } String artifactUrl = samlHelper.getArtifactUrl(realmId, artifact); ArtifactResolve artifactResolve = artifactBindingHelper.generateArtifactResolveRequest(artifact, dsPKEntry, artifactUrl); Envelope soapEnvelope = artifactBindingHelper.generateSOAPEnvelope(artifactResolve); XMLObject response = soapHelper.sendSOAPCommunication(soapEnvelope, artifactUrl, clientCertPKEntry); ArtifactResponse artifactResponse = (ArtifactResponse)((EnvelopeImpl) response).getBody().getUnknownXMLObjects().get(0); org.opensaml.saml2.core.Response samlResponse = (org.opensaml.saml2.core.Response) artifactResponse.getMessage(); return processSAMLResponse(samlResponse, uriInfo); }  @GET @Path("metadata") @Produces({ "text/xml" }) Response getMetadata(); @POST @Path("sso/post") Response processPostBinding(@FormParam("SAMLResponse") String postData, @Context UriInfo uriInfo); @GET @Path("sso/artifact") Response processArtifactBinding(@Context HttpServletRequest request, @Context UriInfo uriInfo); static SimpleDateFormat ft; }### Answer:
@Test (expected= APIAccessDeniedException.class) public void processArtifactBindingInvalidRequest() { setRealm(false); HttpServletRequest request = Mockito.mock(HttpServletRequest.class); UriInfo uriInfo = Mockito.mock(UriInfo.class); Mockito.when(request.getParameter("RelayState")).thenReturn("My Realm"); resource.processArtifactBinding(request, uriInfo); }
@Test public void processArtifactBindingInvalidCondition() throws URISyntaxException { setRealm(false); HttpServletRequest request = Mockito.mock(HttpServletRequest.class); UriInfo uriInfo = Mockito.mock(UriInfo.class); URI uri = new URI(issuerString); Mockito.when(uriInfo.getRequestUri()).thenReturn(uri); Mockito.when(uriInfo.getAbsolutePath()).thenReturn(uri); Mockito.when(request.getParameter("SAMLart")).thenReturn("AAQAAjh3bwgbBZ+LiIx3/RVwDGy0aRUu+xxuNtTZVbFofgZZVCKJQwQNQ7Q="); Mockito.when(request.getParameter("RelayState")).thenReturn("My Realm"); List<Assertion> assertions = new ArrayList<Assertion>(); DateTimeFormatter fmt = DateTimeFormat.forPattern("MM/dd/yyyy"); DateTime datetime = DateTime.now(); datetime = datetime.plusMonths(2) ; Assertion assertion = createAssertion(datetime.toString(fmt), "01/10/2011", issuerString); assertions.add(assertion); Mockito.when(samlHelper.getAssertion(Mockito.any(org.opensaml.saml2.core.Response.class), Mockito.any(KeyStore.PrivateKeyEntry.class))).thenReturn(assertion); expectedException.expect(APIAccessDeniedException.class); expectedException.expectMessage("Authorization could not be verified."); resource.processArtifactBinding(request, uriInfo); Mockito.when(assertion.getSubject()).thenReturn(null); resource.processArtifactBinding(request, uriInfo); assertions.clear(); assertions.add(createAssertion("01/10/2011", datetime.toString(fmt), issuerString)); resource.processArtifactBinding(request, uriInfo); }