soar_authentication_token 6.0.1 → 6.0.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: 5c83cc1b233599c334a1e9da9f4af213192ccc79
4
- data.tar.gz: 23b6b9afc6d39c3ba516228e09e404a4adefbabc
3
+ metadata.gz: c048ea8f50dfe96f02befadf1093f3208a27fb10
4
+ data.tar.gz: ced5e014bfe4f96000276cc6c6d39b68b83d0cb8
5
5
  SHA512:
6
- metadata.gz: 931f6ccd6f377484db1c4af119f69837f40160bd62b4d0193d8577e7b4a2f792dba4b685e633a9e6c9dff24c478862bd879d0ddb927d39a58a473c0af2c68029
7
- data.tar.gz: 0202c7e8ea9702ff868945f5749d831a9f5f19248a71e61e9ec7b6d6d12d899e436feea038c67b70fbd47781d4268ec63ee1fedff993dab8ec5672fb3582512e
6
+ metadata.gz: c93144f5d81b0b7149c0d17765a786999366a245a3b68f8b1fabc349f6cb501cbc5775b8d3dbea3cdafad0f3d90d9e362158ac39790cc24cb449812793bf488e
7
+ data.tar.gz: 2a861c19385dc97ad3eb6d8adda1baa368e06987d7a6fd514d6a69752835773f63f4abfaf4a5872a2be465d51b801538cacdca9476a35546c9264f339aca4585
@@ -58,7 +58,7 @@ module SoarAuthenticationToken
58
58
  def attempt_decode_using_a_key(authentication_token,key_data)
59
59
  public_key = OpenSSL::PKey::EC.new(key_data['public_key'])
60
60
  public_key.private_key = nil
61
- JWT.decode(authentication_token, public_key, true, { :algorithm => 'ES512' })
61
+ JWT.decode(authentication_token.to_s, public_key, true, { :algorithm => 'ES512' })
62
62
  rescue JWT::VerificationError, JWT::DecodeError
63
63
  nil
64
64
  end
@@ -1,3 +1,3 @@
1
1
  module SoarAuthenticationToken
2
- VERSION = '6.0.1'
2
+ VERSION = '6.0.2'
3
3
  end
@@ -207,7 +207,7 @@ describe SoarAuthenticationToken::JwtTokenValidator do
207
207
  expect(iut).to receive(:attempt_decode_using_a_key).once.ordered.with(token, @multiple_key_configuration['keys']['KEYPAIR_20160108T190001']).and_return(nil)
208
208
  expect(iut).to receive(:attempt_decode_using_a_key).once.ordered.with(token, @multiple_key_configuration['keys']['KEYPAIR_20160107T230001']).and_return(nil)
209
209
 
210
- iut.validate(authentication_token: token, flow_identifier: nil, request_information: nil)
210
+ iut.validate(authentication_token: token, flow_identifier: nil, request_information: request_information_from_valid_source)
211
211
  end
212
212
 
213
213
  it 'attempts to use all the public keys' do
@@ -216,7 +216,7 @@ describe SoarAuthenticationToken::JwtTokenValidator do
216
216
 
217
217
  expect(iut).to receive(:attempt_decode_using_a_key).exactly(3).times
218
218
 
219
- iut.validate(authentication_token: token, flow_identifier: nil, request_information: nil)
219
+ iut.validate(authentication_token: token, flow_identifier: nil, request_information: request_information_from_valid_source)
220
220
  end
221
221
  end
222
222
 
@@ -234,7 +234,7 @@ describe SoarAuthenticationToken::JwtTokenValidator do
234
234
  it 'responds indicating the token is valid' do
235
235
  iut = SoarAuthenticationToken::JwtTokenValidator.new(@multiple_key_configuration)
236
236
  iut.inject_store_provider(@test_store)
237
- token_validity, token_meta, message = iut.validate(authentication_token: token, flow_identifier: nil, request_information: nil)
237
+ token_validity, token_meta, message = iut.validate(authentication_token: token, flow_identifier: nil, request_information: request_information_from_valid_source)
238
238
 
