1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/extensions/cookie/test/unit/test_permmanager_local_files.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,48 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Test that permissions work for file:// URIs (aka local files). 1.8 + 1.9 +function getPrincipalFromURIString(uriStr) 1.10 +{ 1.11 + return Services.scriptSecurityManager.getNoAppCodebasePrincipal(NetUtil.newURI(uriStr)); 1.12 +} 1.13 + 1.14 +function run_test() { 1.15 + let pm = Services.perms; 1.16 + 1.17 + // If we add a permission to a file:// URI, the test should return true. 1.18 + let principal = getPrincipalFromURIString("file:///foo/bar"); 1.19 + pm.addFromPrincipal(principal, "test/local-files", pm.ALLOW_ACTION, 0, 0); 1.20 + do_check_eq(pm.testPermissionFromPrincipal(principal, "test/local-files"), pm.ALLOW_ACTION); 1.21 + 1.22 + // Another file:// URI should have the same permission. 1.23 + let witnessPrincipal = getPrincipalFromURIString("file:///bar/foo"); 1.24 + do_check_eq(pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), pm.UNKNOWN_ACTION); 1.25 + 1.26 + // Giving "file:///" a permission shouldn't give it to all file:// URIs. 1.27 + let rootPrincipal = getPrincipalFromURIString("file:///"); 1.28 + pm.addFromPrincipal(rootPrincipal, "test/local-files", pm.ALLOW_ACTION, 0, 0); 1.29 + do_check_eq(pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), pm.UNKNOWN_ACTION); 1.30 + 1.31 + // Giving "file://" a permission shouldn't give it to all file:// URIs. 1.32 + let schemeRootPrincipal = getPrincipalFromURIString("file://"); 1.33 + pm.addFromPrincipal(schemeRootPrincipal, "test/local-files", pm.ALLOW_ACTION, 0, 0); 1.34 + do_check_eq(pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), pm.UNKNOWN_ACTION); 1.35 + 1.36 + // Giving 'node' a permission shouldn't give it to its 'children'. 1.37 + let fileInDirPrincipal = getPrincipalFromURIString("file:///foo/bar/foobar.txt"); 1.38 + do_check_eq(pm.testPermissionFromPrincipal(fileInDirPrincipal, "test/local-files"), pm.UNKNOWN_ACTION); 1.39 + 1.40 + // Revert "file:///foo/bar" permission and check that it has been correctly taken into account. 1.41 + pm.removeFromPrincipal(principal, "test/local-files"); 1.42 + do_check_eq(pm.testPermissionFromPrincipal(principal, "test/local-files"), pm.UNKNOWN_ACTION); 1.43 + do_check_eq(pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), pm.UNKNOWN_ACTION); 1.44 + do_check_eq(pm.testPermissionFromPrincipal(fileInDirPrincipal, "test/local-files"), pm.UNKNOWN_ACTION); 1.45 + 1.46 + // Add the magic "<file>" permission and make sure all "file://" now have the permission. 1.47 + pm.addFromPrincipal(getPrincipalFromURIString("http://<file>"), "test/local-files", pm.ALLOW_ACTION, 0, 0); 1.48 + do_check_eq(pm.testPermissionFromPrincipal(principal, "test/local-files"), pm.ALLOW_ACTION); 1.49 + do_check_eq(pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), pm.ALLOW_ACTION); 1.50 + do_check_eq(pm.testPermissionFromPrincipal(fileInDirPrincipal, "test/local-files"), pm.ALLOW_ACTION); 1.51 +} 1.52 \ No newline at end of file