@Test(expected=DSSException.class) public void testGetBiggerThanMaxSize() { NativeHTTPDataLoader dataLoader = new NativeHTTPDataLoader(); dataLoader.setMaxInputSize(1); dataLoader.get(FILE_URL_TO_LOAD); }
@Override public byte[] get(String url, boolean refresh) { return request(url, HttpMethod.GET, null, !refresh); }
@Test(expected=DSSException.class) public void testGetTimeout() { NativeHTTPDataLoader dataLoader = new NativeHTTPDataLoader(); dataLoader.setTimeout(1); dataLoader.get(HTTP_URL_TO_LOAD); } }
@Test public void testFileGet() { NativeHTTPDataLoader dataLoader = new NativeHTTPDataLoader(); byte[] bytesArray = dataLoader.get(FILE_URL_TO_LOAD); CertificateToken certificate = DSSUtils.loadCertificate(bytesArray); assertNotNull(certificate); }
@Test public void testLoadIssuerNoAIA() { CertificateToken certificate = DSSUtils.loadCertificate(new File("src/test/resources/citizen_ca.cer")); assertTrue(DSSUtils.loadPotentialIssuerCertificates(certificate, new NativeHTTPDataLoader()).isEmpty()); assertTrue(certificate.isCA()); }
@Override public byte[] get(String url) { return get(url, false); }
@Test public void testHttpGet() { NativeHTTPDataLoader dataLoader = new NativeHTTPDataLoader(); byte[] bytesArray = dataLoader.get(HTTP_URL_TO_LOAD); CertificateToken certificate = DSSUtils.loadCertificate(bytesArray); assertNotNull(certificate); }
@Test public void testWithNativeHTTPDataLoader() { OnlineTSPSource tspSource = new OnlineTSPSource(TSA_URL); tspSource.setDataLoader(new NativeHTTPDataLoader()); byte[] digest = DSSUtils.digest(DigestAlgorithm.SHA1, "Hello world".getBytes()); TimeStampToken timeStampResponse = tspSource.getTimeStampResponse(DigestAlgorithm.SHA1, digest); assertNotNull(timeStampResponse); }
@Override public DataAndUrl get(List<String> urlStrings) { for (final String urlString : urlStrings) { try { final byte[] bytes = get(urlString); if (bytes != null) { return new DataAndUrl(bytes, urlString); } } catch (Exception e) { LOGGER.warn("Impossible to obtain data using {}", urlString, e); } } throw new DSSException(String.format("Impossible to obtain data using with given urls %s", urlStrings)); }
@Test public void testGet() { byte[] bytesArray = dataLoader.get(URL_TO_LOAD); NativeHTTPDataLoader dataLoader2 = new NativeHTTPDataLoader(); byte[] bytesArrays2 = dataLoader2.get(URL_TO_LOAD); assertTrue(Arrays.equals(bytesArray, bytesArrays2)); CertificateToken certificate = DSSUtils.loadCertificate(bytesArray); assertNotNull(certificate); }
@Test public void testLoadIssuer() { Collection<CertificateToken> issuers = DSSUtils.loadPotentialIssuerCertificates(certificateWithAIA, new NativeHTTPDataLoader()); assertNotNull(issuers); assertFalse(issuers.isEmpty()); boolean foundIssuer = false; for (CertificateToken issuer : issuers) { if (certificateWithAIA.isSignedBy(issuer)) { foundIssuer = true; } } assertTrue(foundIssuer); }
@Override public byte[] post(String url, byte[] content) { return request(url, HttpMethod.POST, content, false); }
dataLoader = new NativeHTTPDataLoader();
@Test public void testWithNonce() { OnlineTSPSource tspSource = new OnlineTSPSource(TSA_URL); tspSource.setDataLoader(new NativeHTTPDataLoader()); tspSource.setNonceSource(new SecureRandomNonceSource()); byte[] digest = DSSUtils.digest(DigestAlgorithm.SHA1, "Hello world".getBytes()); TimeStampToken timeStampResponse = tspSource.getTimeStampResponse(DigestAlgorithm.SHA1, digest); assertNotNull(timeStampResponse); }