secupdater 0.1.0 → 0.2.0alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1d028b501eb99bb427b8863f56293be6f04daabae1c87245d9aa22364998846e
|
|
4
|
+
data.tar.gz: c8d35b92bcbe9844bc0757f2ec92d054eea94e23df307b060ca3b79b98a5592f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 73464dc3adb67b6ca401ac62fe507b2dc8365daf48b99d862e6843a2bdae5939e1a13e747c8eaac85de9ea2ddea0f9bcc85287359e11c168177c778322f5a69d
|
|
7
|
+
data.tar.gz: 3f4d5a0ca4b2c5e0c91c9dd0a34d066daeae1f4b91ca218c981cd81da62b41ea0e6f27d3bebf014d1d098933a60d9fe3651b8d3f3863ea030ef80ad8a367b7c1
|
|
@@ -5,6 +5,8 @@ require "bundler"
|
|
|
5
5
|
module Secupdater
|
|
6
6
|
class Ecosystem
|
|
7
7
|
class Rubygems < Secupdater::Ecosystem
|
|
8
|
+
FROZEN_EXIT_CODE = 16
|
|
9
|
+
|
|
8
10
|
def self.ecosystem_name = "RubyGems"
|
|
9
11
|
|
|
10
12
|
def manifest_paths = ["Gemfile.lock"]
|
|
@@ -30,7 +32,11 @@ module Secupdater
|
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
def run_update(names, level)
|
|
33
|
-
output, status = Open3.capture2e("bundle", "update", *Array(names), "--conservative", "--#{level}", "--strict")
|
|
35
|
+
output, status = Open3.capture2e({ "BUNDLE_FROZEN" => "false" }, "bundle", "update", *Array(names), "--conservative", "--#{level}", "--strict")
|
|
36
|
+
|
|
37
|
+
if status.exitstatus == FROZEN_EXIT_CODE
|
|
38
|
+
raise Secupdater::Error, "bundle update can't change Gemfile.lock (is BUNDLE_DEPLOYMENT set?)\n#{output}"
|
|
39
|
+
end
|
|
34
40
|
|
|
35
41
|
unless status.success?
|
|
36
42
|
raise Secupdater::UpdateCommandFailed.new(
|
data/lib/secupdater/update.rb
CHANGED
|
@@ -26,11 +26,13 @@ module Secupdater
|
|
|
26
26
|
|
|
27
27
|
status = message = nil
|
|
28
28
|
|
|
29
|
-
ecosystem.update_levels
|
|
29
|
+
levels = ecosystem.update_levels
|
|
30
|
+
|
|
31
|
+
levels.each do |level|
|
|
30
32
|
status, message = attempt_update(dep, advisories, level)
|
|
31
33
|
return status unless message
|
|
32
34
|
|
|
33
|
-
logger.debug "#{level} update: #{message}"
|
|
35
|
+
logger.debug "#{level} update: #{message}" unless level == levels.last
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
if status == :failed
|
data/lib/secupdater/version.rb
CHANGED
|
@@ -137,10 +137,10 @@ RSpec.describe Secupdater::Ecosystem::Rubygems do
|
|
|
137
137
|
end
|
|
138
138
|
end
|
|
139
139
|
|
|
140
|
-
it "runs a strict, conservative bundle update at the given level" do
|
|
140
|
+
it "runs a strict, conservative, unfrozen bundle update at the given level" do
|
|
141
141
|
rubygems.try_update("css_parser", level: :minor)
|
|
142
142
|
|
|
143
|
-
expect(Open3).to have_received(:capture2e).with("bundle", "update", "css_parser", "--conservative", "--minor", "--strict")
|
|
143
|
+
expect(Open3).to have_received(:capture2e).with({ "BUNDLE_FROZEN" => "false" }, "bundle", "update", "css_parser", "--conservative", "--minor", "--strict")
|
|
144
144
|
end
|
|
145
145
|
|
|
146
146
|
it "returns the lockfile change with its new and original content" do
|
|
@@ -164,7 +164,7 @@ RSpec.describe Secupdater::Ecosystem::Rubygems do
|
|
|
164
164
|
it "passes it as a single argument without going through a shell" do
|
|
165
165
|
rubygems.try_update("css_parser; touch pwned", level: :patch)
|
|
166
166
|
|
|
167
|
-
expect(Open3).to have_received(:capture2e).with("bundle", "update", "css_parser; touch pwned", "--conservative", "--patch", "--strict")
|
|
167
|
+
expect(Open3).to have_received(:capture2e).with({ "BUNDLE_FROZEN" => "false" }, "bundle", "update", "css_parser; touch pwned", "--conservative", "--patch", "--strict")
|
|
168
168
|
end
|
|
169
169
|
end
|
|
170
170
|
|
|
@@ -180,5 +180,18 @@ RSpec.describe Secupdater::Ecosystem::Rubygems do
|
|
|
180
180
|
end
|
|
181
181
|
end
|
|
182
182
|
end
|
|
183
|
+
|
|
184
|
+
context "command exits 16 (frozen lockfile)" do
|
|
185
|
+
let(:status) { instance_double(Process::Status, success?: false, exitstatus: 16) }
|
|
186
|
+
|
|
187
|
+
before { allow(Open3).to receive(:capture2e).and_return(["frozen mode is set", status]) }
|
|
188
|
+
|
|
189
|
+
it "raises Secupdater::Error rather than UpdateCommandFailed, so the run stops" do
|
|
190
|
+
expect { rubygems.try_update("css_parser", level: :patch) }.to raise_error(Secupdater::Error) do
|
|
191
|
+
expect(it).not_to be_a(Secupdater::UpdateCommandFailed)
|
|
192
|
+
expect(it.message).to include("frozen mode is set")
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
end
|
|
183
196
|
end
|
|
184
197
|
end
|
|
@@ -5,7 +5,7 @@ require "stringio"
|
|
|
5
5
|
require "tmpdir"
|
|
6
6
|
|
|
7
7
|
module UpdateSpec
|
|
8
|
-
# outcomes: gem name => version try_update moves it to, :unchanged or :
|
|
8
|
+
# outcomes: gem name => version try_update moves it to, :unchanged, :fail or :abort, or a hash of those by level
|
|
9
9
|
class FakeEcosystem
|
|
10
10
|
LOCKFILE = "Gemfile.lock"
|
|
11
11
|
|
|
@@ -40,6 +40,8 @@ module UpdateSpec
|
|
|
40
40
|
case outcome
|
|
41
41
|
when :fail
|
|
42
42
|
raise Secupdater::UpdateCommandFailed.new("bundle update failed", 1, "could not resolve #{name}")
|
|
43
|
+
when :abort
|
|
44
|
+
raise Secupdater::Error, "lockfile is frozen"
|
|
43
45
|
when :unchanged
|
|
44
46
|
[]
|
|
45
47
|
else
|
|
@@ -241,6 +243,30 @@ RSpec.describe Secupdater::Update do
|
|
|
241
243
|
expect(update.call([advisory("rack", "cve/1")])).to eq("rack" => :failed)
|
|
242
244
|
expect(ecosystem.attempts.map(&:last)).to eq([:patch, :minor, :major])
|
|
243
245
|
end
|
|
246
|
+
|
|
247
|
+
it "logs the last level's failure once, as an error" do
|
|
248
|
+
update.call([advisory("rack", "cve/1")])
|
|
249
|
+
|
|
250
|
+
expect(log.string.scan(/could not resolve rack/).length).to eq(3)
|
|
251
|
+
expect(log.string).not_to include("major update:")
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
context "an error that isn't an update failure" do
|
|
256
|
+
let(:outcomes) { { "rack" => :abort, "nokogiri" => "2.0" } }
|
|
257
|
+
|
|
258
|
+
it "stops the run without trying other levels or gems" do
|
|
259
|
+
expect { update.call([advisory("rack", "cve/1"), advisory("nokogiri", "cve/2")]) }
|
|
260
|
+
.to raise_error(Secupdater::Error, "lockfile is frozen")
|
|
261
|
+
|
|
262
|
+
expect(ecosystem.attempts).to eq([["rack", :patch]])
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
it "leaves the lockfile as it found it" do
|
|
266
|
+
expect { update.call([advisory("rack", "cve/1")]) }.to raise_error(Secupdater::Error)
|
|
267
|
+
|
|
268
|
+
expect(lockfile_on_disk).to eq(lockfile)
|
|
269
|
+
end
|
|
244
270
|
end
|
|
245
271
|
|
|
246
272
|
context "a mix of outcomes" do
|