gds-api-adapters 71.6.0 → 72.0.0

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: ecea9412cb0ad1e32c5b4eac37fd53699b06e7b9612a7033eb23f989e1a013d2
4
- data.tar.gz: 311fc8a8a2dc36fc389dd7d0166943dfab092690d5e1ea504b9395fd44a5f2b6
3
+ metadata.gz: 1f884f8a2e2cd91ddec2d467ae503ae442ce852b033a5dfc3cf7d374f8fd60a0
4
+ data.tar.gz: aa34f87913d8ff559a85b99dd5c1fecf82bfddffad74fa2fea19fefbc3f2128d
5
5
  SHA512:
6
- metadata.gz: 255c6879512abcd1c8383d1f4b24799bc408ce04cce55e1cfd1db7365e5e17189d196fa26917283ff411c93b568c824fda237ea683bc9d5d6e56e397c43aaa54
7
- data.tar.gz: 1bc48d079cba0ee202697442fd3646718100df7c5e870ff5c17b38ca32802a11fd4f833f424d12dcf6270a98d3be7fd9a067525c0432dc986c771448be91053c
6
+ metadata.gz: d6ca46bd2cd504c1a434d6fbf7f91399b4542beb2ddc996452236e429abf66530f43ddf00b6078630fc034b9f533f91ae8ca59ba4937a9b31dcb2aea936dc0ea
7
+ data.tar.gz: d31a33695afd0f60cdedc7cd70babbc0f01db7fa4abda227d7d0de8f0e5d237ee260e47a0e528ac90db220de1a4ebc1ab9ba6a3dd62a1c86272cf9fc4ddcf7a5
@@ -11,15 +11,13 @@ class GdsApi::AccountApi < GdsApi::Base
11
11
  # Get an OAuth sign-in URL to redirect the user to
12
12
  #
13
13
  # @param [String, nil] redirect_path path on GOV.UK to send the user to after authentication
14
- # @param [String, nil] state_id identifier originally returned by #create_registration_state
15
14
  # @param [String, nil] level_of_authentication either "level1" (require MFA) or "level0" (do not require MFA)
16
15
  #
17
16
  # @return [Hash] An authentication URL and the OAuth state parameter (for CSRF protection)
18
- def get_sign_in_url(redirect_path: nil, state_id: nil, level_of_authentication: nil)
17
+ def get_sign_in_url(redirect_path: nil, level_of_authentication: nil)
19
18
  querystring = nested_query_string(
20
19
  {
21
20
  redirect_path: redirect_path,
22
- state_id: state_id,
23
21
  level_of_authentication: level_of_authentication,
24
22
  }.compact,
25
23
  )
@@ -36,15 +34,6 @@ class GdsApi::AccountApi < GdsApi::Base
36
34
  post_json("#{endpoint}/api/oauth2/callback", code: code, state: state)
37
35
  end
38
36
 
39
- # Register some initial state, to pass to get_sign_in_url, which is used to initialise the account if the user signs up
40
- #
41
- # @param [Hash, nil] attributes Initial attributes to store
42
- #
43
- # @return [Hash] The state ID to pass to get_sign_in_url
44
- def create_registration_state(attributes:)
45
- post_json("#{endpoint}/api/oauth2/state", attributes: attributes)
46
- end
47
-
48
37
  # Get all the information about a user needed to render the account home page
49
38
  #
50
39
  # @param [String] govuk_account_session Value of the session header
@@ -72,25 +61,6 @@ class GdsApi::AccountApi < GdsApi::Base
72
61
  patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params)
73
62
  end
74
63
 
75
- # Check if a user has an email subscription for the Transition Checker
76
- #
77
- # @param [String] govuk_account_session Value of the session header
78
- #
79
- # @return [Hash] Whether the user has a subscription, and a new session header
80
- def check_for_email_subscription(govuk_account_session:)
81
- get_json("#{endpoint}/api/transition-checker-email-subscription", auth_headers(govuk_account_session))
82
- end
83
-
84
- # Create or update a user's email subscription for the Transition Checker
85
- #
86
- # @param [String] govuk_account_session Value of the session header
87
- # @param [String] slug The email topic slug
88
- #
89
- # @return [Hash] Whether the user has a subscription, and a new session header
90
- def set_email_subscription(govuk_account_session:, slug:)
91
- post_json("#{endpoint}/api/transition-checker-email-subscription", { slug: slug }, auth_headers(govuk_account_session))
92
- end
93
-
94
64
  # Look up the values of a user's attributes
95
65
  #
96
66
  # @param [String] attributes Names of the attributes to check
@@ -156,10 +156,10 @@ class GdsApi::EmailAlertApi < GdsApi::Base
156
156
  # @param [string] Subscriber new_address
157
157
  #
