Skip to content

Commit

Permalink
Remove deprecated sandbox::SandboxCompiler constructor
Browse files Browse the repository at this point in the history
Also tidy up test invocations.

Bug: 1315988
Change-Id: I05c09411bb711d30ce78d49c9fbcc5e0a4105708
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4083665
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1079985}
  • Loading branch information
rsesek authored and Chromium LUCI CQ committed Dec 6, 2022
1 parent 6826c31 commit 874d19f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 57 deletions.
3 changes: 2 additions & 1 deletion content/renderer/sandbox_mac_v2_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ void SetParametersForTest(sandbox::SandboxCompiler* compiler,
const std::string profile =
std::string(sandbox::policy::kSeatbeltPolicyString_common) +
sandbox::policy::kSeatbeltPolicyString_renderer;
sandbox::SandboxCompiler compiler(profile);
sandbox::SandboxCompiler compiler;
compiler.SetProfile(profile);

// Create the logging file and pass /bin/ls as the executable path.
base::ScopedTempDir temp_dir;
Expand Down
5 changes: 0 additions & 5 deletions sandbox/mac/sandbox_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ SandboxCompiler::SandboxCompiler(Target mode) : mode_(mode) {
}
}

SandboxCompiler::SandboxCompiler(const std::string& profile_str)
: SandboxCompiler(Target::kImmediate) {
SetProfile(profile_str);
}

SandboxCompiler::~SandboxCompiler() {}

