secupdater 0.8.0 → 0.9.0

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.release-please-manifest.json +1 -1
  3. data/CHANGELOG.md +16 -0
  4. data/examples/central-project/.gitlab-ci.yml +87 -33
  5. data/lib/secupdater/cli.rb +1 -1
  6. data/lib/secupdater/ecosystem/rubygems.rb +7 -0
  7. data/lib/secupdater/ecosystem.rb +34 -4
  8. data/lib/secupdater/executor.rb +10 -8
  9. data/lib/secupdater/publisher/gitlab.rb +29 -11
  10. data/lib/secupdater/publisher.rb +7 -8
  11. data/lib/secupdater/update.rb +3 -5
  12. data/lib/secupdater/version.rb +1 -1
  13. data/lib/secupdater/yarn_support/audit.rb +86 -0
  14. data/lib/secupdater/yarn_support/lockfile.rb +79 -0
  15. data/lib/secupdater/yarn_support/package_name.rb +14 -0
  16. data/lib/secupdater/yarn_support/range.rb +152 -0
  17. data/lib/secupdater/yarn_support/version.rb +65 -0
  18. data/lib/secupdater.rb +4 -2
  19. data/spec/fixtures/yarn/audit.ndjson +9 -0
  20. data/spec/fixtures/yarn/protocols.yarn.lock +99 -0
  21. data/spec/fixtures/yarn/yarn.lock +265 -0
  22. data/spec/fixtures/yarn/yarn1.lock +8 -0
  23. data/spec/secupdater/cli_spec.rb +11 -0
  24. data/spec/secupdater/ecosystem/rubygems_spec.rb +40 -0
  25. data/spec/secupdater/ecosystem_spec.rb +71 -0
  26. data/spec/secupdater/executor_spec.rb +23 -5
  27. data/spec/secupdater/publisher/gitlab_spec.rb +85 -14
  28. data/spec/secupdater/update_spec.rb +22 -9
  29. data/spec/secupdater/yarn_support/audit_spec.rb +144 -0
  30. data/spec/secupdater/yarn_support/lockfile_spec.rb +171 -0
  31. data/spec/secupdater/yarn_support/package_name_spec.rb +40 -0
  32. data/spec/secupdater/yarn_support/range_spec.rb +158 -0
  33. data/spec/secupdater/yarn_support/version_spec.rb +61 -0
  34. data/spec/secupdater_spec.rb +9 -0
  35. metadata +15 -1
