]> git.parisson.com Git - pdf.js.git/commitdiff
Hash files to make sure they haven't changed.
authorBrendan Dahl <brendan.dahl@gmail.com>
Fri, 4 Nov 2011 16:14:52 +0000 (09:14 -0700)
committerBrendan Dahl <brendan.dahl@gmail.com>
Fri, 4 Nov 2011 16:28:27 +0000 (09:28 -0700)
test/test.py
test/test_manifest.json

index 7d16ea7961651ebbf9b69a76c9e84c2a4f2606d4..bce5ae8f3d73749ab01cc52e93097783084c441e 100644 (file)
@@ -1,4 +1,4 @@
-import json, platform, os, shutil, sys, subprocess, tempfile, threading, time, urllib, urllib2
+import json, platform, os, shutil, sys, subprocess, tempfile, threading, time, urllib, urllib2, hashlib
 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
 import SocketServer
 from optparse import OptionParser
@@ -316,6 +316,28 @@ def downloadLinkedPDFs(manifestList):
 
             print 'done'
 
+def verifyPDFs(manifestList):
+    error = False
+    for item in manifestList:
+        f = item['file']
+        if os.access(f, os.R_OK):
+            fileMd5 = hashlib.md5(open(f).read()).hexdigest()
+            if 'md5' not in item:
+                print 'ERROR: Missing md5 for file "' + f + '".',
+                print 'Hash for current file is "' + fileMd5 + '"'
+                error = True
+                continue
+            md5 = item['md5']
+            if fileMd5 != md5:
+                print 'ERROR: MD5 of file "' + f + '" does not match file.',
+                print 'Expected "' + md5 + '" computed "' + fileMd5 + '"'
+                error = True
+                continue
+        else:
+            print 'ERROR: Unable to open file for reading "' + f + '".'
+            error = True
+    return not error
+
 def setUp(options):
     # Only serve files from a pdf.js clone
     assert not ANAL or os.path.isfile('../src/pdf.js') and os.path.isdir('../.git')
@@ -342,6 +364,9 @@ def setUp(options):
 
     downloadLinkedPDFs(manifestList)
 
+    if not verifyPDFs(manifestList):
+        raise Exception('ERROR: failed to verify pdfs.')
+
     for b in testBrowsers:
         State.taskResults[b.name] = { }
         for item in manifestList:
index 25f609e8dc4103d009a70322da2bd9fdc6bedee6..c3ebe6c050336a90d909d77d72c34615f1d30edd 100644 (file)
 [
     {  "id": "tracemonkey-eq",
        "file": "pdfs/tracemonkey.pdf",
+       "md5": "9a192d8b1a7dc652a19835f6f08098bd",
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "tracemonkey-fbf",
        "file": "pdfs/tracemonkey.pdf",
+       "md5": "9a192d8b1a7dc652a19835f6f08098bd",
        "rounds": 2,
        "type": "fbf"
     },
     {  "id": "html5-canvas-cheat-sheet-load",
        "file": "pdfs/canvas.pdf",
+       "md5": "59510028561daf62e00bf9f6f066b033",
        "rounds": 1,
        "type": "load"
     },
     {  "id": "intelisa-load",
        "file": "pdfs/intelisa.pdf",
+       "md5": "f3ed5487d1afa34d8b77c0c734a95c79",
        "link": true,
        "rounds": 1,
        "type": "load"
     },
     {  "id": "pdfspec-load",
        "file": "pdfs/pdf.pdf",
+       "md5": "dbdb23c939d2be09b43126c3c56060c7",
        "link": true,
        "rounds": 1,
        "type": "load"
     },
     {  "id": "shavian-load",
        "file": "pdfs/shavian.pdf",
+       "md5": "4fabf0a03e82693007435020bc446f9b",
        "link": true,
        "rounds": 1,
        "type": "load"
     },
     {  "id": "sizes",
        "file": "pdfs/sizes.pdf",
+       "md5": "c101ba7b44aee36048e1ac7b98f302ea",
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "openweb-cover",
        "file": "pdfs/openweb_tm-PRINT.pdf",
+       "md5": "53f611dfc19ddfb50554c21c4af465c0",
        "link": true,
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "plusminus",
        "file": "pdfs/Test-plusminus.pdf",
+       "md5": "1ec7ade5b95ac9aaba3a618af28d34c7",
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "openoffice-pdf",
        "file": "pdfs/DiwanProfile.pdf",
+       "md5": "55d0c6a1a6d26c9ec9dcecaa7a471e0e",
        "link": true,
        "rounds": 1,
        "type": "load"
     },
     {  "id": "openofficecidtruetype-pdf",
        "file": "pdfs/arial_unicode_en_cidfont.pdf",
+       "md5": "03591cdf20214fb0b2dd5e5c3dd32d8c",
        "rounds": 1,
        "type": "load"
     },
     {  "id": "openofficearabiccidtruetype-pdf",
        "file": "pdfs/arial_unicode_ab_cidfont.pdf",
+       "md5": "35090fa7d29e7196ae3421812e554988",
        "rounds": 1,
        "type": "load"
     },
     {  "id": "arabiccidtruetype-pdf",
        "file": "pdfs/ArabicCIDTrueType.pdf",
+       "md5": "d66dbd18bdb572d3ac8b88b32de2ece6",
        "rounds": 1,
        "type": "load"
     },
     {  "id": "complexttffont-pdf",
        "file": "pdfs/complex_ttf_font.pdf",
+       "md5": "76de93f9116b01b693bf8583b3e76d91",
        "rounds": 1,
        "type": "load"
     },
     {  "id": "thuluthfont-pdf",
        "file": "pdfs/ThuluthFeatures.pdf",
+       "md5": "b7e18bf7a3d6a9c82aefa12d721072fc",
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "wnv_chinese-pdf",
        "file": "pdfs/wnv_chinese.pdf",
+       "md5": "db682638e68391125e8982d3c984841e",
        "link": true,
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "i9-pdf",
        "file": "pdfs/i9.pdf",
+       "md5": "ba7cd54fdff083bb389295bc0415f6c5",
        "link": true,
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "hmm-pdf",
        "file": "pdfs/hmm.pdf",
+       "md5": "e08467e60101ee5f4a59716e86db6dc9",
        "link": true,
        "rounds": 1,
        "type": "load"
     },
     {  "id": "rotation",
        "file": "pdfs/rotation.pdf",
+       "md5": "4fb25ada00ce7528569d9791c14decf5",
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "ecma262-pdf",
        "file": "pdfs/ecma262.pdf",
+       "md5": "763ead98f535578842891e5574e0af0f",
        "link": true,
        "rounds": 1,
        "type": "load"
     },
     {  "id": "jai-pdf",
        "file": "pdfs/jai.pdf",
+       "md5": "1f5dd128c3757420a881a155f2f8ace3",
        "link": true,
        "rounds": 1,
        "type": "load"
     },
     {  "id": "cable",
        "file": "pdfs/cable.pdf",
+       "md5": "09a41b9a759d60c698228224ab85b46d",
        "link": true,
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "pdkids",
        "file": "pdfs/pdkids.pdf",
+       "md5": "278982bf016dbe46d2066f9245d9b3e6",
        "link": true,
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "artofwar",
        "file": "pdfs/artofwar.pdf",
+       "md5": "7bdd51c327b74f1f7abdd90eedb2f912",
        "link": true,
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "wdsg_fitc",
        "file": "pdfs/wdsg_fitc.pdf",
+       "md5": "5bb1c2b83705d4cdfc43197ee74f07f9",
        "link": true,
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "unix01",
        "file": "pdfs/unix01.pdf",
+       "md5": "2742999f0bf9b9c035dbb0736096e220",
        "link": true,
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "fit11-talk",
        "file": "pdfs/fit11-talk.pdf",
+       "md5": "eb7b224107205db4fea9f7df0185f77d",
        "link": true,
        "rounds": 1,
        "skipPages": [12,31],
     },
     {  "id": "fips197",
        "file": "pdfs/fips197.pdf",
+       "md5": "374800cf78ce4b4abd02cd10a856b57f",
        "link": true,
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "txt2pdf",
        "file": "pdfs/txt2pdf.pdf",
+       "md5": "02cefa0f5e8d96313bb05163b2f88c8c",
        "link": true,
        "rounds": 1,
        "type": "load"
     },
     {  "id": "f1040",
        "file": "pdfs/f1040.pdf",
+       "md5": "7323b50c6d28d959b8b4b92c469b2469",
        "link": true,
        "rounds": 1,
        "type": "load"
     },
     {  "id": "hudsonsurvey",
        "file": "pdfs/hudsonsurvey.pdf",
+       "md5": "bf0e6576a7b6c2fe7485bce1b78e006f",
        "link": true,
        "rounds": 1,
        "type": "load"
     },
     {  "id": "extgstate",
        "file": "pdfs/extgstate.pdf",
+       "md5": "001bb4ec04463a01d93aad748361f049",
        "link": false,
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "usmanm-bad",
        "file": "pdfs/usmanm-bad.pdf",
+       "md5": "38afb822433aaf07fc8f54807cd4f61a",
        "link": true,
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "vesta-bad",
        "file": "pdfs/vesta.pdf",
+       "md5": "0afebc109b7c17b95619ea3fab5eafe6",
        "link": true,
        "rounds": 1,
        "type": "load"
     },
     {  "id": "ibwa-bad",
        "file": "pdfs/ibwa-bad.pdf",
+       "md5": "6ca059d32b74ac2688ae06f727fee755",
        "link": true,
        "rounds": 1,
        "skipPages": [ 16 ],
     },
     {  "id": "tcpdf_033",
        "file": "pdfs/tcpdf_033.pdf",
+       "md5": "de7a4a8b1b476b579df606c2d6e7ed05",
        "link": true,
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "pal-o47",
        "file": "pdfs/pal-o47.pdf",
+       "md5": "81ae15e539e89f0f0b41169d923b611b",
        "link": true,
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "simpletype3font",
        "file": "pdfs/simpletype3font.pdf",
+       "md5": "b374c7543920840c61999e9e86939f99",
        "link": false,
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "close-path-bug",
        "file": "pdfs/close-path-bug.pdf",
+       "md5": "48dd17ef58393857d2d038d33699cac5",
        "rounds": 1,
        "type": "eq"
     },
     {  "id": "alphatrans",
        "file": "pdfs/alphatrans.pdf",
+       "md5": "5ca2d3da0c5f20b3a5a14e895ad24b65",
        "link": false,
        "rounds": 1,
        "type": "eq"