lhc 12.0.0 → 12.1.1

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: 7cde56134f9f363649066cc6a6764534c56887fbd9ea2234beaaac0babe6a56c
4
- data.tar.gz: 4daf357293a3539de5764670def7e682d6d6dfb98cc209980fcd968a187bad31
3
+ metadata.gz: a8c1cf6d1d9237c3cad231ae1fca7cadfcaaf6283eb429544945715235172b61
4
+ data.tar.gz: 9945fabdbdd44fbef2fd472f0e4f7a37f347393b92fda1918abda13d6b65d195
5
5
  SHA512:
6
- metadata.gz: fc0deecc6746fb5c192fdc4648af66992cf21fe1fc340665cb7ec03e98a6f9aaabfbb0f5d59769fa8312c8448cf64c4236f8bcb807915b8055270af709163b75
7
- data.tar.gz: fbbda42ca1d2d7976b41c982a2b5135865af46340f4e5f6539f21c79115144bd9c8ff0039b5ee910e581fbe6d075d6776f564476cccded2e41fd330ab48e952f
6
+ metadata.gz: d208eca04aac94eb7f93b3053590df5c0626165cddf479ca3b1ea94907a71ee530df9de76f86f6b6492f14936a77d06f3ae296c9a854c8f1262866fdc4bad3bf
7
+ data.tar.gz: eaa8166c752a295b34a2b6e0c3406bee09f771a77f2f17ba39b509396fa264ce9387ea5f2dc507fa50f51c2287c0d4fe57bc9849dfdada0a7fc2572aaf5527bf
data/README.md CHANGED
@@ -58,6 +58,7 @@ use it like:
58
58
  * [Authentication Interceptor](#authentication-interceptor)
59
59
  * [Bearer Authentication](#bearer-authentication)
60
60
  * [Basic Authentication](#basic-authentication)
61
+ * [Body Authentication](#body-authentication)
61
62
  * [Reauthenticate](#reauthenticate)
62
63
  * [Bearer Authentication with client access token](#bearer-authentication-with-client-access-token)
63
64
  * [Caching Interceptor](#caching-interceptor)
@@ -92,6 +93,7 @@ use it like:
92
93
 
93
94
 
94
95
 
96
+
95
97
  ## Basic methods
96
98
 
97
99
  Available are `get`, `post`, `put` & `delete`.
@@ -549,6 +551,20 @@ Adds the following header to the request:
549
551
 
550
552
  Which is the base64 encoded credentials "username:password".
551
553
 
554
+ ##### Body Authentication
555
+
556
+ ```ruby
557
+ LHC.post('http://local.ch', auth: { body: { userToken: 'dheur5hrk3' } })
558
+ ```
559
+
560
+ Adds the following to body of all requests:
561
+
562
+ ```
563
+ {
564
+ "userToken": "dheur5hrk3"
565
+ }
566
+ ```
567
+
552
568
  ##### Reauthenticate
553
569
 
554
570
  The current implementation can only offer reauthenticate for _client access tokens_. For this to work the following has to be given:
@@ -35,5 +35,5 @@ Gem::Specification.new do |s|
35
35
  s.add_development_dependency 'timecop'
36
36
  s.add_development_dependency 'webmock'
37
37
 
38
- s.license = 'GPL-3'
38
+ s.license = 'GPL-3.0'
39
39
  end
@@ -4,8 +4,13 @@ class LHC::Auth < LHC::Interceptor
4
4
  include ActiveSupport::Configurable
5
5
  config_accessor :refresh_client_token
6
6
 
7
+ def before_raw_request
8
+ body_authentication! if auth_options[:body]
9
+ end
10
+
7
11
  def before_request
8
- authenticate!
12
+ bearer_authentication! if auth_options[:bearer]
13
+ basic_authentication! if auth_options[:basic]
9
14
  end
10
15
 
11
16
  def after_response
@@ -16,18 +21,15 @@ class LHC::Auth < LHC::Interceptor
16
21
 
17
22
  private
18
23
 
19
- def authenticate!
20
- if auth_options[:bearer]
21
- bearer_authentication!
22
- elsif auth_options[:basic]
23
- basic_authentication!
24
- end
24
+ def body_authentication!
25
+ auth = auth_options[:body]
26
+ request.options[:body] = (request.options[:body] || {}).merge(auth)
25
27
  end
26
28
 
27
29
  def basic_authentication!
28
30
  auth = auth_options[:basic]
29
31
  credentials = "#{auth[:username]}:#{auth[:password]}"
30
- set_authorization_header("Basic #{Base64.encode64(credentials).chomp}")
32
+ set_authorization_header("Basic #{Base64.strict_encode64(credentials).chomp}")
31
33
  end
32
34
 
33
35
  def bearer_authentication!
@@ -78,7 +80,7 @@ class LHC::Auth < LHC::Interceptor
78
80
  end
79
81
 
80
82
  def auth_options
81
- @auth_options ||= request.options[:auth].dup || {}
83
+ request.options[:auth] || {}
82
84
  end
83
85
 
84
86
  def configuration_correct?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LHC
4
- VERSION ||= '12.0.0'
4
+ VERSION ||= '12.1.1'
5
5
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ describe LHC::Auth do
6
+ before(:each) do
7
+ LHC.config.interceptors = [LHC::Auth]
8
+ end
9
+
10
+ it 'adds body authentication to the existing request body' do
11
+ stub_request(:post, "http://local.ch/")
12
+ .with(body: {
13
+ message: 'body',
14
+ userToken: 'dheur5hrk3'
15
+ }.to_json)
16
+
17
+ LHC.post('http://local.ch', auth: { body: { userToken: 'dheur5hrk3' } }, body: {
18
+ message: 'body'
19
+ })
20
+ end
21
+
22
+ it 'adds body authentication to an empty request body' do
23
+ stub_request(:post, "http://local.ch/")
24
+ .with(body: {
25
+ userToken: 'dheur5hrk3'
26
+ }.to_json)
27
+
28
+ LHC.post('http://local.ch', auth: { body: { userToken: 'dheur5hrk3' } })
29
+ end
30
+
31
+ it 'adds nothing if request method is GET' do
32
+ stub_request(:get, "http://local.ch/")
33
+
34
+ LHC.get('http://local.ch', auth: { body: { userToken: 'dheur5hrk3' } })
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ describe LHC::Auth do
6
+ before(:each) do
7
+ LHC.config.interceptors = [LHC::Auth]
8
+ end
9
+
10
+ it 'adds basic auth in a correct way even if username and password are especially long' do
11
+ options = { basic: { username: '123456789101234', password: '12345678901234567890123456789012' } }
12
+ LHC.config.endpoint(:local, 'http://local.ch', auth: options)
13
+ stub_request(:get, 'http://local.ch')
14
+ .with(headers: { 'Authorization' => 'Basic MTIzNDU2Nzg5MTAxMjM0OjEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEy' })
15
+ LHC.get(:local)
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ describe LHC::Auth do
6
+ before(:each) do
7
+ class AuthPrepInterceptor < LHC::Interceptor
8
+
9
+ def before_request
10
+ request.options[:auth] = { bearer: 'sometoken' }
11
+ end
12
+ end
13
+
14
+ LHC.config.interceptors = [AuthPrepInterceptor, LHC::Auth]
15
+ end
16
+
17
+ after do
18
+ LHC.config.reset
19
+ end
20
+
21
+ it 'does not use instance variables internally so that other interceptors can still change auth options' do
22
+ stub_request(:get, "http://local.ch/")
23
+ .with(headers: { 'Authorization' => 'Bearer sometoken' })
24
+ .to_return(status: 200)
25
+ LHC.get('http://local.ch')
26
+ end
27
+ 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: 12.0.0
4
+ version: 12.1.1
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: 2020-07-13 00:00:00.000000000 Z
11
+ date: 2020-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -325,6 +325,9 @@ files:
325
325
  - spec/interceptors/after_response_spec.rb
326
326
  - spec/interceptors/auth/basic_auth_spec.rb
327
327
  - spec/interceptors/auth/bearer_spec.rb
328
+ - spec/interceptors/auth/body_spec.rb
329
+ - spec/interceptors/auth/long_basic_auth_credentials_spec.rb
330
+ - spec/interceptors/auth/no_instance_var_for_options_spec.rb
328
331
  - spec/interceptors/auth/reauthentication_configuration_spec.rb
329
332
  - spec/interceptors/auth/reauthentication_spec.rb
330
333
  - spec/interceptors/before_request_spec.rb
@@ -384,7 +387,7 @@ files:
384
387
  - spec/timeouts/timings_spec.rb
385
388
  homepage: https://github.com/local-ch/lhc
386
389
  licenses:
387
- - GPL-3
390
+ - GPL-3.0
388
391
  metadata: {}
389
392
  post_install_message:
390
393
  rdoc_options: []
@@ -475,6 +478,9 @@ test_files:
475
478
  - spec/interceptors/after_response_spec.rb
476
479
  - spec/interceptors/auth/basic_auth_spec.rb
477
480
  - spec/interceptors/auth/bearer_spec.rb
481
+ - spec/interceptors/auth/body_spec.rb
482
+ - spec/interceptors/auth/long_basic_auth_credentials_spec.rb
483
+ - spec/interceptors/auth/no_instance_var_for_options_spec.rb
478
484
  - spec/interceptors/auth/reauthentication_configuration_spec.rb
479
485
  - spec/interceptors/auth/reauthentication_spec.rb
480
486
  - spec/interceptors/before_request_spec.rb