mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 05:58:19 +08:00
DEV: Raise exception when execute_command will spawn a shell (#12716)
This commit is contained in:
@ -438,6 +438,21 @@ describe Discourse do
|
||||
has_checked_chdir = true
|
||||
thread.join
|
||||
end
|
||||
|
||||
it "raises error for unsafe shell" do
|
||||
expect(Discourse::Utils.execute_command("pwd").strip).to eq(Rails.root.to_s)
|
||||
|
||||
expect do
|
||||
Discourse::Utils.execute_command("echo a b c")
|
||||
end.to raise_error(RuntimeError)
|
||||
|
||||
expect do
|
||||
Discourse::Utils.execute_command({ "ENV1" => "VAL" }, "echo a b c")
|
||||
end.to raise_error(RuntimeError)
|
||||
|
||||
expect(Discourse::Utils.execute_command("echo", "a", "b", "c").strip).to eq("a b c")
|
||||
expect(Discourse::Utils.execute_command("echo a b c", unsafe_shell: true).strip).to eq("a b c")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user