@@ -0,0 +1,171 @@
1
+ require "secupdater"
2
+ require "secupdater/yarn_support/lockfile"
3
+
4
+ RSpec.describe Secupdater::YarnSupport::Lockfile do
5
+ def fixture(name) = File.read(File.expand_path("../../fixtures/yarn/#{name}", __dir__))
6
+
7
+ def entry(key, resolution, version = "1.0.0")
8
+ <<~ENTRY
9
+ #{key.inspect}:
10
+ version: #{version}
11
+ resolution: #{resolution.inspect}
12
+ languageName: node
13
+ linkType: hard
14
+
15
+ ENTRY
16
+ end
17
+
18
+ def lockfile(*entries) = "__metadata:\n version: 8\n cacheKey: 10c0\n\n#{entries.join}"
19
+
20
+ describe "a real workspace lockfile" do
21
+ subject(:parsed) { described_class.parse(fixture("yarn.lock")) }
22
+
23
+ it "lists every npm package with its locked versions" do
24
+ expect(parsed.versions).to eq(
25
+ "@babel/code-frame" => ["7.29.7"],
26
+ "@babel/generator" => ["7.29.16"],
27
+ "@babel/helper-environment-visitor" => ["7.24.7"],
28
+ "@babel/helper-function-name" => ["7.24.7"],
29
+ "@babel/helper-hoist-variables" => ["7.24.7"],
30
+ "@babel/helper-split-export-declaration" => ["7.24.7"],
31
+ "@babel/helper-string-parser" => ["7.29.15"],
32
+ "@babel/helper-validator-identifier" => ["7.29.7"],
33
+ "@babel/parser" => ["7.29.15"],
34
+ "@babel/template" => ["7.29.7"],
35
+ "@babel/traverse" => ["7.22.0"],
36
+ "@babel/types" => ["7.29.15"],
37
+ "@jridgewell/gen-mapping" => ["0.3.13"],
38
+ "@jridgewell/resolve-uri" => ["3.1.3"],
39
+ "@jridgewell/sourcemap-codec" => ["1.6.0"],
40
+ "@jridgewell/trace-mapping" => ["0.3.31"],
41
+ "debug" => ["4.4.3"],
42
+ "globals" => ["11.12.0"],
43
+ "js-tokens" => ["4.0.0"],
44
+ "jsesc" => ["3.1.0"],
45
+ "lodash" => ["4.17.15"],
46
+ "minimist" => ["0.0.8", "1.2.5"],
47
+ "mkdirp" => ["0.5.1"],
48
+ "ms" => ["2.1.3"],
49
+ "picocolors" => ["1.1.1"],
50
+ )
51
+ end
52
+
53
+ it "lists the workspaces, root as ." do
54
+ expect(parsed.workspaces).to eq([".", "packages/a"])
55
+ end
56
+ end
57
+
58
+ describe "a lockfile using other protocols" do
59
+ subject(:parsed) { described_class.parse(fixture("protocols.yarn.lock")) }
60
+
61
+ it "keeps npm packages, aliases under their real name, and builtin patches once" do
62
+ expect(parsed.versions).to eq(
63
+ "JSONStream" => ["1.3.5"],
64
+ "jsonparse" => ["1.3.1"],
65
+ "lodash" => ["4.17.21"],
66
+ "through" => ["2.3.8"],
67
+ "typescript" => ["5.4.5"],
68
+ )
69
+ end
70
+
71
+ it "skips git, file, link and portal packages" do
72
+ expect(parsed.versions.keys).not_to include("is-number", "local-dep", "linked", "portaled")
73
+ end
74
+
75
+ it "has only the root workspace" do
76
+ expect(parsed.workspaces).to eq(["."])
77
+ end
78
+ end
79
+
80
+ it "takes a patched package's name and version from the entry" do
81
+ parsed = described_class.parse(lockfile(
82
+ entry("left-pad@patch:left-pad@npm%3A1.3.0#~/.yarn/patches/left-pad-npm-1.3.0-abc.patch",
83
+ "left-pad@patch:left-pad@npm%3A1.3.0#~/.yarn/patches/left-pad-npm-1.3.0-abc.patch::version=1.3.0&hash=1a2b3c",
84
+ "1.3.0"),
85
+ entry("@scope/pkg@patch:@scope/pkg@npm%3A2.0.0#~/.yarn/patches/x.patch",
86
+ "@scope/pkg@patch:@scope/pkg@npm%3A2.0.0#~/.yarn/patches/x.patch::version=2.0.0&hash=4d5e6f",
87
+ "2.0.0"),
88
+ ))
89
+
90
+ expect(parsed.versions).to eq("left-pad" => ["1.3.0"], "@scope/pkg" => ["2.0.0"])
91
+ end
92
+
93
+ it "skips a patch of a git package" do
94
+ parsed = described_class.parse(lockfile(
95
+ entry("pkg@patch:pkg@https://github.com/o/pkg.git#x.patch",
96
+ "pkg@patch:pkg@https%3A//github.com/o/pkg.git%23commit=abc#~/.yarn/patches/x.patch::version=1.0.0&hash=1"),
97
+ ))
98
+
99
+ expect(parsed.versions).to eq({})
100
+ end
101
+
102
+ it "skips exec packages" do
103
+ parsed = described_class.parse(lockfile(entry("gen@exec:./gen.js", "gen@exec:./gen.js::hash=1&locator=root%40workspace%3A.")))
104
+
105
+ expect(parsed.versions).to eq({})
106
+ end
107
+
108
+ it "sorts versions by semver, not as strings" do
109
+ parsed = described_class.parse(lockfile(
110
+ entry("ms@npm:^2.1.10", "ms@npm:2.1.10", "2.1.10"),
111
+ entry("ms@npm:^2.1.9", "ms@npm:2.1.9", "2.1.9"),
112
+ entry("ms@npm:2.1.9-beta.1", "ms@npm:2.1.9-beta.1", "2.1.9-beta.1"),
113
+ ))
114
+
115
+ expect(parsed.versions).to eq("ms" => ["2.1.9-beta.1", "2.1.9", "2.1.10"])
116
+ end
117
+
118
+ it "accepts an empty lockfile" do
119
+ parsed = described_class.parse(lockfile)
120
+
121
+ expect([parsed.versions, parsed.workspaces]).to eq([{}, []])
122
+ end
123
+
124
+ it "raises on a Yarn 1 lockfile" do
125
+ expect { described_class.parse(fixture("yarn1.lock")) }.to raise_error(Secupdater::Error, /Berry/)
126
+ end
127
+
128
+ ["", "- a\n- b\n", "key: [unclosed\n", "__metadata: &a {}\nx: *a\n", "--- !ruby/object:Object {}\n"].each do |text|
129
+ it "raises a Secupdater::Error on #{text.inspect}" do
130
+ expect { described_class.parse(text) }.to raise_error(Secupdater::Error)
131
+ end
132
+ end
133
+
134
+ it "raises on an entry without a resolution" do
135
+ expect { described_class.parse(lockfile("\"ms@npm:^2\":\n version: 2.1.3\n")) }
136
+ .to raise_error(Secupdater::Error, /ms@npm:\^2/)
137
+ end
138
+
139
+ it "raises on an entry that isn't a mapping" do
140
+ expect { described_class.parse(lockfile("\"ms@npm:^2\": nope\n")) }.to raise_error(Secupdater::Error, /ms@npm:\^2/)
141
+ end
142
+
143
+ [
144
+ ["--force@npm:1.0.0", "--force"],
145
+ ["Evil Name@npm:1.0.0", "Evil Name"],
146
+ ["a..b@npm:1.0.0", "a..b"],
147
+ ["@scope/../x@npm:1.0.0", "@scope/../x"],
148
+ ["nameless", "nameless"],
149
+ ].each do |resolution, name|
150
+ it "raises naming the bad package name in #{resolution.inspect}" do
151
+ expect { described_class.parse(lockfile(entry("x@npm:1", resolution))) }
152
+ .to raise_error(Secupdater::Error, /#{Regexp.escape(name.inspect)}/)
153
+ end
154
+ end
155
+
156
+ ["1.0.0\n--force", "latest", "1.0", 1].each do |version|
157
+ it "raises on the npm version #{version.inspect}" do
158
+ text = lockfile("\"ms@npm:^1\":\n version: #{version.inspect}\n resolution: \"ms@npm:1.0.0\"\n")
159
+
160
+ expect { described_class.parse(text) }.to raise_error(Secupdater::Error)
161
+ end
162
+ end
163
+
164
+ ["/etc", "../outside", "packages/../../x", ""].each do |path|
165
+ it "raises on the workspace path #{path.inspect}" do
166
+ text = lockfile(entry("w@workspace:#{path}", "w@workspace:#{path}", "0.0.0-use.local"))
167
+
168
+ expect { described_class.parse(text) }.to raise_error(Secupdater::Error, /#{Regexp.escape(path.inspect)}/)
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,40 @@
1
+ require "secupdater"
2
+ require "secupdater/yarn_support/package_name"
3
+
4
+ RSpec.describe Secupdater::YarnSupport do
5
+ describe "NAME_PATTERN" do
6
+ %w[lodash left-pad @babel/core @types/node lodash.merge socket.io a_b JSONStream 7zip @0x/utils].each do |name|
7
+ it "accepts #{name}" do
8
+ expect(name).to match(Secupdater::YarnSupport::NAME_PATTERN)
9
+ end
10
+ end
11
+
12
+ [
13
+ "", "-rf", "--force", ".hidden", "_private", "@scope/.x", "@-scope/x", "@scope/", "@/x", "scope/x", "@a/b/c",
14
+ "has space", "a..b", "a~b", "a*b", "a(b)", "a'b", "a!b", "a:b", "café", "x\n--force", "\nx", "x\n",
15
+ ].each do |name|
16
+ it "rejects #{name.inspect}" do
17
+ expect(name).not_to match(Secupdater::YarnSupport::NAME_PATTERN)
18
+ end
19
+ end
20
+
21
+ it "rejects names over npm's 214 character limit" do
22
+ expect("a" * 214).to match(Secupdater::YarnSupport::NAME_PATTERN)
23
+ expect("a" * 215).not_to match(Secupdater::YarnSupport::NAME_PATTERN)
24
+ end
25
+ end
26
+
27
+ describe ".check_name!" do
28
+ it "returns a good name" do
29
+ expect(described_class.check_name!("@babel/core")).to eq("@babel/core")
30
+ end
31
+
32
+ it "raises naming a bad one" do
33
+ expect { described_class.check_name!("--force") }.to raise_error(Secupdater::Error, /"--force"/)
34
+ end
35
+
36
+ it "raises on a non-string" do
37
+ expect { described_class.check_name!(nil) }.to raise_error(Secupdater::Error, /nil/)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,158 @@
1
+ require "secupdater"
2
+ require "secupdater/yarn_support/range"
3
+
4
+ module RangeSpec
5
+ POOL = %w[
6
+ 0.0.0-0 0.0.0 0.0.1 0.0.2 0.0.3 0.0.4-rc.1 0.1.0-0 0.1.0
7
+ 0.2.3 0.2.4 0.3.0-0 0.3.0 1.0.0-alpha 1.0.0 1.1.0 1.2.0-rc.1
8
+ 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0
9
+ 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0
10
+ 2.0.0-alpha 2.0.0 2.3.4 2.3.5-0 2.3.5 2.4.0 2.9.9 3.0.0-0
11
+ 3.0.0 4.17.19 4.17.21 10.0.0
12
+ ].freeze
13
+
14
+ # Generated with node-semver 7.7.2: satisfies(version, range, { includePrerelease: true })
15
+ INCLUDED = {
16
+ ">=1.2.3" => %w[1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha 2.0.0 2.3.4 2.3.5-0 2.3.5 2.4.0 2.9.9 3.0.0-0 3.0.0 4.17.19 4.17.21 10.0.0],
17
+ "<1.2.3" => %w[0.0.0-0 0.0.0 0.0.1 0.0.2 0.0.3 0.0.4-rc.1 0.1.0-0 0.1.0 0.2.3 0.2.4 0.3.0-0 0.3.0 1.0.0-alpha 1.0.0 1.1.0 1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2],
18
+ ">1.2.3" => %w[1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha 2.0.0 2.3.4 2.3.5-0 2.3.5 2.4.0 2.9.9 3.0.0-0 3.0.0 4.17.19 4.17.21 10.0.0],
19
+ "<=1.2.3" => %w[0.0.0-0 0.0.0 0.0.1 0.0.2 0.0.3 0.0.4-rc.1 0.1.0-0 0.1.0 0.2.3 0.2.4 0.3.0-0 0.3.0 1.0.0-alpha 1.0.0 1.1.0 1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5],
20
+ "=1.2.3" => %w[1.2.3 1.2.3+build.5],
21
+ "1.2.3" => %w[1.2.3 1.2.3+build.5],
22
+ "v1.2.3" => %w[1.2.3 1.2.3+build.5],
23
+ "=v1.2.3" => %w[1.2.3 1.2.3+build.5],
24
+ ">= 1.2.3" => %w[1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha 2.0.0 2.3.4 2.3.5-0 2.3.5 2.4.0 2.9.9 3.0.0-0 3.0.0 4.17.19 4.17.21 10.0.0],
25
+ " >=1.2.3 <2 " => %w[1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9],
26
+ "1.2.3+build" => %w[1.2.3 1.2.3+build.5],
27
+ ">=1.2.3-rc.1" => %w[1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha 2.0.0 2.3.4 2.3.5-0 2.3.5 2.4.0 2.9.9 3.0.0-0 3.0.0 4.17.19 4.17.21 10.0.0],
28
+ ">=1.2.3 <2.0.0" => %w[1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha],
29
+ ">1.2.3 <1.2.3" => %w[],
30
+ "1.2.3 2.0.0" => %w[],
31
+ "1.2.3 - 2.3.4" => %w[1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha 2.0.0 2.3.4],
32
+ "1.2 - 2.3.4" => %w[1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha 2.0.0 2.3.4],
33
+ "1.2.3 - 2.3" => %w[1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha 2.0.0 2.3.4 2.3.5-0 2.3.5],
34
+ "1.2.3 - 2" => %w[1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha 2.0.0 2.3.4 2.3.5-0 2.3.5 2.4.0 2.9.9],
35
+ "1.2.3-alpha - 2.3.4-0" => %w[1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha 2.0.0],
36
+ "* - 2" => %w[0.0.0-0 0.0.0 0.0.1 0.0.2 0.0.3 0.0.4-rc.1 0.1.0-0 0.1.0 0.2.3 0.2.4 0.3.0-0 0.3.0 1.0.0-alpha 1.0.0 1.1.0 1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha 2.0.0 2.3.4 2.3.5-0 2.3.5 2.4.0 2.9.9],
37
+ "*" => :all,
38
+ "" => :all,
39
+ "x" => :all,
40
+ "X" => :all,
41
+ "1.x" => %w[1.0.0-alpha 1.0.0 1.1.0 1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9],
42
+ "1.X" => %w[1.0.0-alpha 1.0.0 1.1.0 1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9],
43
+ "1.2.x" => %w[1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9],
44
+ "1.2.*" => %w[1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9],
45
+ "1.x.x" => %w[1.0.0-alpha 1.0.0 1.1.0 1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9],
46
+ "1" => %w[1.0.0-alpha 1.0.0 1.1.0 1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9],
47
+ "1.2" => %w[1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9],
48
+ "<=1.2" => %w[0.0.0-0 0.0.0 0.0.1 0.0.2 0.0.3 0.0.4-rc.1 0.1.0-0 0.1.0 0.2.3 0.2.4 0.3.0-0 0.3.0 1.0.0-alpha 1.0.0 1.1.0 1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9],
49
+ "<1.2" => %w[0.0.0-0 0.0.0 0.0.1 0.0.2 0.0.3 0.0.4-rc.1 0.1.0-0 0.1.0 0.2.3 0.2.4 0.3.0-0 0.3.0 1.0.0-alpha 1.0.0 1.1.0],
50
+ ">1.x" => %w[2.0.0-0 2.0.0-alpha 2.0.0 2.3.4 2.3.5-0 2.3.5 2.4.0 2.9.9 3.0.0-0 3.0.0 4.17.19 4.17.21 10.0.0],
51
+ ">1.2" => %w[1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha 2.0.0 2.3.4 2.3.5-0 2.3.5 2.4.0 2.9.9 3.0.0-0 3.0.0 4.17.19 4.17.21 10.0.0],
52
+ ">=1.2" => %w[1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha 2.0.0 2.3.4 2.3.5-0 2.3.5 2.4.0 2.9.9 3.0.0-0 3.0.0 4.17.19 4.17.21 10.0.0],
53
+ "<=1" => %w[0.0.0-0 0.0.0 0.0.1 0.0.2 0.0.3 0.0.4-rc.1 0.1.0-0 0.1.0 0.2.3 0.2.4 0.3.0-0 0.3.0 1.0.0-alpha 1.0.0 1.1.0 1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9],
54
+ ">*" => %w[],
55
+ "<*" => %w[],
56
+ "=1.x" => %w[1.0.0-alpha 1.0.0 1.1.0 1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9],
57
+ "~1.2.3" => %w[1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9],
58
+ "~1.2" => %w[1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9],
59
+ "~1" => %w[1.0.0 1.1.0 1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9],
60
+ "~0.2.3" => %w[0.2.3 0.2.4],
61
+ "~0.2" => %w[0.2.3 0.2.4],
62
+ "~0" => %w[0.0.0 0.0.1 0.0.2 0.0.3 0.0.4-rc.1 0.1.0-0 0.1.0 0.2.3 0.2.4 0.3.0-0 0.3.0],
63
+ "~1.2.3-beta.2" => %w[1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9],
64
+ "~>1.2.3" => %w[1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9],
65
+ "~ 1.2.3" => %w[1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9],
66
+ "^1.2.3" => %w[1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9],
67
+ "^0.2.3" => %w[0.2.3 0.2.4],
68
+ "^0.0.3" => %w[0.0.3],
69
+ "^1.2.3-beta.2" => %w[1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9],
70
+ "^0.0.3-beta" => %w[0.0.3],
71
+ "^1.2.x" => %w[1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9],
72
+ "^0.0.x" => %w[0.0.0-0 0.0.0 0.0.1 0.0.2 0.0.3 0.0.4-rc.1],
73
+ "^0.0" => %w[0.0.0-0 0.0.0 0.0.1 0.0.2 0.0.3 0.0.4-rc.1],
74
+ "^1.x" => %w[1.0.0-alpha 1.0.0 1.1.0 1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9],
75
+ "^0.x" => %w[0.0.0-0 0.0.0 0.0.1 0.0.2 0.0.3 0.0.4-rc.1 0.1.0-0 0.1.0 0.2.3 0.2.4 0.3.0-0 0.3.0],
76
+ "^ 1.2.3" => %w[1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9],
77
+ "^*" => :all,
78
+ "<0.2.4 || >=1.0.0 <1.2.6" => %w[0.0.0-0 0.0.0 0.0.1 0.0.2 0.0.3 0.0.4-rc.1 0.1.0-0 0.1.0 0.2.3 1.0.0 1.1.0 1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1],
79
+ "1.2.7 || >=1.2.9 <2.0.0" => %w[1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha],
80
+ ">=4.0.0 <=4.17.22" => %w[4.17.19 4.17.21],
81
+ "<0.0.0-0" => %w[],
82
+ ">=0.0.0" => %w[0.0.0 0.0.1 0.0.2 0.0.3 0.0.4-rc.1 0.1.0-0 0.1.0 0.2.3 0.2.4 0.3.0-0 0.3.0 1.0.0-alpha 1.0.0 1.1.0 1.2.0-rc.1 1.2.0 1.2.2 1.2.3-alpha 1.2.3-alpha.7 1.2.3-beta.2 1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9 2.0.0-0 2.0.0-alpha 2.0.0 2.3.4 2.3.5-0 2.3.5 2.4.0 2.9.9 3.0.0-0 3.0.0 4.17.19 4.17.21 10.0.0],
83
+ "~1.2.3 ^2" => %w[],
84
+ "||" => :all,
85
+ "1.2.3 ||" => :all,
86
+ ">=1.2.3\n<2" => %w[1.2.3 1.2.3+build.5 1.2.4-0 1.2.4 1.2.6-rc.1 1.2.6 1.2.9 1.3.0-0 1.3.0 1.9.9],
87
+ }.freeze
88
+
89
+ # node-semver throws on these too
90
+ INVALID = [
91
+ "foo",
92
+ ">=1.2.3 <foo",
93
+ "01.2.3",
94
+ "1.2.03",
95
+ "^01.2.3",
96
+ "1.2.3.4",
97
+ "1.2.3-",
98
+ "1.2.3 - ",
99
+ "1.2.3 - 2.3.4 - 3",
100
+ "1.2.3 -2.3.4",
101
+ "1.2.3- 2.3.4",
102
+ "<>1.2.3",
103
+ ">=>1.2",
104
+ "! 1.2.3",
105
+ "latest",
106
+ "1.2.3 | 2.0.0",
107
+ ].freeze
108
+ end
109
+
110
+ RSpec.describe Secupdater::YarnSupport::Range do
111
+ RangeSpec::INCLUDED.each do |range, included|
112
+ it "matches node-semver for #{range.inspect}" do
113
+ expected = included == :all ? RangeSpec::POOL : included
114
+ actual = RangeSpec::POOL.select { described_class.new(range).include?(it) }
115
+
116
+ expect(actual).to eq(expected)
117
+ end
118
+ end
119
+
120
+ RangeSpec::INVALID.each do |range|
121
+ it "raises naming #{range.inspect}" do
122
+ expect { described_class.new(range) }
123
+ .to raise_error(Secupdater::Error, /#{Regexp.escape(range.inspect)}/)
124
+ end
125
+ end
126
+
127
+ # Not node-semver errors, but we'd rather refuse than guess at an advisory range
128
+ ["~=1.2.3", ">==1.2.3"].each do |range|
129
+ it "refuses the unusual spelling #{range.inspect}" do
130
+ expect { described_class.new(range) }.to raise_error(Secupdater::Error, /#{Regexp.escape(range.inspect)}/)
131
+ end
132
+ end
133
+
134
+ { "~v1.2.3" => "~1.2.3", "^v1.2.3" => "^1.2.3", ">=v1.2.3" => ">=1.2.3", "= 1.2.3" => "1.2.3" }.each do |range, same_as|
135
+ it "reads #{range.inspect} like #{same_as.inspect}" do
136
+ expect(RangeSpec::POOL.select { described_class.new(range).include?(it) })
137
+ .to eq(RangeSpec::POOL.select { described_class.new(same_as).include?(it) })
138
+ end
139
+ end
140
+
141
+ it "raises on a non-string" do
142
+ expect { described_class.new(nil) }.to raise_error(Secupdater::Error)
143
+ end
144
+
145
+ it "accepts a Version" do
146
+ version = Secupdater::YarnSupport::Version.parse("1.2.5")
147
+
148
+ expect(described_class.new("<1.2.6")).to include(version)
149
+ end
150
+
151
+ it "raises on an invalid version" do
152
+ expect { described_class.new("*").include?("1.2") }.to raise_error(Secupdater::Error, /1\.2/)
153
+ end
154
+
155
+ it "returns the original string from to_s" do
156
+ expect(described_class.new(">=1.0.0 <1.2.6").to_s).to eq(">=1.0.0 <1.2.6")
157
+ end
158
+ end
@@ -0,0 +1,61 @@
1
+ require "secupdater"
2
+ require "secupdater/yarn_support/version"
3
+
4
+ RSpec.describe Secupdater::YarnSupport::Version do
5
+ def v(str) = described_class.parse(str)
6
+
7
+ it "parses the parts" do
8
+ version = v("1.22.333-beta.4+sha.5")
9
+
10
+ expect([version.major, version.minor, version.patch, version.prerelease]).to eq([1, 22, 333, ["beta", 4]])
11
+ end
12
+
13
+ it "keeps the original string" do
14
+ expect(v("1.2.3-rc.1+b7").to_s).to eq("1.2.3-rc.1+b7")
15
+ end
16
+
17
+ # From the semver.org precedence example, in ascending order
18
+ it "orders prereleases like semver.org" do
19
+ ascending = %w[1.0.0-alpha 1.0.0-alpha.1 1.0.0-alpha.beta 1.0.0-beta 1.0.0-beta.2 1.0.0-beta.11 1.0.0-rc.1 1.0.0]
20
+
21
+ expect(ascending.shuffle(random: Random.new(1)).map { v(it) }.sort.map(&:to_s)).to eq(ascending)
22
+ end
23
+
24
+ it "compares numerically, not as strings" do
25
+ expect(v("1.10.0")).to be > v("1.9.0")
26
+ expect(v("10.0.0")).to be > v("9.99.99")
27
+ expect(v("1.0.0-rc.10")).to be > v("1.0.0-rc.9")
28
+ end
29
+
30
+ it "sorts numeric prerelease identifiers before alphanumeric ones" do
31
+ expect(v("1.0.0-1")).to be < v("1.0.0-a")
32
+ expect(v("1.0.0-0")).to be < v("1.0.0-0a")
33
+ end
34
+
35
+ it "ignores build metadata for ordering" do
36
+ expect(v("1.2.3+a") <=> v("1.2.3+b")).to eq(0)
37
+ expect(v("1.2.3+a")).to eq(v("1.2.3"))
38
+ end
39
+
40
+ it "compares with non-versions as nil" do
41
+ expect(v("1.2.3") <=> "1.2.3").to be_nil
42
+ end
43
+
44
+ [
45
+ "", "1", "1.2", "1.2.3.4", "v1.2.3", "=1.2.3", " 1.2.3", "1.2.3 ", "01.2.3", "1.02.3", "1.2.03",
46
+ "1.2.3-", "1.2.3-01", "1.2.3-a..b", "1.2.3+", "1.2.3-a_b", "1.x.3", "1.2.3\n--force", "-1.2.3", "latest",
47
+ ].each do |bad|
48
+ it "raises on #{bad.inspect}" do
49
+ expect { v(bad) }.to raise_error(Secupdater::Error, /#{Regexp.escape(bad.inspect)}/)
50
+ end
51
+ end
52
+
53
+ it "raises on a non-string" do
54
+ expect { v(nil) }.to raise_error(Secupdater::Error)
55
+ expect { v(1.2) }.to raise_error(Secupdater::Error)
56
+ end
57
+
58
+ it "allows a leading-zero alphanumeric prerelease identifier" do
59
+ expect(v("1.2.3-0a").prerelease).to eq(["0a"])
60
+ end
61
+ end
@@ -1,6 +1,15 @@
1
1
  require "secupdater"
2
2
 
3
3
  RSpec.describe Secupdater do
4
+ describe Secupdater::SecurityAdvisory do
5
+ it "takes the ranges of vulnerable versions last, for ecosystems whose advisories give those rather than patched versions" do
6
+ advisory = described_class.new("lodash", "ghsa/abcd-efgh", [], "Prototype pollution", nil, "high", ["< 4.17.21"])
7
+
8
+ expect(advisory).to have_attributes(name: "lodash", criticality: "high", vulnerable_versions: ["< 4.17.21"])
9
+ expect(described_class.new("rack", "cve/1", [">= 2.0"]).vulnerable_versions).to be_nil
10
+ end
11
+ end
12
+
4
13
  describe ".build_logger" do
5
14
  it "logs to stderr, so log lines stay in order with errors when stdout is buffered" do
6
15
  expect { Secupdater.build_logger.warn("hello") }.to output("[WARN] hello\n").to_stderr
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secupdater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Anderson
@@ -97,9 +97,18 @@ files:
97
97
  - lib/secupdater/runner.rb
98
98
  - lib/secupdater/update.rb
99
99
  - lib/secupdater/version.rb
100
+ - lib/secupdater/yarn_support/audit.rb
101
+ - lib/secupdater/yarn_support/lockfile.rb
102
+ - lib/secupdater/yarn_support/package_name.rb
103
+ - lib/secupdater/yarn_support/range.rb
104
+ - lib/secupdater/yarn_support/version.rb
100
105
  - release-please-config.json
101
106
  - sig/secupdater.rbs
102
107
  - spec/e2e/secupdater_spec.rb
108
+ - spec/fixtures/yarn/audit.ndjson
109
+ - spec/fixtures/yarn/protocols.yarn.lock
110
+ - spec/fixtures/yarn/yarn.lock
111
+ - spec/fixtures/yarn/yarn1.lock
103
112
  - spec/secupdater/checkout_spec.rb
104
113
  - spec/secupdater/cli_spec.rb
105
114
  - spec/secupdater/dashboard/gitlab_spec.rb
@@ -111,6 +120,11 @@ files:
111
120
  - spec/secupdater/publisher_spec.rb
112
121
  - spec/secupdater/runner_spec.rb
113
122
  - spec/secupdater/update_spec.rb
123
+ - spec/secupdater/yarn_support/audit_spec.rb
124
+ - spec/secupdater/yarn_support/lockfile_spec.rb
125
+ - spec/secupdater/yarn_support/package_name_spec.rb
126
+ - spec/secupdater/yarn_support/range_spec.rb
127
+ - spec/secupdater/yarn_support/version_spec.rb
114
128
  - spec/secupdater_spec.rb
115
129
  - spec/spec_helper.rb
116
130
  homepage: https://github.com/bagedevimo/secupdater