Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | const DATA = "ZIP WRITER TEST DATA"; |
michael@0 | 7 | |
michael@0 | 8 | var TESTS = []; |
michael@0 | 9 | |
michael@0 | 10 | function build_tests() { |
michael@0 | 11 | var id = 0; |
michael@0 | 12 | |
michael@0 | 13 | // Minimum mode is 0o400 |
michael@0 | 14 | for (let u = 4; u <= 7; u++) { |
michael@0 | 15 | for (let g = 0; g <= 7; g++) { |
michael@0 | 16 | for (let o = 0; o <= 7; o++) { |
michael@0 | 17 | TESTS[id] = { |
michael@0 | 18 | name: "test" + u + g + o, |
michael@0 | 19 | permission: (u << 6) + (g << 3) + o |
michael@0 | 20 | }; |
michael@0 | 21 | id++; |
michael@0 | 22 | } |
michael@0 | 23 | } |
michael@0 | 24 | } |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | function run_test() { |
michael@0 | 28 | build_tests(); |
michael@0 | 29 | |
michael@0 | 30 | var foStream = Cc["@mozilla.org/network/file-output-stream;1"]. |
michael@0 | 31 | createInstance(Ci.nsIFileOutputStream); |
michael@0 | 32 | |
michael@0 | 33 | var tmp = tmpDir.clone(); |
michael@0 | 34 | tmp.append("temp-permissions"); |
michael@0 | 35 | tmp.createUnique(Ci.nsILocalFile.DIRECTORY_TYPE, 0755); |
michael@0 | 36 | |
michael@0 | 37 | var file = tmp.clone(); |
michael@0 | 38 | file.append("tempfile"); |
michael@0 | 39 | |
michael@0 | 40 | zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE); |
michael@0 | 41 | for (let i = 0; i < TESTS.length; i++) { |
michael@0 | 42 | // Open the file with the permissions to match how the zipreader extracts |
michael@0 | 43 | // This obeys the umask |
michael@0 | 44 | foStream.init(file, 0x02 | 0x08 | 0x20, TESTS[i].permission, 0); |
michael@0 | 45 | foStream.close(); |
michael@0 | 46 | |
michael@0 | 47 | // umask may have altered the permissions so test against what they really were. |
michael@0 | 48 | // This reduces the coverage of the test but there isn't much we can do |
michael@0 | 49 | var perm = file.permissions & 0xfff; |
michael@0 | 50 | if (TESTS[i].permission != perm) { |
michael@0 | 51 | dump("File permissions for " + TESTS[i].name + " were " + perm.toString(8) + "\n"); |
michael@0 | 52 | TESTS[i].permission = perm; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | zipW.addEntryFile(TESTS[i].name, Ci.nsIZipWriter.COMPRESSION_NONE, file, false); |
michael@0 | 56 | do_check_eq(zipW.getEntry(TESTS[i].name).permissions, TESTS[i].permission | 0o400); |
michael@0 | 57 | file.permissions = 0o600; |
michael@0 | 58 | file.remove(true); |
michael@0 | 59 | } |
michael@0 | 60 | zipW.close(); |
michael@0 | 61 | |
michael@0 | 62 | zipW.open(tmpFile, PR_RDWR); |
michael@0 | 63 | for (let i = 0; i < TESTS.length; i++) { |
michael@0 | 64 | dump("Testing zipwriter file permissions for " + TESTS[i].name + "\n"); |
michael@0 | 65 | do_check_eq(zipW.getEntry(TESTS[i].name).permissions, TESTS[i].permission | 0o400); |
michael@0 | 66 | } |
michael@0 | 67 | zipW.close(); |
michael@0 | 68 | |
michael@0 | 69 | var zipR = new ZipReader(tmpFile); |
michael@0 | 70 | for (let i = 0; i < TESTS.length; i++) { |
michael@0 | 71 | dump("Testing zipreader file permissions for " + TESTS[i].name + "\n"); |
michael@0 | 72 | do_check_eq(zipR.getEntry(TESTS[i].name).permissions, TESTS[i].permission | 0o400); |
michael@0 | 73 | dump("Testing extracted file permissions for " + TESTS[i].name + "\n"); |
michael@0 | 74 | zipR.extract(TESTS[i].name, file); |
michael@0 | 75 | do_check_eq(file.permissions & 0xfff, TESTS[i].permission); |
michael@0 | 76 | do_check_false(file.isDirectory()); |
michael@0 | 77 | file.permissions = 0o600; |
michael@0 | 78 | file.remove(true); |
michael@0 | 79 | } |
michael@0 | 80 | zipR.close(); |
michael@0 | 81 | |
michael@0 | 82 | tmp.remove(true); |
michael@0 | 83 | } |