extensions/cookie/test/unit/test_permmanager_local_files.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 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 // Test that permissions work for file:// URIs (aka local files).
michael@0 5
michael@0 6 function getPrincipalFromURIString(uriStr)
michael@0 7 {
michael@0 8 return Services.scriptSecurityManager.getNoAppCodebasePrincipal(NetUtil.newURI(uriStr));
michael@0 9 }
michael@0 10
michael@0 11 function run_test() {
michael@0 12 let pm = Services.perms;
michael@0 13
michael@0 14 // If we add a permission to a file:// URI, the test should return true.
michael@0 15 let principal = getPrincipalFromURIString("file:///foo/bar");
michael@0 16 pm.addFromPrincipal(principal, "test/local-files", pm.ALLOW_ACTION, 0, 0);
michael@0 17 do_check_eq(pm.testPermissionFromPrincipal(principal, "test/local-files"), pm.ALLOW_ACTION);
michael@0 18
michael@0 19 // Another file:// URI should have the same permission.
michael@0 20 let witnessPrincipal = getPrincipalFromURIString("file:///bar/foo");
michael@0 21 do_check_eq(pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), pm.UNKNOWN_ACTION);
michael@0 22
michael@0 23 // Giving "file:///" a permission shouldn't give it to all file:// URIs.
michael@0 24 let rootPrincipal = getPrincipalFromURIString("file:///");
michael@0 25 pm.addFromPrincipal(rootPrincipal, "test/local-files", pm.ALLOW_ACTION, 0, 0);
michael@0 26 do_check_eq(pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), pm.UNKNOWN_ACTION);
michael@0 27
michael@0 28 // Giving "file://" a permission shouldn't give it to all file:// URIs.
michael@0 29 let schemeRootPrincipal = getPrincipalFromURIString("file://");
michael@0 30 pm.addFromPrincipal(schemeRootPrincipal, "test/local-files", pm.ALLOW_ACTION, 0, 0);
michael@0 31 do_check_eq(pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), pm.UNKNOWN_ACTION);
michael@0 32
michael@0 33 // Giving 'node' a permission shouldn't give it to its 'children'.
michael@0 34 let fileInDirPrincipal = getPrincipalFromURIString("file:///foo/bar/foobar.txt");
michael@0 35 do_check_eq(pm.testPermissionFromPrincipal(fileInDirPrincipal, "test/local-files"), pm.UNKNOWN_ACTION);
michael@0 36
michael@0 37 // Revert "file:///foo/bar" permission and check that it has been correctly taken into account.
michael@0 38 pm.removeFromPrincipal(principal, "test/local-files");
michael@0 39 do_check_eq(pm.testPermissionFromPrincipal(principal, "test/local-files"), pm.UNKNOWN_ACTION);
michael@0 40 do_check_eq(pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), pm.UNKNOWN_ACTION);
michael@0 41 do_check_eq(pm.testPermissionFromPrincipal(fileInDirPrincipal, "test/local-files"), pm.UNKNOWN_ACTION);
michael@0 42
michael@0 43 // Add the magic "<file>" permission and make sure all "file://" now have the permission.
michael@0 44 pm.addFromPrincipal(getPrincipalFromURIString("http://<file>"), "test/local-files", pm.ALLOW_ACTION, 0, 0);
michael@0 45 do_check_eq(pm.testPermissionFromPrincipal(principal, "test/local-files"), pm.ALLOW_ACTION);
michael@0 46 do_check_eq(pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), pm.ALLOW_ACTION);
michael@0 47 do_check_eq(pm.testPermissionFromPrincipal(fileInDirPrincipal, "test/local-files"), pm.ALLOW_ACTION);
michael@0 48 }

mercurial