gds-sso 15.0.0 → 16.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +23 -56
  3. data/Rakefile +11 -6
  4. data/app/controllers/api/user_controller.rb +30 -28
  5. data/app/controllers/authentications_controller.rb +4 -6
  6. data/config/routes.rb +7 -6
  7. data/lib/gds-sso.rb +29 -24
  8. data/lib/gds-sso/api_access.rb +1 -1
  9. data/lib/gds-sso/bearer_token.rb +24 -24
  10. data/lib/gds-sso/config.rb +13 -12
  11. data/lib/gds-sso/controller_methods.rb +7 -8
  12. data/lib/gds-sso/failure_app.rb +8 -8
  13. data/lib/gds-sso/lint/user_spec.rb +24 -25
  14. data/lib/gds-sso/lint/user_test.rb +28 -28
  15. data/lib/gds-sso/railtie.rb +12 -0
  16. data/lib/gds-sso/user.rb +12 -12
  17. data/lib/gds-sso/version.rb +1 -1
  18. data/lib/gds-sso/warden_config.rb +21 -31
  19. data/spec/controller/api_user_controller_spec.rb +40 -37
  20. data/spec/controller/controller_methods_spec.rb +28 -42
  21. data/spec/internal/app/controllers/application_controller.rb +1 -1
  22. data/spec/internal/app/controllers/example_controller.rb +1 -2
  23. data/spec/internal/config/initializers/gds-sso.rb +2 -2
  24. data/spec/internal/config/routes.rb +2 -2
  25. data/spec/internal/db/combustion_test.sqlite +0 -0
  26. data/spec/internal/db/schema.rb +5 -5
  27. data/spec/internal/log/test.log +1131 -1123
  28. data/spec/requests/end_to_end_spec.rb +44 -45
  29. data/spec/spec_helper.rb +12 -13
  30. data/spec/support/controller_spy.rb +14 -0
  31. data/spec/support/serializable_user.rb +3 -0
  32. data/spec/support/signon_integration_helpers.rb +10 -8
  33. data/spec/support/test_user.rb +29 -0
  34. data/spec/support/timecop.rb +1 -1
  35. data/spec/unit/api_access_spec.rb +7 -7
  36. data/spec/unit/bearer_token_spec.rb +14 -15
  37. data/spec/unit/config_spec.rb +5 -5
  38. data/spec/unit/mock_bearer_token_spec.rb +4 -4
  39. data/spec/unit/railtie_spec.rb +14 -0
  40. data/spec/unit/session_serialisation_spec.rb +5 -9
  41. data/spec/unit/user_spec.rb +20 -51
  42. metadata +104 -61
@@ -1,5 +1,5 @@
1
- require 'spec_helper'
2
- require 'gds-sso/bearer_token'
1
+ require "spec_helper"
2
+ require "gds-sso/bearer_token"
3
3
 
4
4
  describe GDS::SSO::MockBearerToken do
5
5
  it "updates the permissions of the user" do
@@ -7,7 +7,7 @@ describe GDS::SSO::MockBearerToken do
7
7
  # call .locate to create the dummy user initially
8
8
  GDS::SSO::Config.additional_mock_permissions_required = nil
9
9
  dummy_user = subject.locate("ABC")
10
- expect(dummy_user.permissions).to match_array(["signin"])
10
+ expect(dummy_user.permissions).to match_array(%w[signin])
11
11
 
12
12
  # add an extra permission
13
13
  GDS::SSO::Config.additional_mock_permissions_required = "extra_permission"
@@ -17,6 +17,6 @@ describe GDS::SSO::MockBearerToken do
17
17
 
18
18
  # call .locate again...this should update our permissions
19
19
  dummy_user_two = subject.locate("ABC")
20
- expect(dummy_user_two.permissions).to match_array(["signin", "extra_permission"])
20
+ expect(dummy_user_two.permissions).to match_array(%w[signin extra_permission])
21
21
  end
22
22
  end
