lhc 6.1.1 → 6.1.2

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
  SHA1:
3
- metadata.gz: 2827291e4ad9cb6ff9752a2a091feb0b2a2434ef
4
- data.tar.gz: 30c81d451d22d7d52dd0890c5c98405d5dfed24b
3
+ metadata.gz: 9144e7e4cdc63f0dfd45813de1d4c75ae28a6c12
4
+ data.tar.gz: 6e0856848c3c817c4ebfb60f57c385c216cb9c60
5
5
  SHA512:
6
- metadata.gz: e0a84470ea8886ee64fa2e93793faa1dba4ed63741ece2a7de4b318955971f0c9827ba8f915d492a45030ea5adcc7aea00de67f922bb2235c6c39e7eb442a159
7
- data.tar.gz: 6ff625ec53ebd93d97165a89c06118d31f4dbd45cb11de593e52c58f6c42cdebcfffcda1a1bba1364b8edaab40e8918a9afb091080894c8ddc2cf9ad0d506ebf
6
+ metadata.gz: 726fbf0e6a53970ce7afbfdb26739381487ba1a9da33f959eb6f75be1d42a4aefaf28673687977fcd2641b5378d23754197f691c028f7b6170e45271db6d7c5c
7
+ data.tar.gz: 3671e777ec3db226d0082a678eaf378337f0ac0fe93d7a9d523a601344ff74b5856c0903e60a2819648b9fa89b65ac0e847471e87cc2b556e16332556809164b
@@ -14,16 +14,42 @@ class LHC::Endpoint
14
14
  self.options = options
15
15
  end
16
16
 
17
+ def uri
18
+ @uri ||= parse_url_gracefully(url)
19
+ end
20
+
21
+ def parse_url_gracefully(url)
22
+ URI.parse(url)
23
+ rescue URI::InvalidURIError
24
+ url
25
+ end
26
+
17
27
  def compile(params)
18
- url.gsub(PLACEHOLDER) do |match|
19
- replacement =
20
- if params.is_a? Proc
21
- params.call(match)
22
- else
23
- find_value(match, params)
24
- end
25
- replacement || fail("Compilation incomplete. Unable to find value for #{match.gsub(':', '')}.")
26
- end
28
+ add_basic_auth(
29
+ without_basic_auth(url).gsub(PLACEHOLDER) do |match|
30
+ replacement =
31
+ if params.is_a? Proc
32
+ params.call(match)
33
+ else
34
+ find_value(match, params)
35
+ end
36
+ replacement || fail("Compilation incomplete. Unable to find value for #{match.gsub(':', '')}.")
37
+ end
38
+ )
39
+ end
40
+
41
+ def add_basic_auth(url)
42
+ return url if !uri || !uri.is_a?(URI) || (uri.user.blank? && uri.password.blank?)
43
+ new_uri = parse_url_gracefully(url)
44
+ new_uri.user = uri.user
45
+ new_uri.password = uri.password
46
+ new_uri.to_s
47
+ end
48
+
49
+ # Strips basic auth from the url
50
+ def without_basic_auth(url)
51
+ return url if !uri || !uri.is_a?(URI) || (uri.user.blank? && uri.password.blank?)
52
+ url.gsub("#{uri.user}:#{uri.password}@", '')
27
53
  end
28
54
 
29
55
  # Endpoint options are immutable
@@ -1,3 +1,3 @@
1
1
  module LHC
2
- VERSION ||= "6.1.1"
2
+ VERSION ||= "6.1.2"
3
3
  end
@@ -16,5 +16,13 @@ describe LHC::Endpoint do
16
16
  LHC.get("https://d123token:@api.github.com/search")
17
17
  }).not_to raise_error
18
18
  end
19
+
20
+ it 'allows complete basic auth (username password) in url, like used for the gemserer' do
21
+ stub_request(:get, "https://name:password@gemserver.com")
22
+ .to_return(body: {}.to_json)
23
+ expect(->{
24
+ LHC.get("https://name:password@gemserver.com")
25
+ }).not_to raise_error
26
+ end
19
27
  end
20
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhc
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.1
4
+ version: 6.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhc/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-05 00:00:00.000000000 Z
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus