Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Unified Diff: sandbox/linux/suid/client/setuid_sandbox_client_unittest.cc

Issue 10823251: Setuid sandbox unittest: fix environment. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/linux/suid/client/setuid_sandbox_client_unittest.cc
diff --git a/sandbox/linux/suid/client/setuid_sandbox_client_unittest.cc b/sandbox/linux/suid/client/setuid_sandbox_client_unittest.cc
index 764ccb10f68e3ff9f189e39ddf14948824e61e21..135e7fc07807918bd83b8b15528fb88e94c0e011 100644
--- a/sandbox/linux/suid/client/setuid_sandbox_client_unittest.cc
+++ b/sandbox/linux/suid/client/setuid_sandbox_client_unittest.cc
@@ -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) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698