158
158
  # @return [Hash] subscriber
159
- def change_subscriber(id:, new_address:)
159
+ def change_subscriber(id:, new_address:, on_conflict: nil)
160
160
  patch_json(
161
161
  "#{endpoint}/subscribers/#{uri_encode(id)}",
162
- new_address: new_address,
162
+ { new_address: new_address, on_conflict: on_conflict }.compact,
163
163
  )
164
164
  end
165
165
 
@@ -188,6 +188,32 @@ class GdsApi::EmailAlertApi < GdsApi::Base
188
188
  )
189
189
  end
190
190
 
191
+ # Mark a subscriber as "linked" to its corresponding GOV.UK Account.
192
+ # In practice "linking" will mean that email-alert-frontend and
193
+ # account-api will treat the subscriber specially (eg, only allowing
194
+ # address changes via the account).
195
+ #
196
+ # @param [string] govuk_account_session The request's session identifier
197
+ #
198
+ # @return [Hash] subscriber
199
+ def link_subscriber_to_govuk_account(govuk_account_session:)
200
+ post_json(
201
+ "#{endpoint}/subscribers/govuk-account/link",
202
+ govuk_account_session: govuk_account_session,
203
+ )
204
+ end
205
+
206
+ # Find a subscriber which has been "linked" to a GOV.UK Account.
207
+ #
208
+ # @param [String] govuk_account_id An ID for the account.
209
+ #
210
+ # @return [Hash] subscriber
211
+ def find_subscriber_by_govuk_account(govuk_account_id:)
212
+ get_json(
213
+ "#{endpoint}/subscribers/govuk-account/#{govuk_account_id}",
214
+ )
215
+ end
216
+
191
217
  # Verify a subscriber has control of a provided email
192
218
  #
193
219
  # @param [string] address Address to send verification email to
@@ -3,7 +3,7 @@ module GdsApi
3
3
  class BaseError < StandardError
4
4
  # Give Sentry extra context about this event
5
5
  # https://docs.sentry.io/clients/ruby/context/
