mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-27 12:15:33 +00:00
fe1e99cceb
Adds additional tests that try to read files and get directory listings from both a web content process and a file content process. Tests include attempting to read the profile directory and cookies file from a web content process and validating that this is prevented by the sandbox when the sandbox level (security.sandbox.content.level) is set high enough. Only Mac (for now) uses a level that includes read access blocking of the profile directory. Tests also attempt to read the profile and cookies file from a file content process which should be allowed. MozReview-Commit-ID: KfyT9ohsuuG --HG-- extra : rebase_source : f1c5aa2fef58a6bb859623072770ea918f8f4df1
72 lines
2.3 KiB
JavaScript
72 lines
2.3 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"]
|
|
.getService(Ci.nsIUUIDGenerator);
|
|
|
|
/*
|
|
* Utility functions for the browser content sandbox tests.
|
|
*/
|
|
|
|
function isMac() { return Services.appinfo.OS == "Darwin" }
|
|
function isWin() { return Services.appinfo.OS == "WINNT" }
|
|
function isLinux() { return Services.appinfo.OS == "Linux" }
|
|
|
|
function isNightly() {
|
|
let version = SpecialPowers.Cc["@mozilla.org/xre/app-info;1"].
|
|
getService(SpecialPowers.Ci.nsIXULAppInfo).version;
|
|
return (version.endsWith("a1"));
|
|
}
|
|
|
|
function uuid() {
|
|
return uuidGenerator.generateUUID().toString();
|
|
}
|
|
|
|
// Returns a file object for a new file in the home dir ($HOME/<UUID>).
|
|
function fileInHomeDir() {
|
|
// get home directory, make sure it exists
|
|
let homeDir = Services.dirsvc.get("Home", Ci.nsILocalFile);
|
|
Assert.ok(homeDir.exists(), "Home dir exists");
|
|
Assert.ok(homeDir.isDirectory(), "Home dir is a directory");
|
|
|
|
// build a file object for a new file named $HOME/<UUID>
|
|
let homeFile = homeDir.clone();
|
|
homeFile.appendRelativePath(uuid());
|
|
Assert.ok(!homeFile.exists(), homeFile.path + " does not exist");
|
|
return (homeFile);
|
|
}
|
|
|
|
// Returns a file object for a new file in the content temp dir (.../<UUID>).
|
|
function fileInTempDir() {
|
|
let contentTempKey = "ContentTmpD";
|
|
if (Services.appinfo.OS == "Linux") {
|
|
// Linux builds don't use the content-specific temp key
|
|
contentTempKey = "TmpD";
|
|
}
|
|
|
|
// get the content temp dir, make sure it exists
|
|
let ctmp = Services.dirsvc.get(contentTempKey, Ci.nsILocalFile);
|
|
Assert.ok(ctmp.exists(), "Content temp dir exists");
|
|
Assert.ok(ctmp.isDirectory(), "Content temp dir is a directory");
|
|
|
|
// build a file object for a new file in content temp
|
|
let tempFile = ctmp.clone();
|
|
tempFile.appendRelativePath(uuid());
|
|
Assert.ok(!tempFile.exists(), tempFile.path + " does not exist");
|
|
return (tempFile);
|
|
}
|
|
|
|
function GetProfileDir() {
|
|
// get profile directory
|
|
let profileDir = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
|
return (profileDir);
|
|
}
|
|
|
|
// Returns a file object for the file or directory named |name| in the
|
|
// profile directory.
|
|
function GetProfileEntry(name) {
|
|
let entry = GetProfileDir();
|
|
entry.append(name);
|
|
return (entry);
|
|
}
|