@@ -0,0 +1,14 @@
1
+ require "rails"
2
+ require "spec_helper"
3
+
4
+ RSpec.describe GDS::SSO::Railtie do
5
+ let(:cache) { double(:cache) }
6
+
7
+ it "re-uses the Rails cache" do
8
+ expect(GDS::SSO::Config.cache).to eq Rails.cache
9
+ end
10
+
11
+ it "honours API only setting" do
12
+ expect(GDS::SSO::Config.api_only).to eq false
13
+ end
14
+ end
@@ -1,11 +1,7 @@
1
- require 'spec_helper'
2
- require 'active_record'
1
+ require "spec_helper"
2
+ require "active_record"
3
3
 
4
4
  describe Warden::SessionSerializer do
5
- class SerializableUser
6
- include GDS::SSO::User
7
- end
8
-
9
5
  before :each do
10
6
  @old_user_model = GDS::SSO::Config.user_model
11
7
  GDS::SSO::Config.user_model = SerializableUser
@@ -35,7 +31,7 @@ describe Warden::SessionSerializer do
35
31
 
36
32
  describe "deserialize a user" do
37
33
  it "should return the user if the timestamp is current and a Time" do
38
- expect(SerializableUser).to receive(:where).with(:uid => 1234, :remotely_signed_out => false).and_return(double(:first => :a_user))
34
+ expect(SerializableUser).to receive(:where).with(uid: 1234, remotely_signed_out: false).and_return(double(first: :a_user))
39
35
 
40
36
  result = @serializer.deserialize [1234, Time.now.utc - GDS::SSO::Config.auth_valid_for + 3600]
41
37
 
@@ -43,7 +39,7 @@ describe Warden::SessionSerializer do
43
39
  end
44
40
 
45
41
  it "should return the user if the timestamp is current and is an ISO 8601 string" do
46
- expect(SerializableUser).to receive(:where).with(:uid => 1234, :remotely_signed_out => false).and_return(double(:first => :a_user))
42
+ expect(SerializableUser).to receive(:where).with(uid: 1234, remotely_signed_out: false).and_return(double(first: :a_user))
47
43
 
48
44
  result = @serializer.deserialize [1234, (Time.now.utc - GDS::SSO::Config.auth_valid_for + 3600).iso8601]
49
45
 
@@ -69,7 +65,7 @@ describe Warden::SessionSerializer do
69
65
  it "should return nil for a user with a badly formatted timestamp" do
70
66
  expect(SerializableUser).not_to receive(:where)
71
67
 
72
- result = @serializer.deserialize [1234, 'this is not a timestamp']
68
+ result = @serializer.deserialize [1234, "this is not a timestamp"]
73
69
 
74
70
  expect(result).to be_nil
75
71
  end
@@ -1,67 +1,36 @@
1
- require 'spec_helper'
2
- require 'gds-sso/user'
3
- require 'gds-sso/lint/user_spec'
1
+ require "spec_helper"
2
+ require "gds-sso/user"
3
+ require "gds-sso/lint/user_spec"
4
4
 
5
- require 'ostruct'
5
+ require "ostruct"
6
6
 
7
7
  describe GDS::SSO::User do
8
8
  before :each do
9
9
  @auth_hash = {
10
- 'provider' => 'gds',
11
- 'uid' => 'abcde',
12
- 'credentials' => {'token' => 'abcdefg', 'secret' => 'abcdefg'},
13
- 'info' => {'name' => 'Matt Patterson', 'email' => 'matt@alphagov.co.uk'},
14
- 'extra' => {
15
- 'user' => {
16
- 'permissions' => [], 'organisation_slug' => nil, "organisation_content_id" => nil, 'disabled' => false
17
- }
18
- }
10
+ "provider" => "gds",
11
+ "uid" => "abcde",
12
+ "credentials" => { "token" => "abcdefg", "secret" => "abcdefg" },
13
+ "info" => { "name" => "Matt Patterson", "email" => "matt@alphagov.co.uk" },
14
+ "extra" => {
15
+ "user" => {
16
+ "permissions" => [], "organisation_slug" => nil, "organisation_content_id" => nil, "disabled" => false
17
+ },
18
+ },
19
19
  }
20
20
  end
21
21
 
22
22
  it "should extract the user params from the oauth hash" do
