gds-api-adapters 73.0.0 → 75.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gds_api/account_api.rb +17 -44
- data/lib/gds_api/test_helpers/account_api.rb +30 -147
- 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: 36e41430cc8105c52489b3ba8bde38b4027a124a4a0cc3ca4ddabf120dd97de8
|
4
|
+
data.tar.gz: c61130dc56390e9a6ff2962589686bb232abbd506b742c14d6d77a9f6ac7500a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b3b29f19b7f55cff24242a9370bfc3cc7b4392de6f9fe84e4d64067bdeabf56b8d35468f2556d86648efb5f7189e3c527203d63ace5ffd6745ad513701addd6
|
7
|
+
data.tar.gz: 5efaa1939f0b3c8644ee3e8c19dc208419cfc6344d3b644c506e76e87965923f3f1c1c9427dc1702be32560caeea38fee900ec5a06ee09b47533324bb3c9e8e0
|
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}")
|
@@ -34,6 +34,15 @@ class GdsApi::AccountApi < GdsApi::Base
|
|
34
34
|
post_json("#{endpoint}/api/oauth2/callback", code: code, state: state)
|
35
35
|
end
|
36
36
|
|
37
|
+
# Get an OIDC end-session URL to redirect the user to
|
38
|
+
#
|
39
|
+
# @param [String, nil] govuk_account_session Value of the session header
|
40
|
+
#
|
41
|
+
# @return [Hash] An end-session URL
|
42
|
+
def get_end_session_url(govuk_account_session: nil)
|
43
|
+
get_json("#{endpoint}/api/oauth2/end-session", auth_headers(govuk_account_session))
|
44
|
+
end
|
45
|
+
|
37
46
|
# Get all the information about a user needed to render the account home page
|
38
47
|
#
|
39
48
|
# @param [String] govuk_account_session Value of the session header
|
@@ -56,13 +65,17 @@ class GdsApi::AccountApi < GdsApi::Base
|
|
56
65
|
# @param [String, nil] email The user's current
|
57
66
|
# @param [Boolean, nil] email_verified Whether the user's current email address is verified
|
58
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
|
59
70
|
#
|
60
71
|
# @return [Hash] The user's subject identifier and email attributes
|
61
|
-
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)
|
62
73
|
params = {
|
63
74
|
email: email,
|
64
75
|
email_verified: email_verified,
|
65
76
|
has_unconfirmed_email: has_unconfirmed_email,
|
77
|
+
cookie_consent: cookie_consent,
|
78
|
+
feedback_consent: feedback_consent,
|
66
79
|
}.compact
|
67
80
|
|
68
81
|
patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params)
|
@@ -118,46 +131,6 @@ class GdsApi::AccountApi < GdsApi::Base
|
|
118
131
|
delete_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", {}, auth_headers(govuk_account_session))
|
119
132
|
end
|
120
133
|
|
121
|
-
# Look up all pages saved by a user in their Account
|
122
|
-
#
|
123
|
-
# @param [String] govuk_account_session Value of the session header
|
124
|
-
#
|
125
|
-
# @return [Hash] containing :saved_pages, an array of single saved page hashes
|
126
|
-
def get_saved_pages(govuk_account_session:)
|
127
|
-
get_json("#{endpoint}/api/saved-pages", auth_headers(govuk_account_session))
|
128
|
-
end
|
129
|
-
|
130
|
-
# Return a single page by unique URL
|
131
|
-
#
|
132
|
-
# @param [String] the path of a page to check
|
133
|
-
# @param [String] govuk_account_session Value of the session header
|
134
|
-
#
|
135
|
-
# @return [Hash] containing :saved_page, a hash of a single saved page value
|
136
|
-
def get_saved_page(page_path:, govuk_account_session:)
|
137
|
-
get_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", auth_headers(govuk_account_session))
|
138
|
-
end
|
139
|
-
|
140
|
-
# Upsert a single saved page entry in a users account
|
141
|
-
#
|
142
|
-
# @param [String] the path of a page to check
|
143
|
-
# @param [String] govuk_account_session Value of the session header
|
144
|
-
#
|
145
|
-
# @return [Hash] A single saved page value (if sucessful)
|
146
|
-
def save_page(page_path:, govuk_account_session:)
|
147
|
-
put_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
|
148
|
-
end
|
149
|
-
|
150
|
-
# Delete a single saved page entry from a users account
|
151
|
-
#
|
152
|
-
# @param [String] the path of a page to check
|
153
|
-
# @param [String] govuk_account_session Value of the session header
|
154
|
-
#
|
155
|
-
# @return [GdsApi::Response] A status code of 204 indicates the saved page has been successfully deleted.
|
156
|
-
# A status code of 404 indicates there is no saved page with this path.
|
157
|
-
def delete_saved_page(page_path:, govuk_account_session:)
|
158
|
-
delete_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
|
159
|
-
end
|
160
|
-
|
161
134
|
private
|
162
135
|
|
163
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,
|
@@ -46,16 +46,36 @@ module GdsApi
|
|
46
46
|
.to_return(status: 401)
|
47
47
|
end
|
48
48
|
|
49
|
+
#############################
|
50
|
+
# GET /api/oauth2/end-session
|
51
|
+
#############################
|
52
|
+
def stub_account_api_get_end_session_url(govuk_account_session: nil, end_session_uri: "http://auth/provider")
|
53
|
+
if govuk_account_session
|
54
|
+
stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/end-session")
|
55
|
+
.with(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session })
|
56
|
+
.to_return(
|
57
|
+
status: 200,
|
58
|
+
body: { end_session_uri: end_session_uri }.to_json,
|
59
|
+
)
|
60
|
+
else
|
61
|
+
stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/end-session")
|
62
|
+
.to_return(
|
63
|
+
status: 200,
|
64
|
+
body: { end_session_uri: end_session_uri }.to_json,
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
49
69
|
###############
|
50
70
|
# GET /api/user
|
51
71
|
###############
|
52
|
-
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)
|
53
73
|
stub_account_api_request(
|
54
74
|
:get,
|
55
75
|
"/api/user",
|
56
76
|
response_body: {
|
57
77
|
id: id,
|
58
|
-
|
78
|
+
mfa: mfa,
|
59
79
|
email: email,
|
60
80
|
email_verified: email_verified,
|
61
81
|
has_unconfirmed_email: has_unconfirmed_email,
|
@@ -105,16 +125,18 @@ module GdsApi
|
|
105
125
|
###########################################
|
106
126
|
# PATCH /api/oidc-users/:subject_identifier
|
107
127
|
###########################################
|
108
|
-
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)
|
109
129
|
stub_account_api_request(
|
110
130
|
:patch,
|
111
131
|
"/api/oidc-users/#{subject_identifier}",
|
112
|
-
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) },
|
113
133
|
response_body: {
|
114
134
|
sub: subject_identifier,
|
115
135
|
email: email || old_email,
|
116
136
|
email_verified: email_verified || old_email_verified,
|
117
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,
|
118
140
|
},
|
119
141
|
)
|
120
142
|
end
|
@@ -236,13 +258,12 @@ module GdsApi
|
|
236
258
|
)
|
237
259
|
end
|
238
260
|
|
239
|
-
def stub_account_api_forbidden_has_attributes(attributes: [],
|
261
|
+
def stub_account_api_forbidden_has_attributes(attributes: [], **options)
|
240
262
|
querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
|
241
263
|
stub_account_api_request(
|
242
264
|
:get,
|
243
265
|
"/api/attributes?#{querystring}",
|
244
266
|
response_status: 403,
|
245
|
-
response_body: { needed_level_of_authentication: needed_level_of_authentication },
|
246
267
|
**options,
|
247
268
|
)
|
248
269
|
end
|
@@ -269,150 +290,12 @@ module GdsApi
|
|
269
290
|
)
|
270
291
|
end
|
271
292
|
|
272
|
-
def stub_account_api_forbidden_set_attributes(attributes: nil,
|
293
|
+
def stub_account_api_forbidden_set_attributes(attributes: nil, **options)
|
273
294
|
stub_account_api_request(
|
274
295
|
:patch,
|
275
296
|
"/api/attributes",
|
276
297
|
with: { body: hash_including({ attributes: attributes }.compact) },
|
277
298
|
response_status: 403,
|
278
|
-
response_body: { needed_level_of_authentication: needed_level_of_authentication },
|
279
|
-
**options,
|
280
|
-
)
|
281
|
-
end
|
282
|
-
|
283
|
-
######################
|
284
|
-
# GET /api/saved-pages
|
285
|
-
######################
|
286
|
-
def stub_account_api_returning_saved_pages(saved_pages: [], **options)
|
287
|
-
stub_account_api_request(
|
288
|
-
:get,
|
289
|
-
"/api/saved-pages",
|
290
|
-
response_body: { saved_pages: saved_pages },
|
291
|
-
**options,
|
292
|
-
)
|
293
|
-
end
|
294
|
-
|
295
|
-
def stub_account_api_unauthorized_get_saved_pages(**options)
|
296
|
-
stub_account_api_request(
|
297
|
-
:get,
|
298
|
-
"/api/saved-pages",
|
299
|
-
response_status: 401,
|
300
|
-
**options,
|
301
|
-
)
|
302
|
-
end
|
303
|
-
|
304
|
-
#################################
|
305
|
-
# GET /api/saved_pages/:page_path
|
306
|
-
#################################
|
307
|
-
def stub_account_api_get_saved_page(page_path:, content_id: "46163ed2-1777-4ee6-bdd4-6a2007e49d8f", title: "Ministry of Magic", **options)
|
308
|
-
stub_account_api_request(
|
309
|
-
:get,
|
310
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
311
|
-
response_body: {
|
312
|
-
saved_page: {
|
313
|
-
page_path: page_path,
|
314
|
-
content_id: content_id,
|
315
|
-
title: title,
|
316
|
-
},
|
317
|
-
},
|
318
|
-
**options,
|
319
|
-
)
|
320
|
-
end
|
321
|
-
|
322
|
-
def stub_account_api_does_not_have_saved_page(page_path:, **options)
|
323
|
-
stub_account_api_request(
|
324
|
-
:get,
|
325
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
326
|
-
response_status: 404,
|
327
|
-
**options,
|
328
|
-
)
|
329
|
-
end
|
330
|
-
|
331
|
-
def stub_account_api_unauthorized_get_saved_page(page_path:, **options)
|
332
|
-
stub_account_api_request(
|
333
|
-
:get,
|
334
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
335
|
-
response_status: 401,
|
336
|
-
**options,
|
337
|
-
)
|
338
|
-
end
|
339
|
-
|
340
|
-
#################################
|
341
|
-
# PUT /api/saved-pages/:page_path
|
342
|
-
#################################
|
343
|
-
def stub_account_api_save_page(page_path:, content_id: "c840bfa2-011a-42cc-ac7a-a6da990aff0b", title: "Ministry of Magic", **options)
|
344
|
-
stub_account_api_request(
|
345
|
-
:put,
|
346
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
347
|
-
response_body: {
|
348
|
-
saved_page: {
|
349
|
-
page_path: page_path,
|
350
|
-
content_id: content_id,
|
351
|
-
title: title,
|
352
|
-
},
|
353
|
-
},
|
354
|
-
**options,
|
355
|
-
)
|
356
|
-
end
|
357
|
-
|
358
|
-
def stub_account_api_save_page_already_exists(page_path:, **options)
|
359
|
-
stub_account_api_save_page(page_path: page_path, **options)
|
360
|
-
end
|
361
|
-
|
362
|
-
def stub_account_api_save_page_cannot_save_page(page_path:, **options)
|
363
|
-
stub_account_api_request(
|
364
|
-
:put,
|
365
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
366
|
-
response_status: 422,
|
367
|
-
response_body: cannot_save_page_problem_detail({ page_path: page_path }),
|
368
|
-
**options,
|
369
|
-
)
|
370
|
-
end
|
371
|
-
|
372
|
-
def stub_account_api_unauthorized_save_page(page_path:, **options)
|
373
|
-
stub_account_api_request(
|
374
|
-
:put,
|
375
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
376
|
-
response_status: 401,
|
377
|
-
**options,
|
378
|
-
)
|
379
|
-
end
|
380
|
-
|
381
|
-
def cannot_save_page_problem_detail(option = {})
|
382
|
-
{
|
383
|
-
title: "Cannot save page",
|
384
|
-
detail: "Cannot save page with path #{option['page_path']}, check it is not blank, and is a well formatted url path.",
|
385
|
-
type: "https://github.com/alphagov/account-api/blob/main/docs/api.md#cannot-save-page",
|
386
|
-
**option,
|
387
|
-
}
|
388
|
-
end
|
389
|
-
|
390
|
-
####################################
|
391
|
-
# DELETE /api/saved-pages/:page_path
|
392
|
-
####################################
|
393
|
-
def stub_account_api_delete_saved_page(page_path:, **options)
|
394
|
-
stub_account_api_request(
|
395
|
-
:delete,
|
396
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
397
|
-
response_status: 204,
|
398
|
-
**options,
|
399
|
-
)
|
400
|
-
end
|
401
|
-
|
402
|
-
def stub_account_api_delete_saved_page_does_not_exist(page_path:, **options)
|
403
|
-
stub_account_api_request(
|
404
|
-
:delete,
|
405
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
406
|
-
response_status: 404,
|
407
|
-
**options,
|
408
|
-
)
|
409
|
-
end
|
410
|
-
|
411
|
-
def stub_account_api_unauthorized_delete_saved_page(page_path:, **options)
|
412
|
-
stub_account_api_request(
|
413
|
-
:delete,
|
414
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
415
|
-
response_status: 401,
|
416
299
|
**options,
|
417
300
|
)
|
418
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.1.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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|