dependabot-maven 0.140.3 → 0.143.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: faa01084789ce9d35656ae869fec4869cca61e2df243e1ddaeb74b2282c8c314
4
- data.tar.gz: 665edebdc3fbdd17a11e19952df56a2e9025f3e93ff13bdab68a53f11c2676d0
3
+ metadata.gz: ceef68bb9cd96abacaebefb8f54a6a0aa493f1cf01eb6abef56f05c68a15aeeb
4
+ data.tar.gz: 0b83dd0fabb5c31cc1eca98ca4688dd0a450eb3082719b434534a6bb4776a615
5
5
  SHA512:
6
- metadata.gz: 53fc158fc5e63b88681d89a3561167331012accf9765a8be2d49840679ac654eb7116058155d5ccc4f32732979c7dcdf8f67cbdfcbf898fdd9e8eb8d4edc8c5e
7
- data.tar.gz: 3dc3738180ca20c9894b915dde558c49830fef8f93ea9de75604e46bf360662d6fe7a4b880218fee3abf57ccebdb440b7e6873d8e2a3655a85c7f02b06f57626
6
+ metadata.gz: 277181d30fddd6aebc0d2f7493b0aca2a0d7590a18a1edf42ee56277ab3d529a3f8d02c79f58e15a063a8d6a43d81554acbc5a6fe1c37a15ce00a3b36211045f
7
+ data.tar.gz: 25d7d938d1fece4c7a0d0b3ba6a04166a46aa61c8f9ffce43f5aa10014e8791c43a8dd69a533c3426a19820eb9133d84daed6ac71b023ad4e1a5021fbe7461cc
@@ -6,6 +6,7 @@ require "dependabot/metadata_finders/base"
6
6
  require "dependabot/file_fetchers/base"
7
7
  require "dependabot/maven/file_parser"
8
8
  require "dependabot/maven/file_parser/repositories_finder"
9
+ require "dependabot/maven/utils/auth_headers_finder"
9
10
 
10
11
  module Dependabot
11
12
  module Maven
@@ -104,7 +105,7 @@ module Dependabot
104
105
  "#{dependency.version}/"\
105
106
  "#{dependency_artifact_id}-#{dependency.version}.pom",
106
107
  idempotent: true,
107
- **SharedHelpers.excon_defaults(headers: auth_details)
108
+ **SharedHelpers.excon_defaults(headers: auth_headers)
108
109
  )
109
110
 
110
111
  @dependency_pom_file = Nokogiri::XML(response.body)
@@ -135,7 +136,7 @@ module Dependabot
135
136
  response = Excon.get(
136
137
  substitute_properties_in_source_url(url, pom),
137
138
  idempotent: true,
138
- **SharedHelpers.excon_defaults(headers: auth_details)
139
+ **SharedHelpers.excon_defaults(headers: auth_headers)
139
140
  )
140
141
 
141
142
  Nokogiri::XML(response.body)
@@ -156,21 +157,8 @@ module Dependabot
156
157
  "#{maven_repo_url}/#{group_id.tr('.', '/')}/#{artifact_id}"
157
158
  end
158
159
 
159
- def auth_details
160
- cred =
161
- credentials.select { |c| c["type"] == "maven_repository" }.
162
- find do |c|
163
- cred_url = c.fetch("url").gsub(%r{/+$}, "")
164
- next false unless cred_url == maven_repo_url
165
-
166
- c.fetch("username", nil)
167
- end
168
-
169
- return {} unless cred
170
-
171
- token = cred.fetch("username") + ":" + cred.fetch("password")
172
- encoded_token = Base64.encode64(token).delete("\n")
173
- { "Authorization" => "Basic #{encoded_token}" }
160
+ def auth_headers
161
+ @auth_headers ||= Utils::AuthHeadersFinder.new(credentials).auth_headers(maven_repo_url)
174
162
  end
175
163
  end
176
164
  end
@@ -7,6 +7,7 @@ module Dependabot
7
7
  module Maven
8
8
  class Requirement < Gem::Requirement
9
9
  quoted = OPS.keys.map { |k| Regexp.quote k }.join("|")
10
+ OR_SYNTAX = /(?<=\]|\)),/.freeze
10
11
  PATTERN_RAW =
11
12
  "\\s*(#{quoted})?\\s*(#{Maven::Version::VERSION_PATTERN})\\s*"
12
13
  PATTERN = /\A#{PATTERN_RAW}\z/.freeze
@@ -32,7 +33,14 @@ module Dependabot
32
33
 
