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