soar_authentication_token 6.0.1 → 6.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/soar_authentication_token/providers/jwt_token_validator.rb +1 -1
- data/lib/soar_authentication_token/version.rb +1 -1
- data/spec/jwt_token_validator_spec.rb +5 -5
- data/spec/rack_middleware_spec.rb +5 -5
- data/spec/remote_token_validator_spec.rb +4 -4
- data/spec/spec_helper.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c048ea8f50dfe96f02befadf1093f3208a27fb10
|
4
|
+
data.tar.gz: ced5e014bfe4f96000276cc6c6d39b68b83d0cb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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.
|
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-
|
11
|
+
date: 2017-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: soar_xt
|