void SandboxCompiler::SetProfile(const std::string& policy) {
Expand Down
8 changes: 0 additions & 8 deletions sandbox/mac/sandbox_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class SEATBELT_EXPORT SandboxCompiler {
// The result of compilation is a SandboxPolicy proto containing a sealed,
// compiled, binary sandbox policy that can be applied immediately.
kCompiled,

// The result of compilation is to be immediately applied to the current
// process using CompileAndApplyProfile().
kImmediate = kCompiled,
};

// Creates a compiler in the default mode, `Target::kSource`.
Expand All @@ -38,10 +34,6 @@ class SEATBELT_EXPORT SandboxCompiler {
// Creates a compiler with the specified target mode.
explicit SandboxCompiler(Target mode);

// Creates a compiler with the specified policy `profile_str` in
// `Target::kImmediate` mode.
explicit SandboxCompiler(const std::string& profile_str);

~SandboxCompiler();
SandboxCompiler(const SandboxCompiler& other) = delete;
SandboxCompiler& operator=(const SandboxCompiler& other) = delete;
Expand Down
65 changes: 24 additions & 41 deletions sandbox/mac/sandbox_compiler_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ class SandboxCompilerTest
};

MULTIPROCESS_TEST_MAIN(BasicProfileProcess) {
std::string profile =
"(version 1)"
"(deny default (with no-log))"
"(allow file-read* file-write* (literal \"/\"))";

SandboxCompiler compiler(GetParamInChild());
compiler.SetProfile(profile);
compiler.SetProfile(R"(
(version 1)
(deny default (with no-log))
(allow file-read* file-write* (literal "/"))
)");

std::string error;
CHECK(compiler.CompileAndApplyProfile(&error));
Expand All @@ -69,13 +68,12 @@ TEST_P(SandboxCompilerTest, BasicProfileTest) {
}

MULTIPROCESS_TEST_MAIN(BasicProfileWithParamProcess) {
std::string profile =
"(version 1)"
"(deny default (with no-log))"
"(allow file-read* file-write* (literal (param \"DIR\")))";

SandboxCompiler compiler(GetParamInChild());
compiler.SetProfile(profile);
compiler.SetProfile(R"(
(version 1)
(deny default (with no-log))
(allow file-read* file-write* (literal (param "DIR")))
)");
CHECK(compiler.SetParameter("DIR", "/"));

std::string error;
Expand All @@ -94,13 +92,12 @@ TEST_P(SandboxCompilerTest, BasicProfileTestWithParam) {
}

MULTIPROCESS_TEST_MAIN(ProfileFunctionalProcess) {
std::string profile =
"(version 1)"
"(deny default (with no-log))"
"(allow file-read-data file-read-metadata (literal \"/dev/urandom\"))";

SandboxCompiler compiler(GetParamInChild());
compiler.SetProfile(profile);
compiler.SetProfile(R"(
(version 1)
(deny default (with no-log))
(allow file-read-data file-read-metadata (literal "/dev/urandom"))
)");

std::string error;
CHECK(compiler.CompileAndApplyProfile(&error));
Expand All @@ -126,15 +123,14 @@ TEST_P(SandboxCompilerTest, ProfileFunctionalityTest) {
}

MULTIPROCESS_TEST_MAIN(ProfileFunctionalTestWithParamsProcess) {
std::string profile =
"(version 1)"
"(deny default (with no-log))"
"(if (string=? (param \"ALLOW_FILE\") \"TRUE\")"
" (allow file-read-data file-read-metadata (literal (param "
"\"URANDOM\"))))";

SandboxCompiler compiler(GetParamInChild());
compiler.SetProfile(profile);
compiler.SetProfile(R"(
(version 1)
(deny default (with no-log))
(if (string=? (param "ALLOW_FILE") "TRUE")
(allow file-read-data file-read-metadata (literal (param "URANDOM")))
)
)");

CHECK(compiler.SetBooleanParameter("ALLOW_FILE", true));
CHECK(!compiler.SetParameter("ALLOW_FILE", "duplicate key is not allowed"));
Expand Down Expand Up @@ -168,10 +164,8 @@ TEST_P(SandboxCompilerTest, ProfileFunctionalityTestWithParams) {
}

MULTIPROCESS_TEST_MAIN(ProfileFunctionalityTestErrorProcess) {
std::string profile = "(+ 5 a)";

SandboxCompiler compiler(GetParamInChild());
compiler.SetProfile(profile);
compiler.SetProfile("(+ 5 a)");

// Make sure that this invalid profile results in an error returned.
std::string error;
Expand Down Expand Up @@ -215,20 +209,9 @@ TEST_P(SandboxCompilerTest, DuplicateKeys) {
}
}

TEST_F(SandboxCompilerTest, DefaultConstructor) {
std::string profile =
R"((version 1) (deny default) (allow file-read* (path "/")))";
SandboxCompiler compiler(profile);
absl::optional<mac::SandboxPolicy> policy =
compiler.CompilePolicyToProto(nullptr);
ASSERT_TRUE(policy.has_value());
EXPECT_FALSE(policy->compiled().data().empty());
}

INSTANTIATE_TEST_SUITE_P(Target,
SandboxCompilerTest,
testing::Values(SandboxCompiler::Target::kSource,
SandboxCompiler::Target::kCompiled,
SandboxCompiler::Target::kImmediate));
SandboxCompiler::Target::kCompiled));

} // namespace sandbox
6 changes: 4 additions & 2 deletions sandbox/mac/seatbelt_extension_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ TEST_F(SeatbeltExtensionTest, FileReadAccess) {
}

MULTIPROCESS_TEST_MAIN(FileReadAccess) {
sandbox::SandboxCompiler compiler(kSandboxProfile);
sandbox::SandboxCompiler compiler;
compiler.SetProfile(kSandboxProfile);
std::string error;
CHECK(compiler.CompileAndApplyProfile(&error)) << error;

Expand Down Expand Up @@ -166,7 +167,8 @@ TEST_F(SeatbeltExtensionTest, DirReadWriteAccess) {
}

MULTIPROCESS_TEST_MAIN(DirReadWriteAccess) {
sandbox::SandboxCompiler compiler(kSandboxProfile);
sandbox::SandboxCompiler compiler;
compiler.SetProfile(kSandboxProfile);
std::string error;
CHECK(compiler.CompileAndApplyProfile(&error)) << error;

Expand Down

0 comments on commit 874d19f

Please sign in to comment.