23
- expected = {'uid' => 'abcde',
24
- 'name' => 'Matt Patterson',
25
- 'email' => 'matt@alphagov.co.uk',
26
- "permissions" => [],
27
- "organisation_slug" => nil,
28
- "organisation_content_id" => nil,
29
- 'disabled' => false,
30
- }
23
+ expected = { "uid" => "abcde",
24
+ "name" => "Matt Patterson",
25
+ "email" => "matt@alphagov.co.uk",
26
+ "permissions" => [],
27
+ "organisation_slug" => nil,
28
+ "organisation_content_id" => nil,
29
+ "disabled" => false }
31
30
  expect(GDS::SSO::User.user_params_from_auth_hash(@auth_hash)).to eq(expected)
32
31
  end
33
32
 
34
33
  context "making sure that the lint spec is valid" do
35
- class TestUser < OpenStruct
36
- include GDS::SSO::User
37
-
38
- def self.where(opts)
39
- []
40
- end
41
-
42
- def self.create!(options, scope = {})
43
- new(options)
44
- end
45
-
46
- def update_attribute(key, value)
47
- send("#{key}=".to_sym, value)
48
- end
49
-
50
- def update!(options)
51
- options.each do |key, value|
52
- update_attribute(key, value)
53
- end
54
- end
55
-
56
- def remotely_signed_out?
57
- remotely_signed_out
58
- end
59
-
60
- def disabled?
61
- disabled
62
- end
63
- end
64
-
65
34
  let(:described_class) { TestUser }
66
35
  it_behaves_like "a gds-sso user class"
67
36
  end
metadata CHANGED
@@ -1,85 +1,119 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-sso
3
3
  version: !ruby/object:Gem::Version
4
- version: 15.0.0
4
+ version: 16.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-12 00:00:00.000000000 Z
11
+ date: 2021-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: multi_json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5'
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '5'
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: warden
28
+ name: oauth2
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.2'
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: omniauth
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
39
46
  - !ruby/object:Gem::Version
40
47
  version: '1.2'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '3.0'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '1.2'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.0'
41
61
  - !ruby/object:Gem::Dependency
42
- name: oauth2
62
+ name: omniauth-gds
43
63
  requirement: !ruby/object:Gem::Requirement
44
64
  requirements:
45
65
  - - "~>"
46
66
  - !ruby/object:Gem::Version
47
- version: '1.0'
67
+ version: '3.2'
48
68
  type: :runtime
49
69
  prerelease: false
50
70
  version_requirements: !ruby/object:Gem::Requirement
51
71
  requirements:
52
72
  - - "~>"
53
73
  - !ruby/object:Gem::Version
54
- version: '1.0'
74
+ version: '3.2'
55
75
  - !ruby/object:Gem::Dependency
56
- name: omniauth
76
+ name: plek
57
77
  requirement: !ruby/object:Gem::Requirement
58
78
  requirements:
59
79
  - - "~>"
60
80
  - !ruby/object:Gem::Version
61
- version: '1.2'
81
+ version: '4.0'
62
82
  type: :runtime
63
83
  prerelease: false
64
84
  version_requirements: !ruby/object:Gem::Requirement
65
85
  requirements:
66
86
  - - "~>"
67
87
  - !ruby/object:Gem::Version
68
- version: '1.2'
88
+ version: '4.0'
69
89
  - !ruby/object:Gem::Dependency
70
- name: omniauth-gds
90
+ name: rails
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '5'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '5'
103
+ - !ruby/object:Gem::Dependency
104
+ name: warden
71
105
  requirement: !ruby/object:Gem::Requirement
72
106
  requirements:
73
107
  - - "~>"
74
108
  - !ruby/object:Gem::Version
75
- version: '3.2'
109
+ version: '1.2'
76
110
  type: :runtime
77
111
  prerelease: false
78
112
  version_requirements: !ruby/object:Gem::Requirement
79
113
  requirements:
80
114
  - - "~>"
81
115
  - !ruby/object:Gem::Version
82
- version: '3.2'
116
+ version: '1.2'
83
117
  - !ruby/object:Gem::Dependency
84
118
  name: warden-oauth2
85
119
  requirement: !ruby/object:Gem::Requirement
@@ -95,89 +129,89 @@ dependencies:
95
129
  - !ruby/object:Gem::Version
96
130
  version: 0.0.1
97
131
  - !ruby/object:Gem::Dependency
