soar_authentication_token 4.0.1 → 5.0.0
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 +4 -4
- data/.gitignore +2 -0
- data/README.md +8 -8
- data/bin/rotate-configs +23 -0
- data/docker-compose.yml +2 -1
- data/lib/soar_authentication_token.rb +1 -0
- data/lib/soar_authentication_token/config_rotator.rb +119 -0
- data/lib/soar_authentication_token/providers/jwt_token_generator.rb +4 -6
- data/lib/soar_authentication_token/providers/jwt_token_validator.rb +24 -26
- data/lib/soar_authentication_token/token_validator.rb +1 -1
- data/lib/soar_authentication_token/version.rb +1 -1
- data/spec/config_rotator_spec.rb +283 -0
- data/spec/jwt_token_validator_spec.rb +291 -0
- data/spec/rack_middleware_spec.rb +3 -3
- data/spec/remote_token_validator_spec.rb +78 -0
- data/spec/static_token_validator_spec.rb +104 -0
- data/spec/token_generator_spec.rb +9 -5
- data/spec/token_validator_spec.rb +1 -272
- metadata +13 -2
@@ -9,20 +9,24 @@ describe SoarAuthenticationToken::TokenGenerator do
|
|
9
9
|
|
10
10
|
before :each do
|
11
11
|
@generator_configuration_local = {
|
12
|
-
'provider' => 'JwtTokenGenerator',
|
12
|
+
'provider' => 'SoarAuthenticationToken::JwtTokenGenerator',
|
13
13
|
'private_key' => @private_key
|
14
14
|
}
|
15
15
|
@validator_configuration_local = {
|
16
|
-
'provider' => 'JwtTokenValidator',
|
17
|
-
'
|
16
|
+
'provider' => 'SoarAuthenticationToken::JwtTokenValidator',
|
17
|
+
'keys' => {
|
18
|
+
'keyA' => {
|
19
|
+
'public_key' => @public_key
|
20
|
+
}
|
21
|
+
}
|
18
22
|
}
|
19
23
|
@configuration_remote_generator = {
|
20
|
-
'provider' => 'RemoteTokenGenerator',
|
24
|
+
'provider' => 'SoarAuthenticationToken::RemoteTokenGenerator',
|
21
25
|
'generator-url' => 'http://authentication-token-generator-service:9393/generate',
|
22
26
|
'generator-client-auth-token' => 'test_ecosystem_token_for_auth_token_aaapi_authenticator_service'
|
23
27
|
}
|
24
28
|
@configuration_remote_validator = {
|
25
|
-
'provider' => 'RemoteTokenValidator',
|
29
|
+
'provider' => 'SoarAuthenticationToken::RemoteTokenValidator',
|
26
30
|
'validator-url' => 'http://authentication-token-validator-service:9393/validate',
|
27
31
|
}
|
28
32
|
|
@@ -3,282 +3,11 @@ require 'yaml'
|
|
3
3
|
|
4
4
|
describe SoarAuthenticationToken::TokenValidator do
|
5
5
|
subject { SoarAuthenticationToken::TokenValidator }
|
6
|
-
before :all do
|
7
|
-
@test_store = AuthTokenStoreProvider::StubClient.new
|
8
|
-
keypair_generator = SoarAuthenticationToken::KeypairGenerator.new
|
9
|
-
@valid_private_key, @valid_public_key = keypair_generator.generate
|
10
|
-
@invalid_private_key, @invalid_public_key = keypair_generator.generate
|
11
|
-
@test_identifier = 'a@b.co.za'
|
12
|
-
@local_valid_generator_configuration = {
|
13
|
-
'provider' => 'JwtTokenGenerator',
|
14
|
-
'private_key' => @valid_private_key
|
15
|
-
}
|
16
|
-
@local_invalid_generator_configuration = {
|
17
|
-
'provider' => 'JwtTokenGenerator',
|
18
|
-
'private_key' => @invalid_private_key
|
19
|
-
}
|
20
|
-
|
21
|
-
@token_for_client_service_1 = 'some_secret_token_string_1111'
|
22
|
-
@token_for_client_service_2 = 'some_secret_token_string_2222'
|
23
|
-
@token_for_client_service_3_expired = 'some_secret_token_string_3333_expired'
|
24
|
-
@token_for_client_service_3_unknown = 'some_secret_token_string_3333_unknown'
|
25
|
-
|
26
|
-
current_time = Time.now
|
27
|
-
@static_validator_configuration = {
|
28
|
-
'provider' => 'StaticTokenValidator',
|
29
|
-
'static_tokens' => [
|
30
|
-
{
|
31
|
-
'token' => 'some_secret_token_string_1111',
|
32
|
-
'authenticated_identifier' => 'calling_client_service_1',
|
33
|
-
'token_issue_time' => current_time.utc.iso8601(3),
|
34
|
-
'token_expiry_time' => (current_time + 100).utc.iso8601(3)
|
35
|
-
},
|
36
|
-
{
|
37
|
-
'token' => 'some_secret_token_string_2222',
|
38
|
-
'authenticated_identifier' => 'calling_client_service_2',
|
39
|
-
'token_issue_time' => current_time.utc.iso8601(3),
|
40
|
-
'token_expiry_time' => (current_time + 100).utc.iso8601(3)
|
41
|
-
},
|
42
|
-
{
|
43
|
-
'token' => 'some_secret_token_string_3333_expired',
|
44
|
-
'authenticated_identifier' => 'calling_client_service_3',
|
45
|
-
'token_issue_time' => (current_time - 100).utc.iso8601(3),
|
46
|
-
'token_expiry_time' => (current_time - 50).utc.iso8601(3)
|
47
|
-
}
|
48
|
-
]
|
49
|
-
}
|
50
|
-
@local_validator_configuration = {
|
51
|
-
'provider' => 'JwtTokenValidator',
|
52
|
-
'public_key' => @valid_public_key
|
53
|
-
}
|
54
|
-
@remote_generator_configuration = {
|
55
|
-
'provider' => 'RemoteTokenGenerator',
|
56
|
-
'generator-url' => 'http://authentication-token-generator-service:9393/generate',
|
57
|
-
'generator-client-auth-token' => 'test_ecosystem_token_for_auth_token_aaapi_authenticator_service'
|
58
|
-
}
|
59
|
-
@remote_validator_configuration = {
|
60
|
-
'provider' => 'RemoteTokenValidator',
|
61
|
-
'validator-url' => 'http://authentication-token-validator-service:9393/validate',
|
62
|
-
'generator-client-auth-token' => 'test_ecosystem_token_for_auth_token_aaapi_authenticator_service'
|
63
|
-
}
|
64
|
-
@local_valid_generator = SoarAuthenticationToken::TokenGenerator.new(@local_valid_generator_configuration)
|
65
|
-
@local_valid_generator.inject_store_provider(@test_store)
|
66
|
-
@local_invalid_generator = SoarAuthenticationToken::TokenGenerator.new(@local_invalid_generator_configuration)
|
67
|
-
@local_invalid_generator.inject_store_provider(@test_store)
|
68
|
-
@remote_generator = SoarAuthenticationToken::TokenGenerator.new(@remote_generator_configuration)
|
69
|
-
end
|
70
|
-
|
71
|
-
before :each do
|
72
|
-
@iut_local = SoarAuthenticationToken::TokenValidator.new(@local_validator_configuration)
|
73
|
-
@iut_local.inject_store_provider(@test_store)
|
74
|
-
@iut_remote = SoarAuthenticationToken::TokenValidator.new(@remote_validator_configuration)
|
75
|
-
|
76
|
-
@iut_static = SoarAuthenticationToken::TokenValidator.new(@static_validator_configuration)
|
77
|
-
end
|
78
|
-
|
79
|
-
after :each do
|
80
|
-
end
|
81
6
|
|
82
7
|
it 'has a version number' do
|
83
8
|
expect(SoarAuthenticationToken::VERSION).not_to be nil
|
84
9
|
end
|
85
10
|
|
86
|
-
|
87
|
-
context "given that the validator is configured for local validation" do
|
88
|
-
context 'given valid token' do
|
89
|
-
let!(:token_validation_result) {
|
90
|
-
token, token_generator_meta = @local_valid_generator.generate(authenticated_identifier: @test_identifier)
|
91
|
-
@iut_local.validate(authentication_token: token)
|
92
|
-
}
|
93
|
-
let!(:token_validity) { token_validation_result[0] }
|
94
|
-
let!(:token_meta) { token_validation_result[1] }
|
95
|
-
let!(:message) { token_validation_result[2] }
|
96
|
-
|
97
|
-
it 'indicate token is valid' do
|
98
|
-
expect(token_validity).to eq true
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'provide the token meta' do
|
102
|
-
expect(token_meta['authenticated_identifier']).to eq @test_identifier
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'provide a message indicating that the token is valid' do
|
106
|
-
expect(message).to match /Valid token for/
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context 'given expired token' do
|
111
|
-
let!(:token_validation_result) {
|
112
|
-
token, token_generator_meta = @local_valid_generator.generate(authenticated_identifier: @test_identifier)
|
113
|
-
allow(Time).to receive(:now).and_return(Time.now+one_year_in_seconds)
|
114
|
-
@iut_local.validate(authentication_token: token)
|
115
|
-
}
|
116
|
-
let!(:token_validity) { token_validation_result[0] }
|
117
|
-
let!(:token_meta) { token_validation_result[1] }
|
118
|
-
let!(:message) { token_validation_result[2] }
|
119
|
-
|
120
|
-
it 'indicate token is invalid' do
|
121
|
-
expect(token_validity).to eq false
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'does not provide the token meta' do
|
125
|
-
expect(token_meta).to eq nil
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'provide a message indicating that the token is invalid' do
|
129
|
-
expect(message).to match /Expired token/
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context 'given unknown token (not in store)' do
|
134
|
-
let!(:token_validation_result) {
|
135
|
-
token, token_generator_meta = @local_valid_generator.generate(authenticated_identifier: @test_identifier)
|
136
|
-
@test_store.instance_variable_set("@store", []) #clear store
|
137
|
-
@iut_local.validate(authentication_token: token)
|
138
|
-
}
|
139
|
-
let!(:token_validity) { token_validation_result[0] }
|
140
|
-
let!(:token_meta) { token_validation_result[1] }
|
141
|
-
let!(:message) { token_validation_result[2] }
|
142
|
-
|
143
|
-
it 'indicate that token is invalid' do
|
144
|
-
expect(token_validity).to eq false
|
145
|
-
end
|
146
|
-
|
147
|
-
it 'does not provide the token meta' do
|
148
|
-
expect(token_meta).to eq nil
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'provide a message indicating that the token is invalid' do
|
152
|
-
expect(message).to match /Unknown token/
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
context 'given invalid token (garbage or different key)' do
|
157
|
-
let!(:token_validation_result) {
|
158
|
-
token, token_generator_meta = @remote_generator.generate(authenticated_identifier: @test_identifier)
|
159
|
-
@iut_local.validate(authentication_token: token)
|
160
|
-
}
|
161
|
-
let!(:token_validity) { token_validation_result[0] }
|
162
|
-
let!(:token_meta) { token_validation_result[1] }
|
163
|
-
let!(:message) { token_validation_result[2] }
|
164
|
-
|
165
|
-
it 'indicate token is invalid' do
|
166
|
-
expect(token_validity).to eq false
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'does not provide the token meta' do
|
170
|
-
expect(token_meta).to eq nil
|
171
|
-
end
|
172
|
-
|
173
|
-
it 'provide a message indicating that the token is invalid' do
|
174
|
-
expect(message).to match /Token decode\/verification failure/
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
11
|
+
#TODO testing to ensure that it can instantiate the providers, but otherwise there is not much here to test.
|
178
12
|
|
179
|
-
|
180
|
-
|
181
|
-
context "given that the validator is configured for remote validation" do
|
182
|
-
context 'given valid token' do
|
183
|
-
let!(:token_validation_result) {
|
184
|
-
token, token_generator_meta = @remote_generator.generate(authenticated_identifier: @test_identifier)
|
185
|
-
@iut_remote.validate(authentication_token: token)
|
186
|
-
}
|
187
|
-
let!(:token_validity) { token_validation_result[0] }
|
188
|
-
let!(:token_meta) { token_validation_result[1] }
|
189
|
-
let!(:message) { token_validation_result[2] }
|
190
|
-
|
191
|
-
it 'should indicate valid if the token is valid' do
|
192
|
-
expect(token_validity).to eq true
|
193
|
-
end
|
194
|
-
|
195
|
-
it 'should provide the authenticated_identifier if the token is valid' do
|
196
|
-
expect(token_meta['authenticated_identifier']).to eq @test_identifier
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
context 'given invalid (generalized) token' do
|
201
|
-
let!(:token_validation_result) {
|
202
|
-
token, token_generator_meta = @local_invalid_generator.generate(authenticated_identifier: @test_identifier)
|
203
|
-
@iut_remote.validate(authentication_token: token)
|
204
|
-
}
|
205
|
-
let!(:token_validity) { token_validation_result[0] }
|
206
|
-
let!(:token_meta) { token_validation_result[1] }
|
207
|
-
let!(:message) { token_validation_result[2] }
|
208
|
-
|
209
|
-
it 'indicate token is invalid' do
|
210
|
-
expect(token_validity).to eq false
|
211
|
-
end
|
212
|
-
|
213
|
-
it 'does not provide the token meta' do
|
214
|
-
expect(token_meta).to eq nil
|
215
|
-
end
|
216
|
-
|
217
|
-
it 'provides a message indicating the token is invalid' do
|
218
|
-
expect(message).to match /Token decode\/verification failure/
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
|
223
|
-
end
|
224
|
-
context "given that the validator is configured for static tokens" do
|
225
|
-
let(:iut) { subject.new(@static_validator_configuration) }
|
226
|
-
context "given a token that is in the list of static tokens and not expired" do
|
227
|
-
let(:response) { iut.validate(authentication_token: @token_for_client_service_1) }
|
228
|
-
let(:token_validity) { response[0] }
|
229
|
-
let(:token_meta) { response[1] }
|
230
|
-
let(:message) { response[2] }
|
231
|
-
|
232
|
-
it 'should respond with true indicating token is valid' do
|
233
|
-
expect(token_validity).to eq true
|
234
|
-
end
|
235
|
-
|
236
|
-
it 'should respond with token meta' do
|
237
|
-
expect(token_meta).to_not eq nil
|
238
|
-
end
|
239
|
-
|
240
|
-
it 'should respond with a message indicating that the token is valid' do
|
241
|
-
expect(message).to eq 'Valid token for <calling_client_service_1>'
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
context "the token is in the list of static tokens and expired" do
|
246
|
-
let(:response) { @iut_static.validate(authentication_token: @token_for_client_service_3_expired) }
|
247
|
-
let(:token_validity) { response[0] }
|
248
|
-
let(:token_meta) { response[1] }
|
249
|
-
let(:message) { response[2] }
|
250
|
-
|
251
|
-
it 'should respond with false indicating token is invalid' do
|
252
|
-
expect(token_validity).to eq false
|
253
|
-
end
|
254
|
-
|
255
|
-
it 'should respond with nil token meta' do
|
256
|
-
expect(token_meta).to eq nil
|
257
|
-
end
|
258
|
-
|
259
|
-
it 'should respond with a message indicating that the token is expired' do
|
260
|
-
expect(message).to match /Expired token/
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
context "given a token that is not in the list of static tokens" do
|
265
|
-
let(:response) { @iut_static.validate(authentication_token: @token_for_client_service_3_unknown) }
|
266
|
-
let(:token_validity) { response[0] }
|
267
|
-
let(:token_meta) { response[1] }
|
268
|
-
let(:message) { response[2] }
|
269
|
-
|
270
|
-
it 'should respond with false indicating token is invalid' do
|
271
|
-
expect(token_validity).to eq false
|
272
|
-
end
|
273
|
-
|
274
|
-
it 'should respond with no token meta' do
|
275
|
-
expect(token_meta).to eq nil
|
276
|
-
end
|
277
|
-
|
278
|
-
it 'should respond with a message indicating that the token is valid' do
|
279
|
-
expect(message).to match /Unknown static token/
|
280
|
-
end
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
13
|
end
|
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:
|
4
|
+
version: 5.0.0
|
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-02-
|
11
|
+
date: 2017-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: soar_xt
|
@@ -202,6 +202,7 @@ email:
|
|
202
202
|
executables:
|
203
203
|
- console
|
204
204
|
- keypair-generator
|
205
|
+
- rotate-configs
|
205
206
|
- setup
|
206
207
|
extensions: []
|
207
208
|
extra_rdoc_files: []
|
@@ -218,10 +219,12 @@ files:
|
|
218
219
|
- Rakefile
|
219
220
|
- bin/console
|
220
221
|
- bin/keypair-generator
|
222
|
+
- bin/rotate-configs
|
221
223
|
- bin/setup
|
222
224
|
- docker-compose-isolated.yml
|
223
225
|
- docker-compose.yml
|
224
226
|
- lib/soar_authentication_token.rb
|
227
|
+
- lib/soar_authentication_token/config_rotator.rb
|
225
228
|
- lib/soar_authentication_token/keypair_generator.rb
|
226
229
|
- lib/soar_authentication_token/providers/jwt_token_generator.rb
|
227
230
|
- lib/soar_authentication_token/providers/jwt_token_validator.rb
|
@@ -239,9 +242,13 @@ files:
|
|
239
242
|
- sanity/Gemfile
|
240
243
|
- sanity/sanity.rb
|
241
244
|
- soar_authentication_token.gemspec
|
245
|
+
- spec/config_rotator_spec.rb
|
246
|
+
- spec/jwt_token_validator_spec.rb
|
242
247
|
- spec/keypair_generator_spec.rb
|
243
248
|
- spec/rack_middleware_spec.rb
|
249
|
+
- spec/remote_token_validator_spec.rb
|
244
250
|
- spec/spec_helper.rb
|
251
|
+
- spec/static_token_validator_spec.rb
|
245
252
|
- spec/token_generator_spec.rb
|
246
253
|
- spec/token_validator_spec.rb
|
247
254
|
homepage: https://gitlab.host-h.net/hetznerZA/authentication-token-service
|
@@ -269,8 +276,12 @@ signing_key:
|
|
269
276
|
specification_version: 4
|
270
277
|
summary: Client library for Hetzner's authentication token service
|
271
278
|
test_files:
|
279
|
+
- spec/config_rotator_spec.rb
|
280
|
+
- spec/jwt_token_validator_spec.rb
|
272
281
|
- spec/keypair_generator_spec.rb
|
273
282
|
- spec/rack_middleware_spec.rb
|
283
|
+
- spec/remote_token_validator_spec.rb
|
274
284
|
- spec/spec_helper.rb
|
285
|
+
- spec/static_token_validator_spec.rb
|
275
286
|
- spec/token_generator_spec.rb
|
276
287
|
- spec/token_validator_spec.rb
|