netwerk/test/unit/test_bug712914_secinfo_validation.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 var _ios;
michael@0 2
michael@0 3 var ACCESS_WRITE = Ci.nsICache.ACCESS_WRITE;
michael@0 4 var ACCESS_READ = Ci.nsICache.ACCESS_READ;
michael@0 5
michael@0 6 var KEY_CORRUPT_SECINFO = "http://corruptSecurityInfo/";
michael@0 7 var ENTRY_DATA = "foobar";
michael@0 8
michael@0 9 function create_scriptable_input(unscriptable_input) {
michael@0 10 var istream = Cc["@mozilla.org/scriptableinputstream;1"].
michael@0 11 createInstance(Ci.nsIScriptableInputStream);
michael@0 12 istream.init(unscriptable_input);
michael@0 13 return istream;
michael@0 14 }
michael@0 15
michael@0 16 function write_data(entry) {
michael@0 17 var ostream = entry.openOutputStream(0);
michael@0 18 if (ostream.write(ENTRY_DATA, ENTRY_DATA.length) != ENTRY_DATA.length) {
michael@0 19 do_throw("Could not write all data!");
michael@0 20 }
michael@0 21 ostream.close();
michael@0 22 }
michael@0 23
michael@0 24 function continue_failure(status, entry) {
michael@0 25 // Make sure we couldn't open this for reading
michael@0 26 do_check_eq(status, Cr.NS_ERROR_CACHE_KEY_NOT_FOUND);
michael@0 27
michael@0 28 // Make sure the cache is empty
michael@0 29 get_device_entry_count("disk", null, function(count, consumption) {
michael@0 30 do_check_eq(count, 0);
michael@0 31 do_check_eq(consumption, 0);
michael@0 32 run_next_test();
michael@0 33 });
michael@0 34 }
michael@0 35
michael@0 36 function try_read_corrupt_secinfo() {
michael@0 37 asyncOpenCacheEntry(KEY_CORRUPT_SECINFO,
michael@0 38 "disk", Ci.nsICacheStorage.OPEN_READONLY, null,
michael@0 39 continue_failure);
michael@0 40 }
michael@0 41
michael@0 42 function write_corrupt_secinfo(status, entry) {
michael@0 43 entry.setMetaDataElement("security-info", "blablabla");
michael@0 44 write_data(entry);
michael@0 45 try {
michael@0 46 entry.close();
michael@0 47 } catch (e) {
michael@0 48 do_throw("Unexpected exception closing corrupt entry: " + e);
michael@0 49 }
michael@0 50
michael@0 51 try_read_corrupt_secinfo();
michael@0 52 }
michael@0 53
michael@0 54 function test_corrupt_secinfo() {
michael@0 55 asyncOpenCacheEntry(KEY_CORRUPT_SECINFO,
michael@0 56 "disk", Ci.nsICacheStorage.OPEN_TRUNCATE, null,
michael@0 57 write_corrupt_secinfo);
michael@0 58 }
michael@0 59
michael@0 60 function run_test() {
michael@0 61 if (newCacheBackEndUsed()) {
michael@0 62 // broken sec info should doom a cache entry (when broken sec info is written, load should fail with NOT_FOUND)
michael@0 63 do_check_true(true, "This test doesn't run with the new cache backend, the test or the cache needs to be fixed");
michael@0 64 return;
michael@0 65 }
michael@0 66
michael@0 67 // Make sure we have a cache to use
michael@0 68 do_get_profile();
michael@0 69
michael@0 70 // Make sure the cache is empty
michael@0 71 evict_cache_entries();
michael@0 72
michael@0 73 // Add new tests at the end of this section
michael@0 74 add_test(test_corrupt_secinfo);
michael@0 75
michael@0 76 // Let's get going!
michael@0 77 run_next_test();
michael@0 78 }

mercurial