98
- name: multi_json
132
+ name: capybara
99
133
  requirement: !ruby/object:Gem::Requirement
100
134
  requirements:
101
- - - "~>"
135
+ - - ">="
102
136
  - !ruby/object:Gem::Version
103
- version: '1.0'
104
- type: :runtime
137
+ version: '2'
138
+ type: :development
105
139
  prerelease: false
106
140
  version_requirements: !ruby/object:Gem::Requirement
107
141
  requirements:
108
- - - "~>"
142
+ - - ">="
109
143
  - !ruby/object:Gem::Version
110
- version: '1.0'
144
+ version: '2'
111
145
  - !ruby/object:Gem::Dependency
112
- name: rake
146
+ name: capybara-mechanize
113
147
  requirement: !ruby/object:Gem::Requirement
114
148
  requirements:
115
149
  - - ">="
116
150
  - !ruby/object:Gem::Version
117
- version: '0.9'
151
+ version: '1'
118
152
  type: :development
119
153
  prerelease: false
120
154
  version_requirements: !ruby/object:Gem::Requirement
121
155
  requirements:
122
156
  - - ">="
123
157
  - !ruby/object:Gem::Version
124
- version: '0.9'
158
+ version: '1'
125
159
  - !ruby/object:Gem::Dependency
126
- name: capybara
160
+ name: combustion
127
161
  requirement: !ruby/object:Gem::Requirement
128
162
  requirements:
129
163
  - - ">="
130
164
  - !ruby/object:Gem::Version
131
- version: '2'
165
+ version: '0.9'
132
166
  type: :development
133
167
  prerelease: false
134
168
  version_requirements: !ruby/object:Gem::Requirement
135
169
  requirements:
136
170
  - - ">="
137
171
  - !ruby/object:Gem::Version
138
- version: '2'
172
+ version: '0.9'
139
173
  - !ruby/object:Gem::Dependency
140
- name: rspec-rails
174
+ name: rake
141
175
  requirement: !ruby/object:Gem::Requirement
142
176
  requirements:
143
177
  - - ">="
144
178
  - !ruby/object:Gem::Version
145
- version: '3'
179
+ version: '0.9'
146
180
  type: :development
147
181
  prerelease: false
148
182
  version_requirements: !ruby/object:Gem::Requirement
149
183
  requirements:
150
184
  - - ">="
151
185
  - !ruby/object:Gem::Version
152
- version: '3'
186
+ version: '0.9'
153
187
  - !ruby/object:Gem::Dependency
154
- name: capybara-mechanize
188
+ name: rspec-rails
155
189
  requirement: !ruby/object:Gem::Requirement
156
190
  requirements:
157
191
  - - ">="
158
192
  - !ruby/object:Gem::Version
159
- version: '1'
193
+ version: '3'
160
194
  type: :development
161
195
  prerelease: false
162
196
  version_requirements: !ruby/object:Gem::Requirement
163
197
  requirements:
164
198
  - - ">="
165
199
  - !ruby/object:Gem::Version
166
- version: '1'
200
+ version: '3'
167
201
  - !ruby/object:Gem::Dependency
168
- name: combustion
202
+ name: rubocop-govuk
169
203
  requirement: !ruby/object:Gem::Requirement
170
204
  requirements:
171
205
  - - ">="
172
206
  - !ruby/object:Gem::Version
173
- version: '0.9'
207
+ version: '0'
174
208
  type: :development
175
209
  prerelease: false
176
210
  version_requirements: !ruby/object:Gem::Requirement
177
211
  requirements:
178
212
  - - ">="
179
213
  - !ruby/object:Gem::Version
180
- version: '0.9'
214
+ version: '0'
181
215
  - !ruby/object:Gem::Dependency
182
216
  name: sqlite3
183
217
  requirement: !ruby/object:Gem::Requirement
@@ -231,6 +265,7 @@ files:
231
265
  - lib/gds-sso/failure_app.rb
232
266
  - lib/gds-sso/lint/user_spec.rb
233
267
  - lib/gds-sso/lint/user_test.rb
268
+ - lib/gds-sso/railtie.rb
234
269
  - lib/gds-sso/user.rb
235
270
  - lib/gds-sso/version.rb
