Skip to content

Commit 80e9daa

Browse files
committed
Test that a 404 is neither cached nor recorded as valid
Exercises the new status checking against the real wwPDB archive: downloadFile must throw HttpStatusException rather than writing the error page to the destination, and createValidationFiles must not record a .size for it. Without the second half the cached error page would pass validateFile, since its recorded size would match the error body exactly.
1 parent f061f57 commit 80e9daa

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎biojava-core/src/test/java/org/biojava/nbio/core/util/FileDownloadUtilsTest.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,31 @@ void testValidationFiles() throws IOException{
214214
}
215215
}
216216

217+
@Nested
218+
class HttpStatus {
219+
220+
@Test
221+
void notFoundThrowsAndLeavesNothingBehind() throws IOException {
222+
// A path that is guaranteed absent from the wwPDB archive.
223+
URL missing = new URL("https://files.wwpdb.org/pub/pdb/data/structures/divided/mmCIF/zz/zzzz.cif.gz");
224+
File dest = new File(System.getProperty("java.io.tmpdir"), "bj-missing.cif.gz");
225+
File sizeFile = new File(dest.getParentFile(), dest.getName() + ".size");
226+
dest.delete();
227+
sizeFile.delete();
228+
229+
HttpStatusException e = assertThrows(HttpStatusException.class,
230+
() -> FileDownloadUtils.downloadFile(missing, dest));
231+
assertEquals(404, e.getStatusCode());
232+
assertTrue(e.isNotFound());
233+
assertFalse(dest.exists(), "a 404 body must never be written to the destination");
234+
235+
// ... and no validation metadata may be recorded for it either, or the
236+
// cached error page would later pass validation.
237+
FileDownloadUtils.createValidationFiles(missing, dest, null, FileDownloadUtils.Hash.UNKNOWN);
238+
assertFalse(sizeFile.exists(), "no size file should be written for a 404 response");
239+
}
240+
}
241+
217242
@Nested
218243
class Hashing {
219244

0 commit comments

Comments
 (0)