33
34
  def initialize(*requirements)
34
35
  requirements = requirements.flatten.flat_map do |req_string|
35
- convert_java_constraint_to_ruby_constraint(req_string)
36
+ # NOTE: Support ruby-style version requirements that are created from
37
+ # PR ignore conditions
38
+ version_reqs = req_string.split(",").map(&:strip)
39
+ if version_reqs.all? { |s| Gem::Requirement::PATTERN.match?(s) }
40
+ version_reqs
41
+ else
42
+ convert_java_constraint_to_ruby_constraint(req_string)
43
+ end
36
44
  end
37
45
 
38
46
  super(requirements)
@@ -46,7 +54,9 @@ module Dependabot
46
54
  private
47
55
 
48
56
  def self.split_java_requirement(req_string)
49
- req_string.split(/(?<=\]|\)),/).flat_map do |str|
57
+ return [req_string] unless req_string.match?(OR_SYNTAX)
58
+
59
+ req_string.split(OR_SYNTAX).flat_map do |str|
50
60
  next str if str.start_with?("(", "[")
51
61
 
52
62
  exacts, *rest = str.split(/,(?=\[|\()/)
@@ -6,6 +6,7 @@ require "dependabot/maven/file_parser/repositories_finder"
6
6
  require "dependabot/maven/update_checker"
7
7
  require "dependabot/maven/version"
8
8
  require "dependabot/maven/requirement"
9
+ require "dependabot/maven/utils/auth_headers_finder"
9
10
 
10
11
  module Dependabot
11
12
  module Maven
@@ -13,8 +14,6 @@ module Dependabot
13
14
  class VersionFinder
14
15
  TYPE_SUFFICES = %w(jre android java).freeze
15
16
 
16
- MAVEN_RANGE_REGEX = /[\(\[].*,.*[\)\]]/.freeze
17
-
18
17
  def initialize(dependency:, dependency_files:, credentials:,
19
18
  ignored_versions:, security_advisories:,
20
19
  raise_on_ignored: false)
@@ -94,10 +93,10 @@ module Dependabot
94
93
  filtered = possible_versions
95
94
 
96
95
  ignored_versions.each do |req|
97
- ignore_req = Maven::Requirement.new(parse_requirement_string(req))
96
+ ignore_requirements = Maven::Requirement.requirements_array(req)
98
97
  filtered =
99
98
  filtered.
100
- reject { |v| ignore_req.satisfied_by?(v.fetch(:version)) }
99
+ reject { |v| ignore_requirements.any? { |r| r.satisfied_by?(v.fetch(:version)) } }
101
100
  end
102
101
 
103
102
  raise AllVersionsIgnored if @raise_on_ignored && filtered.empty? && possible_versions.any?
@@ -105,12 +104,6 @@ module Dependabot
105
104
  filtered
106
105
  end
107
106
 
108
- def parse_requirement_string(string)
109
- return string if string.match?(MAVEN_RANGE_REGEX)
110
-
111
- string.split(",").map(&:strip)
112
- end
113
-
114
107
  def filter_vulnerable_versions(possible_versions)
115
108
  versions_array = possible_versions
116
109
 
@@ -152,10 +145,8 @@ module Dependabot
152
145
  url = repository_details.fetch("url")
153
146
  response = Excon.head(
154
147
  dependency_files_url(url, version),
155
- user: repository_details.fetch("username"),
156
- password: repository_details.fetch("password"),
157
148
  idempotent: true,
158
- **SharedHelpers.excon_defaults
149
+ **SharedHelpers.excon_defaults(headers: repository_details.fetch("auth_headers"))
159
150
  )
160
151
 
161
152
  response.status < 400
@@ -173,10 +164,8 @@ module Dependabot
173
164
  begin
174
165
  response = Excon.get(
175
166
  dependency_metadata_url(repository_details.fetch("url")),
176
- user: repository_details.fetch("username"),
177
- password: repository_details.fetch("password"),
178
167
  idempotent: true,
179
- **Dependabot::SharedHelpers.excon_defaults
168
+ **Dependabot::SharedHelpers.excon_defaults(headers: repository_details.fetch("auth_headers"))
180
169
  )
181
170
  check_response(response, repository_details.fetch("url"))
182
171
 
@@ -206,10 +195,10 @@ module Dependabot
206
195
 
207
196
  @repositories =
208
197
  details.reject do |repo|
209
- next if repo["password"]
198
+ next if repo["auth_headers"]
210
199
 
211
- # Reject this entry if an identical one with a password exists
212
- details.any? { |r| r["url"] == repo["url"] && r["password"] }
200
+ # Reject this entry if an identical one with non-empty auth_headers exists
201
+ details.any? { |r| r["url"] == repo["url"] && r["auth_headers"] != {} }
213
202
  end
214
203
  end
215
204
 
@@ -219,7 +208,7 @@ module Dependabot
219
208
  new(dependency_files: dependency_files).
220
209
  repository_urls(pom: pom).
221
210
  map do |url|
222
- { "url" => url, "username" => nil, "password" => nil }
211
+ { "url" => url, "auth_headers" => {} }
223
212
  end
224
213
  end
225
214
 
@@ -229,8 +218,7 @@ module Dependabot
229
218
  map do |cred|
230
219
  {
231
220
  "url" => cred.fetch("url").gsub(%r{/+$}, ""),
232
- "username" => cred.fetch("username", nil),
233
- "password" => cred.fetch("password", nil)
221
+ "auth_headers" => auth_headers(cred.fetch("url").gsub(%r{/+$}, ""))
234
222
  }
235
223
  end
236
224
  end
@@ -287,6 +275,14 @@ module Dependabot
287
275
 
288
276
  %w(http:// https://).map { |p| p + central_url_without_protocol }
289
277
  end
278
+
279
+ def auth_headers_finder
280
+ @auth_headers_finder ||= Utils::AuthHeadersFinder.new(credentials)
281
+ end
282
+
283
+ def auth_headers(maven_repo_url)
284
+ auth_headers_finder.auth_headers(maven_repo_url)
285
+ end
290
286
  end
291
287
  end
292
288
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dependabot
4
+ module Maven
5
+ module Utils
6
+ class AuthHeadersFinder
7
+ def initialize(credentials)
8
+ @credentials = credentials
9
+ end
10
+
11
+ def auth_headers(maven_repo_url)
12
+ cred =
13
+ credentials.select { |c| c["type"] == "maven_repository" }.
14
+ find do |c|
15
+ cred_url = c.fetch("url").gsub(%r{/+$}, "")
16
+ next false unless cred_url == maven_repo_url
17
+
18
+ c.fetch("username", nil)
19
+ end
20
+
21
+ return gitlab_auth_headers(maven_repo_url) unless cred
22
+
23
+ token = cred.fetch("username") + ":" + cred.fetch("password")
24
+ encoded_token = Base64.strict_encode64(token)
25
+ { "Authorization" => "Basic #{encoded_token}" }
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :credentials
31
+
32
+ def gitlab_auth_headers(maven_repo_url)
33
+ return {} unless gitlab_maven_repo?(URI(maven_repo_url).path)
34
+
35
+ cred =
36
+ credentials.select { |c| c["type"] == "git_source" }.
37
+ find do |c|
38
+ cred_host = c.fetch("host").gsub(%r{/+$}, "")
39
+ next false unless URI(maven_repo_url).host == cred_host
40
+
41
+ c.fetch("password", nil)
42
+ end
43
+
44
+ return {} unless cred
45
+
46
+ { "Private-Token" => cred.fetch("password") }
47
+ end
48
+
49
+ def gitlab_maven_repo?(maven_repo_path)
50
+ gitlab_maven_repo_reg = %r{^/api/v4.*/packages/maven/?$}.freeze
51
+ maven_repo_path.match?(gitlab_maven_repo_reg)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-maven
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.140.3
4
+ version: 0.143.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-12 00:00:00.000000000 Z
11
+ date: 2021-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dependabot-common
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.140.3
19
+ version: 0.143.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.140.3
26
+ version: 0.143.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: byebug
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 1.12.0
103
+ version: 1.13.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 1.12.0
110
+ version: 1.13.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -199,6 +199,7 @@ files:
199
199
  - lib/dependabot/maven/update_checker/property_updater.rb
200
200
  - lib/dependabot/maven/update_checker/requirements_updater.rb
201
201
  - lib/dependabot/maven/update_checker/version_finder.rb
202
+ - lib/dependabot/maven/utils/auth_headers_finder.rb
202
203
  - lib/dependabot/maven/version.rb
203
204
  homepage: https://github.com/dependabot/dependabot-core
204
205
  licenses:
@@ -219,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
220
  - !ruby/object:Gem::Version
220
221
  version: 2.5.0
221
222
  requirements: []
222
- rubygems_version: 3.2.3
223
+ rubygems_version: 3.2.15
223
224
  signing_key:
224
225
  specification_version: 4
225
226
  summary: Maven support for dependabot