236
271
  - lib/gds-sso/warden_config.rb
@@ -253,12 +288,16 @@ files:
253
288
  - spec/requests/end_to_end_spec.rb
254
289
  - spec/spec_helper.rb
255
290
  - spec/support/backport_controller_test_params.rb
291
+ - spec/support/controller_spy.rb
292
+ - spec/support/serializable_user.rb
256
293
  - spec/support/signon_integration_helpers.rb
294
+ - spec/support/test_user.rb
257
295
  - spec/support/timecop.rb
258
296
  - spec/unit/api_access_spec.rb
259
297
  - spec/unit/bearer_token_spec.rb
260
298
  - spec/unit/config_spec.rb
261
299
  - spec/unit/mock_bearer_token_spec.rb
300
+ - spec/unit/railtie_spec.rb
262
301
  - spec/unit/session_serialisation_spec.rb
263
302
  - spec/unit/user_spec.rb
264
303
  homepage: https://github.com/alphagov/gds-sso
@@ -280,35 +319,39 @@ required_rubygems_version: !ruby/object:Gem::Requirement
280
319
  - !ruby/object:Gem::Version
281
320
  version: '0'
282
321
  requirements: []
283
- rubygems_version: 3.1.2
322
+ rubygems_version: 3.1.6
284
323
  signing_key:
285
324
  specification_version: 4
286
325
  summary: Client for GDS' OAuth 2-based SSO
287
326
  test_files:
288
- - spec/fixtures/integration/signon.sql
289
- - spec/fixtures/integration/authorize_api_users.sql
290
- - spec/support/timecop.rb
291
- - spec/support/signon_integration_helpers.rb
292
- - spec/support/backport_controller_test_params.rb
293
- - spec/controller/controller_methods_spec.rb
294
- - spec/controller/api_user_controller_spec.rb
295
- - spec/unit/bearer_token_spec.rb
296
- - spec/unit/mock_bearer_token_spec.rb
297
- - spec/unit/session_serialisation_spec.rb
298
- - spec/unit/config_spec.rb
299
- - spec/unit/api_access_spec.rb
300
- - spec/unit/user_spec.rb
301
- - spec/spec_helper.rb
302
327
  - spec/requests/end_to_end_spec.rb
303
- - spec/internal/app/controllers/application_controller.rb
328
+ - spec/internal/app/models/user.rb
304
329
  - spec/internal/app/controllers/example_controller.rb
330
+ - spec/internal/app/controllers/application_controller.rb
305
331
  - spec/internal/app/assets/config/manifest.js
306
- - spec/internal/app/models/user.rb
307
- - spec/internal/log/test.log
332
+ - spec/internal/db/combustion_test.sqlite
333
+ - spec/internal/db/schema.rb
308
334
  - spec/internal/public/favicon.ico
309
- - spec/internal/config/database.yml
335
+ - spec/internal/log/test.log
310
336
  - spec/internal/config/routes.rb
311
- - spec/internal/config/initializers/gds-sso.rb
312
337
  - spec/internal/config/storage.yml
313
- - spec/internal/db/combustion_test.sqlite
314
- - spec/internal/db/schema.rb
338
+ - spec/internal/config/initializers/gds-sso.rb
339
+ - spec/internal/config/database.yml
340
+ - spec/fixtures/integration/authorize_api_users.sql
341
+ - spec/fixtures/integration/signon.sql
342
+ - spec/spec_helper.rb
343
+ - spec/controller/api_user_controller_spec.rb
344
+ - spec/controller/controller_methods_spec.rb
345
+ - spec/unit/bearer_token_spec.rb
346
+ - spec/unit/api_access_spec.rb
347
+ - spec/unit/config_spec.rb
348
+ - spec/unit/session_serialisation_spec.rb
349
+ - spec/unit/railtie_spec.rb
350
+ - spec/unit/user_spec.rb
351
+ - spec/unit/mock_bearer_token_spec.rb
352
+ - spec/support/test_user.rb
353
+ - spec/support/controller_spy.rb
354
+ - spec/support/timecop.rb
355
+ - spec/support/serializable_user.rb
356
+ - spec/support/backport_controller_test_params.rb
357
+ - spec/support/signon_integration_helpers.rb