### Question:
SamlHelper { public String getArtifactUrl(String realmId, String artifact) { byte[] sourceId = retrieveSourceId(artifact); Entity realm = realmHelper.findRealmById(realmId); if (realm == null) { LOG.error("Invalid realm: " + realmId); throw new APIAccessDeniedException("Authorization could not be verified."); } Map<String, Object> idp = (Map<String, Object>) realm.getBody().get("idp"); String realmSourceId = (String) idp.get("sourceId"); if (realmSourceId == null || realmSourceId.isEmpty()) { LOG.error("SourceId is not configured properly for realm: " + realmId); throw new APIAccessDeniedException("Authorization could not be verified."); } byte[] realmByteSourceId = DatatypeConverter.parseHexBinary(realmSourceId); if (!Arrays.equals(realmByteSourceId, sourceId)) { LOG.error("SourceId from Artifact does not match configured SourceId for realm: " + realmId); throw new APIAccessDeniedException("Authorization could not be verified."); } return (String) idp.get("artifactResolutionEndpoint"); }  @PostConstruct void init(); Pair<String, String> createSamlAuthnRequestForRedirect(String destination, boolean forceAuthn, int idpType); org.w3c.dom.Document parseToDoc(String data); String decodeSAMLPostResponse(String encodedReponse); Signature getDigitalSignature(KeyStore.PrivateKeyEntry keystoreEntry); void validateSignature(Response samlResponse, Assertion assertion); LinkedMultiValueMap<String, String> extractAttributesFromResponse(Assertion samlAssertion); String getArtifactUrl(String realmId, String artifact); org.opensaml.saml2.core.Response convertToSAMLResponse(org.w3c.dom.Element element); Assertion getAssertion(org.opensaml.saml2.core.Response samlResponse, KeyStore.PrivateKeyEntry keystoreEntry); void validateStatus(org.opensaml.saml2.core.Response samlResponse); static final Namespace SAML_NS; static final Namespace SAMLP_NS; }### Answer:
@Test public void testGetArtifactUrl() { setRealm(VALID_SOURCEID); String result = samlHelper.getArtifactUrl(REALM_ID, ARTIFACT); Assert.assertEquals(ARTIFACT_RESOLUTION_ENDPOINT, result); }
@Test(expected = APIAccessDeniedException.class) public void testGetArtifactUrlIncorrectSourceId() { setRealm(INCORRECT_SOURCEID); String result = samlHelper.getArtifactUrl(REALM_ID, ARTIFACT); Assert.assertEquals(ARTIFACT_RESOLUTION_ENDPOINT, result); }
@Test(expected = IllegalArgumentException.class) public void testGetArtifactUrlInvalidSourceIdFormat() { setRealm(NOT_HEX_SOURCEID); String result = samlHelper.getArtifactUrl(REALM_ID, ARTIFACT); Assert.assertEquals(ARTIFACT_RESOLUTION_ENDPOINT, result); }