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