gds-api-adapters 73.1.0 → 75.2.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/lib/gds_api/account_api.rb +8 -44
- data/lib/gds_api/test_helpers/account_api.rb +12 -149
- data/lib/gds_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed853f2f02ea63fdb7b79c7ef4460076b88cc32d1b3c4f6841ba5ced95d9e22e
|
4
|
+
data.tar.gz: 72bc43ca960d3efece046f7faac4c3369fcaf27a4e9611ef6ca4ebcac4081a9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ceb5f3b05c87b631691e4221ebdd7fdeeb349fa2b4a213c8407e3af113bbcaac47e6e0e41b8f31ee4370bc59c726d212d397a3a808d9fe0c692f750ea00c215
|
7
|
+
data.tar.gz: d53218eba5ead7910b50e20d8dcb33787c3056e1cdd77bc92c33cb1a60eeeb15c4101e0bf4e9828fdfa32703f99d9bef5c36a67891ed0f6bc0ef175d150cc7ad
|
data/lib/gds_api/account_api.rb
CHANGED
@@ -11,14 +11,14 @@ 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 [
|
14
|
+
# @param [Boolean, nil] mfa whether to authenticate the user with MFA or not
|
15
15
|
#
|
16
16
|
# @return [Hash] An authentication URL and the OAuth state parameter (for CSRF protection)
|
17
|
-
def get_sign_in_url(redirect_path: nil,
|
17
|
+
def get_sign_in_url(redirect_path: nil, mfa: false)
|
18
18
|
querystring = nested_query_string(
|
19
19
|
{
|
20
20
|
redirect_path: redirect_path,
|
21
|
-
|
21
|
+
mfa: mfa,
|
22
22
|
}.compact,
|
23
23
|
)
|
24
24
|
get_json("#{endpoint}/api/oauth2/sign-in?#{querystring}")
|
@@ -65,13 +65,17 @@ class GdsApi::AccountApi < GdsApi::Base
|
|
65
65
|
# @param [String, nil] email The user's current
|
66
66
|
# @param [Boolean, nil] email_verified Whether the user's current email address is verified
|
67
67
|
# @param [Boolean, nil] has_unconfirmed_email Whether the user has a new, pending, email address
|
68
|
+
# @param [Boolean, nil] cookie_consent Whether the user has consented to analytics cookies
|
69
|
+
# @param [Boolean, nil] feedback_consent Whether the user has consented to being contacted for feedback
|
68
70
|
#
|
69
71
|
# @return [Hash] The user's subject identifier and email attributes
|
70
|
-
def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil)
|
72
|
+
def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil, cookie_consent: nil, feedback_consent: nil)
|
71
73
|
params = {
|
72
74
|
email: email,
|
73
75
|
email_verified: email_verified,
|
74
76
|
has_unconfirmed_email: has_unconfirmed_email,
|
77
|
+
cookie_consent: cookie_consent,
|
78
|
+
feedback_consent: feedback_consent,
|
75
79
|
}.compact
|
76
80
|
|
77
81
|
patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params)
|
@@ -127,46 +131,6 @@ class GdsApi::AccountApi < GdsApi::Base
|
|
127
131
|
delete_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", {}, auth_headers(govuk_account_session))
|
128
132
|
end
|
129
133
|
|
130
|
-
# Look up all pages saved by a user in their Account
|
131
|
-
#
|
132
|
-
# @param [String] govuk_account_session Value of the session header
|
133
|
-
#
|
134
|
-
# @return [Hash] containing :saved_pages, an array of single saved page hashes
|
135
|
-
def get_saved_pages(govuk_account_session:)
|
136
|
-
get_json("#{endpoint}/api/saved-pages", auth_headers(govuk_account_session))
|
137
|
-
end
|
138
|
-
|
139
|
-
# Return a single page by unique URL
|
140
|
-
#
|
141
|
-
# @param [String] the path of a page to check
|
142
|
-
# @param [String] govuk_account_session Value of the session header
|
143
|
-
#
|
144
|
-
# @return [Hash] containing :saved_page, a hash of a single saved page value
|
145
|
-
def get_saved_page(page_path:, govuk_account_session:)
|
146
|
-
get_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", auth_headers(govuk_account_session))
|
147
|
-
end
|
148
|
-
|
149
|
-
# Upsert a single saved page entry in a users account
|
150
|
-
#
|
151
|
-
# @param [String] the path of a page to check
|
152
|
-
# @param [String] govuk_account_session Value of the session header
|
153
|
-
#
|
154
|
-
# @return [Hash] A single saved page value (if sucessful)
|
155
|
-
def save_page(page_path:, govuk_account_session:)
|
156
|
-
put_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
|
157
|
-
end
|
158
|
-
|
159
|
-
# Delete a single saved page entry from a users account
|
160
|
-
#
|
161
|
-
# @param [String] the path of a page to check
|
162
|
-
# @param [String] govuk_account_session Value of the session header
|
163
|
-
#
|
164
|
-
# @return [GdsApi::Response] A status code of 204 indicates the saved page has been successfully deleted.
|
165
|
-
# A status code of 404 indicates there is no saved page with this path.
|
166
|
-
def delete_saved_page(page_path:, govuk_account_session:)
|
167
|
-
delete_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
|
168
|
-
end
|
169
|
-
|
170
134
|
private
|
171
135
|
|
172
136
|
def nested_query_string(params)
|
@@ -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,
|
23
|
-
querystring = Rack::Utils.build_nested_query({ redirect_path: redirect_path,
|
22
|
+
def stub_account_api_get_sign_in_url(redirect_path: nil, mfa: false, auth_uri: "http://auth/provider", state: "state")
|
23
|
+
querystring = Rack::Utils.build_nested_query({ redirect_path: redirect_path, mfa: mfa }.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", cookie_consent: false)
|
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, feedback_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, cookie_consent: cookie_consent }.to_json,
|
39
|
+
body: { govuk_account_session: govuk_account_session, redirect_path: redirect_path, ga_client_id: ga_client_id, cookie_consent: cookie_consent, feedback_consent: feedback_consent }.to_json,
|
40
40
|
)
|
41
41
|
end
|
42
42
|
|
@@ -69,13 +69,13 @@ module GdsApi
|
|
69
69
|
###############
|
70
70
|
# GET /api/user
|
71
71
|
###############
|
72
|
-
def stub_account_api_user_info(id: "user-id",
|
72
|
+
def stub_account_api_user_info(id: "user-id", mfa: false, email: "email@example.com", email_verified: true, has_unconfirmed_email: false, services: {}, **options)
|
73
73
|
stub_account_api_request(
|
74
74
|
:get,
|
75
75
|
"/api/user",
|
76
76
|
response_body: {
|
77
77
|
id: id,
|
78
|
-
|
78
|
+
mfa: mfa,
|
79
79
|
email: email,
|
80
80
|
email_verified: email_verified,
|
81
81
|
has_unconfirmed_email: has_unconfirmed_email,
|
@@ -125,16 +125,18 @@ module GdsApi
|
|
125
125
|
###########################################
|
126
126
|
# PATCH /api/oidc-users/:subject_identifier
|
127
127
|
###########################################
|
128
|
-
def stub_update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil, old_email: nil, old_email_verified: nil, old_has_unconfirmed_email: nil)
|
128
|
+
def stub_update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil, cookie_consent: nil, feedback_consent: nil, old_email: nil, old_email_verified: nil, old_has_unconfirmed_email: nil, old_cookie_consent: nil, old_feedback_consent: nil)
|
129
129
|
stub_account_api_request(
|
130
130
|
:patch,
|
131
131
|
"/api/oidc-users/#{subject_identifier}",
|
132
|
-
with: { body: hash_including({ email: email, email_verified: email_verified, has_unconfirmed_email: has_unconfirmed_email }.compact) },
|
132
|
+
with: { body: hash_including({ email: email, email_verified: email_verified, has_unconfirmed_email: has_unconfirmed_email, cookie_consent: cookie_consent, feedback_consent: feedback_consent }.compact) },
|
133
133
|
response_body: {
|
134
134
|
sub: subject_identifier,
|
135
135
|
email: email || old_email,
|
136
136
|
email_verified: email_verified || old_email_verified,
|
137
137
|
has_unconfirmed_email: has_unconfirmed_email || old_has_unconfirmed_email,
|
138
|
+
cookie_consent: cookie_consent || old_cookie_consent,
|
139
|
+
feedback_consent: feedback_consent || old_feedback_consent,
|
138
140
|
},
|
139
141
|
)
|
140
142
|
end
|
@@ -256,13 +258,12 @@ module GdsApi
|
|
256
258
|
)
|
257
259
|
end
|
258
260
|
|
259
|
-
def stub_account_api_forbidden_has_attributes(attributes: [],
|
261
|
+
def stub_account_api_forbidden_has_attributes(attributes: [], **options)
|
260
262
|
querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
|
261
263
|
stub_account_api_request(
|
262
264
|
:get,
|
263
265
|
"/api/attributes?#{querystring}",
|
264
266
|
response_status: 403,
|
265
|
-
response_body: { needed_level_of_authentication: needed_level_of_authentication },
|
266
267
|
**options,
|
267
268
|
)
|
268
269
|
end
|
@@ -289,150 +290,12 @@ module GdsApi
|
|
289
290
|
)
|
290
291
|
end
|
291
292
|
|
292
|
-
def stub_account_api_forbidden_set_attributes(attributes: nil,
|
293
|
+
def stub_account_api_forbidden_set_attributes(attributes: nil, **options)
|
293
294
|
stub_account_api_request(
|
294
295
|
:patch,
|
295
296
|
"/api/attributes",
|
296
297
|
with: { body: hash_including({ attributes: attributes }.compact) },
|
297
298
|
response_status: 403,
|
298
|
-
response_body: { needed_level_of_authentication: needed_level_of_authentication },
|
299
|
-
**options,
|
300
|
-
)
|
301
|
-
end
|
302
|
-
|
303
|
-
######################
|
304
|
-
# GET /api/saved-pages
|
305
|
-
######################
|
306
|
-
def stub_account_api_returning_saved_pages(saved_pages: [], **options)
|
307
|
-
stub_account_api_request(
|
308
|
-
:get,
|
309
|
-
"/api/saved-pages",
|
310
|
-
response_body: { saved_pages: saved_pages },
|
311
|
-
**options,
|
312
|
-
)
|
313
|
-
end
|
314
|
-
|
315
|
-
def stub_account_api_unauthorized_get_saved_pages(**options)
|
316
|
-
stub_account_api_request(
|
317
|
-
:get,
|
318
|
-
"/api/saved-pages",
|
319
|
-
response_status: 401,
|
320
|
-
**options,
|
321
|
-
)
|
322
|
-
end
|
323
|
-
|
324
|
-
#################################
|
325
|
-
# GET /api/saved_pages/:page_path
|
326
|
-
#################################
|
327
|
-
def stub_account_api_get_saved_page(page_path:, content_id: "46163ed2-1777-4ee6-bdd4-6a2007e49d8f", title: "Ministry of Magic", **options)
|
328
|
-
stub_account_api_request(
|
329
|
-
:get,
|
330
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
331
|
-
response_body: {
|
332
|
-
saved_page: {
|
333
|
-
page_path: page_path,
|
334
|
-
content_id: content_id,
|
335
|
-
title: title,
|
336
|
-
},
|
337
|
-
},
|
338
|
-
**options,
|
339
|
-
)
|
340
|
-
end
|
341
|
-
|
342
|
-
def stub_account_api_does_not_have_saved_page(page_path:, **options)
|
343
|
-
stub_account_api_request(
|
344
|
-
:get,
|
345
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
346
|
-
response_status: 404,
|
347
|
-
**options,
|
348
|
-
)
|
349
|
-
end
|
350
|
-
|
351
|
-
def stub_account_api_unauthorized_get_saved_page(page_path:, **options)
|
352
|
-
stub_account_api_request(
|
353
|
-
:get,
|
354
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
355
|
-
response_status: 401,
|
356
|
-
**options,
|
357
|
-
)
|
358
|
-
end
|
359
|
-
|
360
|
-
#################################
|
361
|
-
# PUT /api/saved-pages/:page_path
|
362
|
-
#################################
|
363
|
-
def stub_account_api_save_page(page_path:, content_id: "c840bfa2-011a-42cc-ac7a-a6da990aff0b", title: "Ministry of Magic", **options)
|
364
|
-
stub_account_api_request(
|
365
|
-
:put,
|
366
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
367
|
-
response_body: {
|
368
|
-
saved_page: {
|
369
|
-
page_path: page_path,
|
370
|
-
content_id: content_id,
|
371
|
-
title: title,
|
372
|
-
},
|
373
|
-
},
|
374
|
-
**options,
|
375
|
-
)
|
376
|
-
end
|
377
|
-
|
378
|
-
def stub_account_api_save_page_already_exists(page_path:, **options)
|
379
|
-
stub_account_api_save_page(page_path: page_path, **options)
|
380
|
-
end
|
381
|
-
|
382
|
-
def stub_account_api_save_page_cannot_save_page(page_path:, **options)
|
383
|
-
stub_account_api_request(
|
384
|
-
:put,
|
385
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
386
|
-
response_status: 422,
|
387
|
-
response_body: cannot_save_page_problem_detail({ page_path: page_path }),
|
388
|
-
**options,
|
389
|
-
)
|
390
|
-
end
|
391
|
-
|
392
|
-
def stub_account_api_unauthorized_save_page(page_path:, **options)
|
393
|
-
stub_account_api_request(
|
394
|
-
:put,
|
395
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
396
|
-
response_status: 401,
|
397
|
-
**options,
|
398
|
-
)
|
399
|
-
end
|
400
|
-
|
401
|
-
def cannot_save_page_problem_detail(option = {})
|
402
|
-
{
|
403
|
-
title: "Cannot save page",
|
404
|
-
detail: "Cannot save page with path #{option['page_path']}, check it is not blank, and is a well formatted url path.",
|
405
|
-
type: "https://github.com/alphagov/account-api/blob/main/docs/api.md#cannot-save-page",
|
406
|
-
**option,
|
407
|
-
}
|
408
|
-
end
|
409
|
-
|
410
|
-
####################################
|
411
|
-
# DELETE /api/saved-pages/:page_path
|
412
|
-
####################################
|
413
|
-
def stub_account_api_delete_saved_page(page_path:, **options)
|
414
|
-
stub_account_api_request(
|
415
|
-
:delete,
|
416
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
417
|
-
response_status: 204,
|
418
|
-
**options,
|
419
|
-
)
|
420
|
-
end
|
421
|
-
|
422
|
-
def stub_account_api_delete_saved_page_does_not_exist(page_path:, **options)
|
423
|
-
stub_account_api_request(
|
424
|
-
:delete,
|
425
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
426
|
-
response_status: 404,
|
427
|
-
**options,
|
428
|
-
)
|
429
|
-
end
|
430
|
-
|
431
|
-
def stub_account_api_unauthorized_delete_saved_page(page_path:, **options)
|
432
|
-
stub_account_api_request(
|
433
|
-
:delete,
|
434
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
435
|
-
response_status: 401,
|
436
299
|
**options,
|
437
300
|
)
|
438
301
|
end
|
data/lib/gds_api/version.rb
CHANGED
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:
|
4
|
+
version: 75.2.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-
|
11
|
+
date: 2021-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|