239
239
  expect(token_validity).to eq true
240
240
  end
@@ -250,7 +250,7 @@ describe SoarAuthenticationToken::JwtTokenValidator do
250
250
  iut.inject_store_provider(@test_store)
251
251
 
252
252
  expect(iut).to receive(:attempt_decode_using_a_key).once.with(token, @multiple_key_configuration['keys']['KEYPAIR_20160108T200001']).and_return([token_meta])
253
- iut.validate(authentication_token: token, flow_identifier: nil, request_information: nil)
253
+ iut.validate(authentication_token: token, flow_identifier: nil, request_information: request_information_from_valid_source)
254
254
  end
255
255
  end
256
256
 
@@ -288,7 +288,7 @@ describe SoarAuthenticationToken::JwtTokenValidator do
288
288
  expect(iut).to receive(:attempt_decode_using_a_key).once.with(token, @multiple_key_configuration['keys']['KEYPAIR_20160108T200001']).and_return(nil)
289
289
  expect(iut).to receive(:attempt_decode_using_a_key).once.with(token, @multiple_key_configuration['keys']['KEYPAIR_20160108T190001']).and_return([token_meta])
290
290
  expect(iut).not_to receive(:attempt_decode_using_a_key).with(token, @multiple_key_configuration['keys']['KEYPAIR_20160107T230001'])
291
- iut.validate(authentication_token: token, flow_identifier: nil, request_information: nil)
291
+ iut.validate(authentication_token: token, flow_identifier: nil, request_information: request_information_from_valid_source)
292
292
  end
293
293
  end
294
294
  end
@@ -80,7 +80,7 @@ describe SoarAuthenticationToken::RackMiddleware do
80
80
  context "when called with a request environment" do
81
81
  context 'with no authentication token' do
82
82
  it "return with 401" do
83
- opts = { }
83
+ opts = { 'REMOTE_ADDR' => '1.1.1.1' }
84
84
  code, env, body = @iut.call Rack::MockRequest.env_for('http://service', opts)
85
85
  expect([code, env, body]).to eq([401, {"Content-Type" => "application/json"}, @failure_response_json])
86
86
  end
@@ -88,7 +88,7 @@ describe SoarAuthenticationToken::RackMiddleware do
88
88
 
89
89
  context 'with an invalid authentication token' do
90
90
  it "return with 401" do
91
- opts = { 'HTTP_AUTHORIZATION' => @local_invalid_generator.generate(authenticated_identifier: 'a@b.com') }
91
+ opts = { 'REMOTE_ADDR' => '1.1.1.1', 'HTTP_AUTHORIZATION' => @local_invalid_generator.generate(authenticated_identifier: 'a@b.com') }
92
92
  code, env, body = @iut.call Rack::MockRequest.env_for('http://service', opts)
93
93
  expect([code, env, body]).to eq([401, {"Content-Type" => "application/json"}, @failure_response_json])
94
94
  end
@@ -96,19 +96,19 @@ describe SoarAuthenticationToken::RackMiddleware do
96
96
 
97
97
  context 'with a valid authentiation token' do
98
98
  it "pass requests to the application" do
99
- opts = { 'HTTP_AUTHORIZATION' => @local_valid_generator.generate(authenticated_identifier: 'a@b.com') }
99
+ opts = { 'REMOTE_ADDR' => '1.1.1.1', 'HTTP_AUTHORIZATION' => @local_valid_generator.generate(authenticated_identifier: 'a@b.com') }
100
100
  code, env, body = @iut.call Rack::MockRequest.env_for('http://service', opts)
101
101
  expect([code, env, body['message']]).to eq([200, {"Content-Type"=>"application/json"}, "tested with authenticated user a@b.com" ])
102
102
  end
103
103
 
104
104
  it "populate the 'user' key in the rack session with the authenticated user" do
