gds-api-adapters 71.4.0 → 71.5.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 +41 -5
- data/lib/gds_api/test_helpers/account_api.rb +140 -14
- 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: 40bafd0ac54082d307befb62d5a9f4af3d21c53ff42ec51bcc5ee4c2e7897e9a
|
4
|
+
data.tar.gz: '029eeb35b60b20ad1da0c4f5da7162db15aa768ce539f67e39ea44e78df7e807'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f025fac520f508122ffa5a7cf17569ec1b00a60d10b418fa1d4d3e57681f15497dd3e8eaba990b29a52ca87309945e2de90cae5682a265b89ac340bc0e08547e
|
7
|
+
data.tar.gz: d0c513eda3423fba67d49250aa6d18359a09ad816a15d0523b215555e828003a6ccaf108412d91bbabcb80bed6ccf6fe67cba2590b6010c09a4667cf6ff719cb
|
data/lib/gds_api/account_api.rb
CHANGED
@@ -57,12 +57,19 @@ class GdsApi::AccountApi < GdsApi::Base
|
|
57
57
|
# Update the user record with privileged information from the auth service. Only the auth service will call this.
|
58
58
|
#
|
59
59
|
# @param [String] subject_identifier The identifier of the user, shared between the auth service and GOV.UK.
|
60
|
-
# @param [String, nil] email The
|
61
|
-
# @param [Boolean, nil] email_verified Whether the
|
60
|
+
# @param [String, nil] email The user's current
|
61
|
+
# @param [Boolean, nil] email_verified Whether the user's current email address is verified
|
62
|
+
# @param [Boolean, nil] has_unconfirmed_email Whether the user has a new, pending, email address
|
62
63
|
#
|
63
64
|
# @return [Hash] The user's subject identifier and email attributes
|
64
|
-
def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil)
|
65
|
-
|
65
|
+
def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil)
|
66
|
+
params = {
|
67
|
+
email: email,
|
68
|
+
email_verified: email_verified,
|
69
|
+
has_unconfirmed_email: has_unconfirmed_email,
|
70
|
+
}.compact
|
71
|
+
|
72
|
+
patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params)
|
66
73
|
end
|
67
74
|
|
68
75
|
# Check if a user has an email subscription for the Transition Checker
|
@@ -116,11 +123,40 @@ class GdsApi::AccountApi < GdsApi::Base
|
|
116
123
|
get_json("#{endpoint}/api/attributes/names?#{querystring}", auth_headers(govuk_account_session))
|
117
124
|
end
|
118
125
|
|
126
|
+
# Get the details of an account-linked email subscription.
|
127
|
+
#
|
128
|
+
# @param [String] name Name of the subscription
|
129
|
+
# @param [String] govuk_account_session Value of the session header
|
130
|
+
#
|
131
|
+
# @return [Hash] Details of the subscription, if it exists.
|
132
|
+
def get_email_subscription(name:, govuk_account_session:)
|
133
|
+
get_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", auth_headers(govuk_account_session))
|
134
|
+
end
|
135
|
+
|
136
|
+
# Create or update an account-linked email subscription.
|
137
|
+
#
|
138
|
+
# @param [String] name Name of the subscription
|
139
|
+
# @param [String] topic_slug The email-alert-api topic slug to subscribe to
|
140
|
+
# @param [String] govuk_account_session Value of the session header
|
141
|
+
#
|
142
|
+
# @return [Hash] Details of the newly created subscription.
|
143
|
+
def put_email_subscription(name:, topic_slug:, govuk_account_session:)
|
144
|
+
put_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", { topic_slug: topic_slug }, auth_headers(govuk_account_session))
|
145
|
+
end
|
146
|
+
|
147
|
+
# Unsubscribe and delete an account-linked email subscription.
|
148
|
+
#
|
149
|
+
# @param [String] name Name of the subscription
|
150
|
+
# @param [String] govuk_account_session Value of the session header
|
151
|
+
def delete_email_subscription(name:, govuk_account_session:)
|
152
|
+
delete_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", {}, auth_headers(govuk_account_session))
|
153
|
+
end
|
154
|
+
|
119
155
|
# Look up all pages saved by a user in their Account
|
120
156
|
#
|
121
157
|
# @param [String] govuk_account_session Value of the session header
|
122
158
|
#
|
123
|
-
# @return [Hash] containing :saved_pages, an array of single saved page hashes
|
159
|
+
# @return [Hash] containing :saved_pages, an array of single saved page hashes
|
124
160
|
def get_saved_pages(govuk_account_session:)
|
125
161
|
get_json("#{endpoint}/api/saved-pages", auth_headers(govuk_account_session))
|
126
162
|
end
|
@@ -5,6 +5,20 @@ module GdsApi
|
|
5
5
|
module AccountApi
|
6
6
|
ACCOUNT_API_ENDPOINT = Plek.find("account-api")
|
7
7
|
|
8
|
+
def stub_account_api_request(method, path, with: {}, response_status: 200, response_body: {}, govuk_account_session: nil, new_govuk_account_session: nil)
|
9
|
+
with.merge!(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session }) if govuk_account_session
|
10
|
+
new_govuk_account_session = nil if response_status >= 400
|
11
|
+
to_return = { status: response_status, body: response_body.merge(govuk_account_session: new_govuk_account_session).compact.to_json }
|
12
|
+
if with.empty?
|
13
|
+
stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").to_return(**to_return)
|
14
|
+
else
|
15
|
+
stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").with(**with).to_return(**to_return)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#########################
|
20
|
+
# GET /api/oauth2/sign-in
|
21
|
+
#########################
|
8
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")
|
9
23
|
querystring = Rack::Utils.build_nested_query({ redirect_path: redirect_path, state_id: state_id, level_of_authentication: level_of_authentication }.compact)
|
10
24
|
stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/sign-in?#{querystring}")
|
@@ -14,6 +28,9 @@ module GdsApi
|
|
14
28
|
)
|
15
29
|
end
|
16
30
|
|
31
|
+
###########################
|
32
|
+
# POST /api/oauth2/callback
|
33
|
+
###########################
|
17
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")
|
18
35
|
stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/callback")
|
19
36
|
.with(body: hash_including({ code: code, state: state }.compact))
|
@@ -29,6 +46,9 @@ module GdsApi
|
|
29
46
|
.to_return(status: 401)
|
30
47
|
end
|
31
48
|
|
49
|
+
########################
|
50
|
+
# POST /api/oauth2/state
|
51
|
+
########################
|
32
52
|
def stub_account_api_create_registration_state(attributes: nil, state_id: "state-id")
|
33
53
|
stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/state")
|
34
54
|
.with(body: hash_including({ attributes: attributes }.compact))
|
@@ -38,7 +58,10 @@ module GdsApi
|
|
38
58
|
)
|
39
59
|
end
|
40
60
|
|
41
|
-
|
61
|
+
###############
|
62
|
+
# GET /api/user
|
63
|
+
###############
|
64
|
+
def stub_account_api_user_info(level_of_authentication: "level0", email: "email@example.com", email_verified: true, has_unconfirmed_email: false, services: {}, **options)
|
42
65
|
stub_account_api_request(
|
43
66
|
:get,
|
44
67
|
"/api/user",
|
@@ -46,6 +69,7 @@ module GdsApi
|
|
46
69
|
level_of_authentication: level_of_authentication,
|
47
70
|
email: email,
|
48
71
|
email_verified: email_verified,
|
72
|
+
has_unconfirmed_email: has_unconfirmed_email,
|
49
73
|
services: services,
|
50
74
|
},
|
51
75
|
**options,
|
@@ -69,19 +93,120 @@ module GdsApi
|
|
69
93
|
)
|
70
94
|
end
|
71
95
|
|
72
|
-
|
96
|
+
###########################################
|
97
|
+
# PATCH /api/oidc-users/:subject_identifier
|
98
|
+
###########################################
|
99
|
+
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)
|
73
100
|
stub_account_api_request(
|
74
101
|
:patch,
|
75
102
|
"/api/oidc-users/#{subject_identifier}",
|
76
|
-
with: { body: hash_including({ email: email, email_verified: email_verified }.compact) },
|
103
|
+
with: { body: hash_including({ email: email, email_verified: email_verified, has_unconfirmed_email: has_unconfirmed_email }.compact) },
|
77
104
|
response_body: {
|
78
105
|
sub: subject_identifier,
|
79
106
|
email: email || old_email,
|
80
107
|
email_verified: email_verified || old_email_verified,
|
108
|
+
has_unconfirmed_email: has_unconfirmed_email || old_has_unconfirmed_email,
|
109
|
+
},
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
####################################
|
114
|
+
# GET /api/email-subscriptions/:name
|
115
|
+
####################################
|
116
|
+
def stub_account_api_get_email_subscription(name:, topic_slug: "slug", email_alert_api_subscription_id: "12345", **options)
|
117
|
+
stub_account_api_request(
|
118
|
+
:get,
|
119
|
+
"/api/email-subscriptions/#{name}",
|
120
|
+
response_body: {
|
121
|
+
email_subscription: {
|
122
|
+
name: name,
|
123
|
+
topic_slug: topic_slug,
|
124
|
+
email_alert_api_subscription_id: email_alert_api_subscription_id,
|
125
|
+
},
|
126
|
+
},
|
127
|
+
**options,
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
def stub_account_api_get_email_subscription_does_not_exist(name:, **options)
|
132
|
+
stub_account_api_request(
|
133
|
+
:get,
|
134
|
+
"/api/email-subscriptions/#{name}",
|
135
|
+
response_status: 404,
|
136
|
+
**options,
|
137
|
+
)
|
138
|
+
end
|
139
|
+
|
140
|
+
def stub_account_api_get_email_subscription_unauthorized(name:, **options)
|
141
|
+
stub_account_api_request(
|
142
|
+
:get,
|
143
|
+
"/api/email-subscriptions/#{name}",
|
144
|
+
response_status: 401,
|
145
|
+
**options,
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
149
|
+
####################################
|
150
|
+
# PUT /api/email-subscriptions/:name
|
151
|
+
####################################
|
152
|
+
def stub_account_api_put_email_subscription(name:, topic_slug: nil, **options)
|
153
|
+
stub_account_api_request(
|
154
|
+
:put,
|
155
|
+
"/api/email-subscriptions/#{name}",
|
156
|
+
with: { body: hash_including({ topic_slug: topic_slug }.compact) },
|
157
|
+
response_body: {
|
158
|
+
email_subscription: {
|
159
|
+
name: name,
|
160
|
+
topic_slug: topic_slug || "slug",
|
161
|
+
},
|
81
162
|
},
|
163
|
+
**options,
|
164
|
+
)
|
165
|
+
end
|
166
|
+
|
167
|
+
def stub_account_api_unauthorized_put_email_subscription(name:, topic_slug: nil, **options)
|
168
|
+
stub_account_api_request(
|
169
|
+
:put,
|
170
|
+
"/api/email-subscriptions/#{name}",
|
171
|
+
with: { body: hash_including({ topic_slug: topic_slug }.compact) },
|
172
|
+
response_status: 401,
|
173
|
+
**options,
|
82
174
|
)
|
83
175
|
end
|
84
176
|
|
177
|
+
#######################################
|
178
|
+
# DELETE /api/email-subscriptions/:name
|
179
|
+
#######################################
|
180
|
+
def stub_account_api_delete_email_subscription(name:, **options)
|
181
|
+
stub_account_api_request(
|
182
|
+
:delete,
|
183
|
+
"/api/email-subscriptions/#{name}",
|
184
|
+
response_status: 204,
|
185
|
+
**options,
|
186
|
+
)
|
187
|
+
end
|
188
|
+
|
189
|
+
def stub_account_api_delete_email_subscription_does_not_exist(name:, **options)
|
190
|
+
stub_account_api_request(
|
191
|
+
:delete,
|
192
|
+
"/api/email-subscriptions/#{name}",
|
193
|
+
response_status: 404,
|
194
|
+
**options,
|
195
|
+
)
|
196
|
+
end
|
197
|
+
|
198
|
+
def stub_account_api_unauthorized_delete_email_subscription(name:, **options)
|
199
|
+
stub_account_api_request(
|
200
|
+
:delete,
|
201
|
+
"/api/email-subscriptions/#{name}",
|
202
|
+
response_status: 401,
|
203
|
+
**options,
|
204
|
+
)
|
205
|
+
end
|
206
|
+
|
207
|
+
################################################
|
208
|
+
# GET /api/transition-checker-email-subscription
|
209
|
+
################################################
|
85
210
|
def stub_account_api_has_email_subscription(**options)
|
86
211
|
stub_account_api_request(
|
87
212
|
:get,
|
@@ -119,6 +244,9 @@ module GdsApi
|
|
119
244
|
)
|
120
245
|
end
|
121
246
|
|
247
|
+
#################################################
|
248
|
+
# POST /api/transition-checker-email-subscription
|
249
|
+
#################################################
|
122
250
|
def stub_account_api_set_email_subscription(slug: nil, **options)
|
123
251
|
stub_account_api_request(
|
124
252
|
:post,
|
@@ -149,6 +277,9 @@ module GdsApi
|
|
149
277
|
)
|
150
278
|
end
|
151
279
|
|
280
|
+
#####################
|
281
|
+
# GET /api/attributes
|
282
|
+
#####################
|
152
283
|
def stub_account_api_has_attributes(attributes: [], values: {}, **options)
|
153
284
|
querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
|
154
285
|
stub_account_api_request(
|
@@ -180,6 +311,9 @@ module GdsApi
|
|
180
311
|
)
|
181
312
|
end
|
182
313
|
|
314
|
+
#######################
|
315
|
+
# PATCH /api/attributes
|
316
|
+
#######################
|
183
317
|
def stub_account_api_set_attributes(attributes: nil, **options)
|
184
318
|
stub_account_api_request(
|
185
319
|
:patch,
|
@@ -210,6 +344,9 @@ module GdsApi
|
|
210
344
|
)
|
211
345
|
end
|
212
346
|
|
347
|
+
###########################
|
348
|
+
# GET /api/attributes/names
|
349
|
+
###########################
|
213
350
|
def stub_account_api_get_attributes_names(attributes: [], **options)
|
214
351
|
querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
|
215
352
|
stub_account_api_request(
|
@@ -241,17 +378,6 @@ module GdsApi
|
|
241
378
|
)
|
242
379
|
end
|
243
380
|
|
244
|
-
def stub_account_api_request(method, path, with: {}, response_status: 200, response_body: {}, govuk_account_session: nil, new_govuk_account_session: nil)
|
245
|
-
with.merge!(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session }) if govuk_account_session
|
246
|
-
new_govuk_account_session = nil if response_status >= 400
|
247
|
-
to_return = { status: response_status, body: response_body.merge(govuk_account_session: new_govuk_account_session).compact.to_json }
|
248
|
-
if with.empty?
|
249
|
-
stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").to_return(**to_return)
|
250
|
-
else
|
251
|
-
stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").with(**with).to_return(**to_return)
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
381
|
######################
|
256
382
|
# GET /api/saved-pages
|
257
383
|
######################
|
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: 71.
|
4
|
+
version: 71.5.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-
|
11
|
+
date: 2021-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|