6
- def raven_context
6
+ def sentry_context
7
7
  {
8
8
  # Make Sentry group exceptions by type instead of message, so all
9
9
  # exceptions like `GdsApi::TimedOutException` will get grouped as one
@@ -19,8 +19,8 @@ module GdsApi
19
19
  #########################
20
20
  # GET /api/oauth2/sign-in
21
21
  #########################
22
- def stub_account_api_get_sign_in_url(redirect_path: nil, state_id: nil, level_of_authentication: nil, auth_uri: "http://auth/provider", state: "state")
23
- querystring = Rack::Utils.build_nested_query({ redirect_path: redirect_path, state_id: state_id, level_of_authentication: level_of_authentication }.compact)
22
+ def stub_account_api_get_sign_in_url(redirect_path: nil, level_of_authentication: nil, auth_uri: "http://auth/provider", state: "state")
23
+ querystring = Rack::Utils.build_nested_query({ redirect_path: redirect_path, level_of_authentication: level_of_authentication }.compact)
24
24
  stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/sign-in?#{querystring}")
25
25
  .to_return(
26
26
  status: 200,
@@ -31,12 +31,12 @@ module GdsApi
31
31
  ###########################
32
32
  # POST /api/oauth2/callback
33
33
  ###########################
34
- def stub_account_api_validates_auth_response(code: nil, state: nil, govuk_account_session: "govuk-account-session", redirect_path: "/", ga_client_id: "ga-client-id")
34
+ def stub_account_api_validates_auth_response(code: nil, state: nil, govuk_account_session: "govuk-account-session", redirect_path: "/", ga_client_id: "ga-client-id", cookie_consent: false)
35
35
  stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/callback")
36
36
  .with(body: hash_including({ code: code, state: state }.compact))
37
37
  .to_return(
38
38
  status: 200,
39
- body: { govuk_account_session: govuk_account_session, redirect_path: redirect_path, ga_client_id: ga_client_id }.to_json,
39
+ body: { govuk_account_session: govuk_account_session, redirect_path: redirect_path, ga_client_id: ga_client_id, cookie_consent: cookie_consent }.to_json,
40
40
  )
41
41
  end
42
42
 
@@ -46,26 +46,15 @@ module GdsApi
46
46
  .to_return(status: 401)
47
47
  end
48
48
 
49
- ########################
50
- # POST /api/oauth2/state
51
- ########################
52
- def stub_account_api_create_registration_state(attributes: nil, state_id: "state-id")
53
- stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/state")
54
- .with(body: hash_including({ attributes: attributes }.compact))
55
- .to_return(
56
- status: 200,
57
- body: { state_id: state_id }.to_json,
58
- )
59
- end
60
-
61
49
  ###############
62
50
  # GET /api/user
63
51
  ###############
64
- def stub_account_api_user_info(level_of_authentication: "level0", email: "email@example.com", email_verified: true, has_unconfirmed_email: false, services: {}, **options)
52
+ def stub_account_api_user_info(id: "user-id", level_of_authentication: "level0", email: "email@example.com", email_verified: true, has_unconfirmed_email: false, services: {}, **options)
65
53
  stub_account_api_request(
66
54
  :get,
67
55
  "/api/user",
68
56
  response_body: {
57
+ id: id,
69
58
  level_of_authentication: level_of_authentication,
70
59
  email: email,
71
60
  email_verified: email_verified,
@@ -137,7 +126,7 @@ module GdsApi
137
126
  )
138
127
  end
139
128
 
140
- def stub_account_api_get_email_subscription_unauthorized(name:, **options)
129
+ def stub_account_api_unauthorized_get_email_subscription(name:, **options)
141
130
  stub_account_api_request(
142
131
  :get,
143
132
  "/api/email-subscriptions/#{name}",
@@ -204,79 +193,6 @@ module GdsApi
204
193
  )
205
194
  end
206
195
 
207
- ################################################
208
- # GET /api/transition-checker-email-subscription
209
- ################################################
210
- def stub_account_api_has_email_subscription(**options)
211
- stub_account_api_request(
212
- :get,
213
- "/api/transition-checker-email-subscription",
214
- response_body: { has_subscription: true },
215
- **options,
216
- )
217
- end
218
-
219
- def stub_account_api_does_not_have_email_subscription(**options)
220
- stub_account_api_request(
221
- :get,
222
- "/api/transition-checker-email-subscription",
223
- response_body: { has_subscription: false },
224
- **options,
225
- )
226
- end
227
-
228
- def stub_account_api_unauthorized_get_email_subscription(**options)
229
- stub_account_api_request(
230
- :get,
231
- "/api/transition-checker-email-subscription",
232
- response_status: 401,
233
- **options,
234
- )
235
- end
236
-
237
- def stub_account_api_forbidden_get_email_subscription(needed_level_of_authentication: "level1", **options)
238
- stub_account_api_request(
239
- :get,
240
- "/api/transition-checker-email-subscription",
241
- response_status: 403,
242
- response_body: { needed_level_of_authentication: needed_level_of_authentication },
243
- **options,
244
- )
245
- end
246
-
247
- #################################################
248
- # POST /api/transition-checker-email-subscription
249
- #################################################
250
- def stub_account_api_set_email_subscription(slug: nil, **options)
251
- stub_account_api_request(
252
- :post,
253
- "/api/transition-checker-email-subscription",
254
- with: { body: hash_including({ slug: slug }.compact) },
255
- **options,
256
- )
257
- end
258
-
259
- def stub_account_api_unauthorized_set_email_subscription(slug: nil, **options)
260
- stub_account_api_request(
261
- :post,
262
- "/api/transition-checker-email-subscription",
263
- with: { body: hash_including({ slug: slug }.compact) },
264
- response_status: 401,
265
- **options,
266
- )
267
- end
268
-
269
- def stub_account_api_forbidden_set_email_subscription(slug: nil, needed_level_of_authentication: "level1", **options)
270
- stub_account_api_request(
271
- :post,
272
- "/api/transition-checker-email-subscription",
273
- with: { body: hash_including({ slug: slug }.compact) },
274
- response_status: 403,
275
- response_body: { needed_level_of_authentication: needed_level_of_authentication },
276
- **options,
277
- )
278
- end
279
-
280
196
  #####################
281
197
  # GET /api/attributes
282
198
  #####################
@@ -506,7 +422,7 @@ module GdsApi
506
422
  )
507
423
  end
508
424
 
509
- def stub_account_api_delete_saved_page_unauthorised(page_path:, **options)
425
+ def stub_account_api_unauthorized_delete_saved_page(page_path:, **options)
510
426
  stub_account_api_request(
511
427
  :delete,
512
428
  "/api/saved-pages/#{CGI.escape(page_path)}",
@@ -6,11 +6,11 @@ module GdsApi
6
6
  module EmailAlertApi
7
7
  EMAIL_ALERT_API_ENDPOINT = Plek.find("email-alert-api")
8
8
 
9
- def stub_email_alert_api_has_updated_subscriber(id, new_address)
9
+ def stub_email_alert_api_has_updated_subscriber(id, new_address, govuk_account_id: nil)
10
10
  stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{id}")
11
11
  .to_return(
12
12
  status: 200,
13
- body: get_subscriber_response(id, new_address).to_json,
13
+ body: get_subscriber_response(id, new_address, govuk_account_id).to_json,
14
14
  )
15
15
  end
16
16
 
@@ -265,11 +265,11 @@ module GdsApi
265
265
  ).to_return(status: 422)
266
266
  end
267
267
 
268
- def stub_email_alert_api_sends_subscriber_verification_email(subscriber_id, address)
268
+ def stub_email_alert_api_sends_subscriber_verification_email(subscriber_id, address, govuk_account_id: nil)
269
269
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/auth-token")
270
270
  .to_return(
271
271
  status: 201,
272
- body: get_subscriber_response(subscriber_id, address).to_json,
272
+ body: get_subscriber_response(subscriber_id, address, govuk_account_id).to_json,
273
273
  )
274
274
  end
275
275
 
@@ -283,7 +283,12 @@ module GdsApi
283
283
  .to_return(status: 404)
284
284
  end
285
285
 
286
- def stub_email_alert_api_authenticate_subscriber_by_govuk_account(govuk_account_session, subscriber_id, address, new_govuk_account_session: nil)
286
+ def stub_email_alert_api_subscriber_verification_email_linked_to_govuk_account
287
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/auth-token")
288
+ .to_return(status: 403)
289
+ end
290
+
291
+ def stub_email_alert_api_authenticate_subscriber_by_govuk_account(govuk_account_session, subscriber_id, address, govuk_account_id: "user-id", new_govuk_account_session: nil)
287
292
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
288
293
  .with(
289
294
  body: { govuk_account_session: govuk_account_session }.to_json,
@@ -291,7 +296,7 @@ module GdsApi
291
296
  status: 200,
292
297
  body: {
293
298
  govuk_account_session: new_govuk_account_session,
294
- }.compact.merge(get_subscriber_response(subscriber_id, address)).to_json,
299
+ }.compact.merge(get_subscriber_response(subscriber_id, address, govuk_account_id)).to_json,
295
300
  )
296
301
  end
297
302
 
@@ -328,6 +333,52 @@ module GdsApi
328
333
  )