105
- opts = { 'HTTP_AUTHORIZATION' => @local_valid_generator.generate(authenticated_identifier: 'a@b.com') }
105
+ opts = { 'REMOTE_ADDR' => '1.1.1.1', 'HTTP_AUTHORIZATION' => @local_valid_generator.generate(authenticated_identifier: 'a@b.com') }
106
106
  code, env, body = @iut.call Rack::MockRequest.env_for('http://service', opts)
107
107
  expect(body['user']).to eq('a@b.com')
108
108
  end
109
109
 
110
110
  it "populate the 'auth_token_meta' key in the rack session with the hash containing the token meta" do
111
- opts = { 'HTTP_AUTHORIZATION' => @local_valid_generator.generate(authenticated_identifier: 'a@b.com') }
111
+ opts = { 'REMOTE_ADDR' => '1.1.1.1', 'HTTP_AUTHORIZATION' => @local_valid_generator.generate(authenticated_identifier: 'a@b.com') }
112
112
  code, env, body = @iut.call Rack::MockRequest.env_for('http://service', opts)
113
113
  expect(body['auth_token_meta']['authenticated_identifier']).to eq('a@b.com')
114
114
  end
@@ -38,7 +38,7 @@ describe SoarAuthenticationToken::RemoteTokenValidator do
38
38
  context 'given valid token' do
39
39
  let!(:token_validation_result) {
40
40
  token, token_generator_meta = @remote_generator.generate(authenticated_identifier: @test_identifier)
41
- iut.validate(authentication_token: token, request_information: nil, flow_identifier: nil)
41
+ iut.validate(authentication_token: token, request_information: request_information_from_valid_source, flow_identifier: nil)
42
42
  }
43
43
  let!(:token_validity) { token_validation_result[0] }
44
44
  let!(:token_meta) { token_validation_result[1] }
@@ -56,7 +56,7 @@ describe SoarAuthenticationToken::RemoteTokenValidator do
56
56
  context 'given invalid (generalized) token' do
57
57
  let!(:token_validation_result) {
58
58
  token, token_generator_meta = @local_invalid_generator.generate(authenticated_identifier: @test_identifier)
59
- iut.validate(authentication_token: token, request_information: nil, flow_identifier: nil)
59
+ iut.validate(authentication_token: token, request_information: request_information_from_valid_source, flow_identifier: nil)
60
60
  }
61
61
  let!(:token_validity) { token_validation_result[0] }
62
62
  let!(:token_meta) { token_validation_result[1] }
@@ -88,13 +88,13 @@ describe SoarAuthenticationToken::RemoteTokenValidator do
88
88
  }
89
89
  it 'raise error after attempt that timeout has occured' do
90
90
  expect{
91
- iut.validate(authentication_token: valid_token, request_information: nil, flow_identifier: nil)
91
+ iut.validate(authentication_token: valid_token, request_information: request_information_from_valid_source, flow_identifier: nil)
92
92
  }.to raise_error Timeout::Error
93
93
  end
94
94
  it 'by default attempts 2 times with 3 second timeout' do
95
95
  start_time = Time.now
96
96
  expect{
97
- iut.validate(authentication_token: valid_token, request_information: nil, flow_identifier: nil)
97
+ iut.validate(authentication_token: valid_token, request_information: request_information_from_valid_source, flow_identifier: nil)
98
98
  }.to raise_error Timeout::Error
99
99
  expect(Time.now - start_time).to be_within(1).of 6
100
100
  end
data/spec/spec_helper.rb CHANGED
@@ -17,6 +17,13 @@ def one_year_in_seconds
17
17
  31536000
18
18
  end
19
19
 
20
+ def request_information_from_valid_source
21
+ { 'source_address' => '1.1.1.1',
22
+ 'user_agent' => 'some shiny browser',
23
+ 'service' => 'test-service',
24
+ 'resource' => '/'
25
+ }
26
+ end
20
27
 
21
28
  module AuthTokenStoreProvider
22
29
  class LocalStubClient
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soar_authentication_token
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.1
4
+ version: 6.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Barney de Villiers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-03 00:00:00.000000000 Z
11
+ date: 2017-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: soar_xt