Skip to content

Commit

Permalink
Add test coverage for jordansissel#607 (safesystem w/ no $SHELL)
Browse files Browse the repository at this point in the history
Also: Add missing SecureRandom.uuid under 1.8.x (for the tests)
  • Loading branch information
jls committed Feb 5, 2014
1 parent a536649 commit f8c7b24
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/fpm/package/dir_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
require "fpm/package/dir" # local
require "stud/temporary"

if RUBY_VERSION =~ /^1\.8/
# The following method copied from ruby 1.9.3
module SecureRandom
def self.uuid
ary = self.random_bytes(16).unpack("NnnnnN")
ary[2] = (ary[2] & 0x0fff) | 0x4000
ary[3] = (ary[3] & 0x3fff) | 0x8000
"%08x-%04x-%04x-%04x-%04x%08x" % ary
end
end
end

describe FPM::Package::Dir do
let(:tmpdir) { Stud::Temporary.directory("tmpdir") }
let(:output) { Stud::Temporary.directory("output") }
Expand Down
54 changes: 54 additions & 0 deletions spec/fpm/util_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require "spec_setup"
require "fpm" # local

describe FPM::Util do
subject do
Class.new do
include FPM::Util
def initialize
@logger = Cabin::Channel.new
end
end.new
end

describe "#safe_system" do
context "with a missing $SHELL" do
before do
@orig_shell = ENV["SHELL"]
ENV.delete("SHELL")
end

after do
ENV["SHELL"] = @orig_shell unless @orig_shell.nil?
end

it "should assume /bin/sh" do
insist { subject.default_shell } == "/bin/sh"
end

it "should still run commands correctly" do
# This will raise an exception if we can't run it at all.
subject.safesystem("true")
end
end
context "with $SHELL set to an empty string" do
before do
@orig_shell = ENV["SHELL"]
ENV["SHELL"] = ""
end

after do
ENV["SHELL"] = @orig_shell unless @orig_shell.nil?
end

it "should assume /bin/sh" do
insist { subject.default_shell } == "/bin/sh"
end

it "should still run commands correctly" do
# This will raise an exception if we can't run it at all.
subject.safesystem("true")
end
end
end
end

0 comments on commit f8c7b24

Please sign in to comment.