329
334
  end
330
335
 
336
+ def stub_email_alert_api_link_subscriber_to_govuk_account(govuk_account_session, subscriber_id, address, govuk_account_id: "user-id", new_govuk_account_session: nil)
337
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/link")
338
+ .with(
339
+ body: { govuk_account_session: govuk_account_session }.to_json,
340
+ ).to_return(
341
+ status: 200,
342
+ body: {
343
+ govuk_account_session: new_govuk_account_session,
344
+ }.compact.merge(get_subscriber_response(subscriber_id, address, govuk_account_id)).to_json,
345
+ )
346
+ end
347
+
348
+ def stub_email_alert_api_link_subscriber_to_govuk_account_session_invalid(govuk_account_session)
349
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/link")
350
+ .with(
351
+ body: { govuk_account_session: govuk_account_session }.to_json,
352
+ ).to_return(
353
+ status: 401,
354
+ )
355
+ end
356
+
357
+ def stub_email_alert_api_link_subscriber_to_govuk_account_email_unverified(govuk_account_session, new_govuk_account_session: nil)
358
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/link")
359
+ .with(
360
+ body: { govuk_account_session: govuk_account_session }.to_json,
361
+ ).to_return(
362
+ status: 403,
363
+ body: {
364
+ govuk_account_session: new_govuk_account_session,
365
+ }.compact.to_json,
366
+ )
367
+ end
368
+
369
+ def stub_email_alert_api_find_subscriber_by_govuk_account(govuk_account_id, subscriber_id, address)
370
+ stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/#{govuk_account_id}")
371
+ .to_return(
372
+ status: 200,
373
+ body: get_subscriber_response(subscriber_id, address, govuk_account_id).to_json,
374
+ )
375
+ end
376
+
377
+ def stub_email_alert_api_find_subscriber_by_govuk_account_no_subscriber(govuk_account_id)
378
+ stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/#{govuk_account_id}")
379
+ .to_return(status: 404)
380
+ end
381
+
331
382
  def assert_unsubscribed(uuid)
332
383
  assert_requested(:post, "#{EMAIL_ALERT_API_ENDPOINT}/unsubscribe/#{uuid}", times: 1)
333
384
  end
@@ -359,11 +410,12 @@ module GdsApi
359
410
 
360
411
  private
361
412
 
362
- def get_subscriber_response(id, address)
413
+ def get_subscriber_response(id, address, govuk_account_id)
363
414
  {
364
415
  "subscriber" => {
365
416
  "id" => id,
366
417
  "address" => address,
418
+ "govuk_account_id" => govuk_account_id,
367
419
  },
368
420
  }
369
421
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "71.6.0".freeze
2
+ VERSION = "72.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 71.6.0
4
+ version: 72.0.0
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: 2021-06-23 00:00:00.000000000 Z
11
+ date: 2021-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable