Commit 64c8669b authored by jln@chromium.org's avatar jln@chromium.org

Setuid sandbox unittest: fix environment.

Don't pollute LD_PRELOAD in the environment after a test runs.

BUG=


Review URL: https://chromiumcodereview.appspot.com/10823251

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150739 0039d316-1c4b-4281-b951-d872f2087c98
parent e7ceccb7
......@@ -18,6 +18,10 @@ TEST(SetuidSandboxClient, SetupLaunchEnvironment) {
scoped_ptr<base::Environment> env(base::Environment::Create());
EXPECT_TRUE(env != NULL);
std::string saved_ld_preload;
bool environment_had_ld_preload;
// First, back-up the real LD_PRELOAD if any.
environment_had_ld_preload = env->GetVar("LD_PRELOAD", &saved_ld_preload);
// Setup environment variables to save or not save.
EXPECT_TRUE(env->SetVar("LD_PRELOAD", kTestValue));
EXPECT_TRUE(env->UnSetVar("LD_ORIGIN_PATH"));
......@@ -46,6 +50,14 @@ TEST(SetuidSandboxClient, SetupLaunchEnvironment) {
// Check that LD_ORIGIN_PATH was not saved.
EXPECT_FALSE(env->HasVar("SANDBOX_LD_ORIGIN_PATH"));
// We should not forget to restore LD_PRELOAD at the end, or this environment
// variable will affect the next running tests!
if (environment_had_ld_preload) {
EXPECT_TRUE(env->SetVar("LD_PRELOAD", saved_ld_preload));
} else {
EXPECT_TRUE(env->UnSetVar("LD_PRELOAD"));
}
}
TEST(SetuidSandboxClient, SandboxedClientAPI) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment