gds-api-adapters 71.8.0 → 73.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/lib/gds_api/account_api.rb +8 -42
- data/lib/gds_api/exceptions.rb +1 -1
- data/lib/gds_api/test_helpers/account_api.rb +26 -125
- 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: e27eb1087cbf7f61da350a3c09dc2d1c235ed5b6ee6b096ae9ca3c3f25edb2e9
|
4
|
+
data.tar.gz: 24af32669af502a68d4085e86be5705e8ff98f6899e50f6b01df1b3b884a2e56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4b6328db22729d14c8f4f456d8886dd2de5de9d75efd1fbb5f00124f1f067fe520ea5556d67ac32ffd36653598ee9895d029abfcd2ecc3a1ef22c8d8b618574
|
7
|
+
data.tar.gz: 9c78e6148f87c00c682222bf1468a32b9e70aa05b7a1163f2aabc2b7d0c050d591a43a80ccf502e6f7c01b695859effc33879ca3ced8dd7f3912eed4a2f75c39
|
data/lib/gds_api/account_api.rb
CHANGED
@@ -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,
|
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
|
@@ -54,6 +43,13 @@ class GdsApi::AccountApi < GdsApi::Base
|
|
54
43
|
get_json("#{endpoint}/api/user", auth_headers(govuk_account_session))
|
55
44
|
end
|
56
45
|
|
46
|
+
# Delete a users account
|
47
|
+
#
|
48
|
+
# @param [String] subject_identifier The identifier of the user, shared between the auth service and GOV.UK.
|
49
|
+
def delete_user_by_subject_identifier(subject_identifier:)
|
50
|
+
delete_json("#{endpoint}/api/oidc-users/#{subject_identifier}")
|
51
|
+
end
|
52
|
+
|
57
53
|
# Update the user record with privileged information from the auth service. Only the auth service will call this.
|
58
54
|
#
|
59
55
|
# @param [String] subject_identifier The identifier of the user, shared between the auth service and GOV.UK.
|
@@ -72,25 +68,6 @@ class GdsApi::AccountApi < GdsApi::Base
|
|
72
68
|
patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params)
|
73
69
|
end
|
74
70
|
|
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
71
|
# Look up the values of a user's attributes
|
95
72
|
#
|
96
73
|
# @param [String] attributes Names of the attributes to check
|
@@ -112,17 +89,6 @@ class GdsApi::AccountApi < GdsApi::Base
|
|
112
89
|
patch_json("#{endpoint}/api/attributes", { attributes: attributes }, auth_headers(govuk_account_session))
|
113
90
|
end
|
114
91
|
|
115
|
-
# Look up the names of a user's attributes
|
116
|
-
#
|
117
|
-
# @param [String] attributes Names of the attributes to check
|
118
|
-
# @param [String] govuk_account_session Value of the session header
|
119
|
-
#
|
120
|
-
# @return [Hash] The attribute names (if present), and a new session header
|
121
|
-
def get_attributes_names(attributes:, govuk_account_session:)
|
122
|
-
querystring = nested_query_string({ attributes: attributes }.compact)
|
123
|
-
get_json("#{endpoint}/api/attributes/names?#{querystring}", auth_headers(govuk_account_session))
|
124
|
-
end
|
125
|
-
|
126
92
|
# Get the details of an account-linked email subscription.
|
127
93
|
#
|
128
94
|
# @param [String] name Name of the subscription
|
data/lib/gds_api/exceptions.rb
CHANGED
@@ -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
|
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,
|
23
|
-
querystring = Rack::Utils.build_nested_query({ redirect_path: redirect_path,
|
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,18 +46,6 @@ 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
|
###############
|
@@ -94,6 +82,26 @@ module GdsApi
|
|
94
82
|
)
|
95
83
|
end
|
96
84
|
|
85
|
+
############################################
|
86
|
+
# DELETE /api/oidc-users/:subject_identifier
|
87
|
+
############################################
|
88
|
+
|
89
|
+
def stub_account_api_delete_user_by_subject_identifier(subject_identifier:)
|
90
|
+
stub_account_api_request(
|
91
|
+
:delete,
|
92
|
+
"/api/oidc-users/#{subject_identifier}",
|
93
|
+
response_status: 204,
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
def stub_account_api_delete_user_by_subject_identifier_does_not_exist(subject_identifier:)
|
98
|
+
stub_account_api_request(
|
99
|
+
:delete,
|
100
|
+
"/api/oidc-users/#{subject_identifier}",
|
101
|
+
response_status: 404,
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
97
105
|
###########################################
|
98
106
|
# PATCH /api/oidc-users/:subject_identifier
|
99
107
|
###########################################
|
@@ -138,7 +146,7 @@ module GdsApi
|
|
138
146
|
)
|
139
147
|
end
|
140
148
|
|
141
|
-
def
|
149
|
+
def stub_account_api_unauthorized_get_email_subscription(name:, **options)
|
142
150
|
stub_account_api_request(
|
143
151
|
:get,
|
144
152
|
"/api/email-subscriptions/#{name}",
|
@@ -205,79 +213,6 @@ module GdsApi
|
|
205
213
|
)
|
206
214
|
end
|
207
215
|
|
208
|
-
################################################
|
209
|
-
# GET /api/transition-checker-email-subscription
|
210
|
-
################################################
|
211
|
-
def stub_account_api_has_email_subscription(**options)
|
212
|
-
stub_account_api_request(
|
213
|
-
:get,
|
214
|
-
"/api/transition-checker-email-subscription",
|
215
|
-
response_body: { has_subscription: true },
|
216
|
-
**options,
|
217
|
-
)
|
218
|
-
end
|
219
|
-
|
220
|
-
def stub_account_api_does_not_have_email_subscription(**options)
|
221
|
-
stub_account_api_request(
|
222
|
-
:get,
|
223
|
-
"/api/transition-checker-email-subscription",
|
224
|
-
response_body: { has_subscription: false },
|
225
|
-
**options,
|
226
|
-
)
|
227
|
-
end
|
228
|
-
|
229
|
-
def stub_account_api_unauthorized_get_email_subscription(**options)
|
230
|
-
stub_account_api_request(
|
231
|
-
:get,
|
232
|
-
"/api/transition-checker-email-subscription",
|
233
|
-
response_status: 401,
|
234
|
-
**options,
|
235
|
-
)
|
236
|
-
end
|
237
|
-
|
238
|
-
def stub_account_api_forbidden_get_email_subscription(needed_level_of_authentication: "level1", **options)
|
239
|
-
stub_account_api_request(
|
240
|
-
:get,
|
241
|
-
"/api/transition-checker-email-subscription",
|
242
|
-
response_status: 403,
|
243
|
-
response_body: { needed_level_of_authentication: needed_level_of_authentication },
|
244
|
-
**options,
|
245
|
-
)
|
246
|
-
end
|
247
|
-
|
248
|
-
#################################################
|
249
|
-
# POST /api/transition-checker-email-subscription
|
250
|
-
#################################################
|
251
|
-
def stub_account_api_set_email_subscription(slug: nil, **options)
|
252
|
-
stub_account_api_request(
|
253
|
-
:post,
|
254
|
-
"/api/transition-checker-email-subscription",
|
255
|
-
with: { body: hash_including({ slug: slug }.compact) },
|
256
|
-
**options,
|
257
|
-
)
|
258
|
-
end
|
259
|
-
|
260
|
-
def stub_account_api_unauthorized_set_email_subscription(slug: nil, **options)
|
261
|
-
stub_account_api_request(
|
262
|
-
:post,
|
263
|
-
"/api/transition-checker-email-subscription",
|
264
|
-
with: { body: hash_including({ slug: slug }.compact) },
|
265
|
-
response_status: 401,
|
266
|
-
**options,
|
267
|
-
)
|
268
|
-
end
|
269
|
-
|
270
|
-
def stub_account_api_forbidden_set_email_subscription(slug: nil, needed_level_of_authentication: "level1", **options)
|
271
|
-
stub_account_api_request(
|
272
|
-
:post,
|
273
|
-
"/api/transition-checker-email-subscription",
|
274
|
-
with: { body: hash_including({ slug: slug }.compact) },
|
275
|
-
response_status: 403,
|
276
|
-
response_body: { needed_level_of_authentication: needed_level_of_authentication },
|
277
|
-
**options,
|
278
|
-
)
|
279
|
-
end
|
280
|
-
|
281
216
|
#####################
|
282
217
|
# GET /api/attributes
|
283
218
|
#####################
|
@@ -345,40 +280,6 @@ module GdsApi
|
|
345
280
|
)
|
346
281
|
end
|
347
282
|
|
348
|
-
###########################
|
349
|
-
# GET /api/attributes/names
|
350
|
-
###########################
|
351
|
-
def stub_account_api_get_attributes_names(attributes: [], **options)
|
352
|
-
querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
|
353
|
-
stub_account_api_request(
|
354
|
-
:get,
|
355
|
-
"/api/attributes/names?#{querystring}",
|
356
|
-
response_body: { values: attributes },
|
357
|
-
**options,
|
358
|
-
)
|
359
|
-
end
|
360
|
-
|
361
|
-
def stub_account_api_unauthorized_get_attributes_names(attributes: [], **options)
|
362
|
-
querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
|
363
|
-
stub_account_api_request(
|
364
|
-
:get,
|
365
|
-
"/api/attributes/names?#{querystring}",
|
366
|
-
response_status: 401,
|
367
|
-
**options,
|
368
|
-
)
|
369
|
-
end
|
370
|
-
|
371
|
-
def stub_account_api_forbidden_get_attributes_names(attributes: [], needed_level_of_authentication: "level1", **options)
|
372
|
-
querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
|
373
|
-
stub_account_api_request(
|
374
|
-
:get,
|
375
|
-
"/api/attributes/names?#{querystring}",
|
376
|
-
response_status: 403,
|
377
|
-
response_body: { needed_level_of_authentication: needed_level_of_authentication },
|
378
|
-
**options,
|
379
|
-
)
|
380
|
-
end
|
381
|
-
|
382
283
|
######################
|
383
284
|
# GET /api/saved-pages
|
384
285
|
######################
|
@@ -507,7 +408,7 @@ module GdsApi
|
|
507
408
|
)
|
508
409
|
end
|
509
410
|
|
510
|
-
def
|
411
|
+
def stub_account_api_unauthorized_delete_saved_page(page_path:, **options)
|
511
412
|
stub_account_api_request(
|
512
413
|
:delete,
|
513
414
|
"/api/saved-pages/#{CGI.escape(page_path)}",
|
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: 73.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-
|
11
|
+
date: 2021-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|